@@ -693,7 +693,8 @@ func (fs *filesystem) LinkAt(ctx context.Context, rp *vfs.ResolvingPath, vd vfs.
693
693
return err
694
694
}
695
695
}
696
- if err := vfsObj .LinkAt (ctx , fs .creds , & vfs.PathOperation {
696
+ createCreds := parent .credsForCreate (rp .Credentials (), parent .isSGIDSet ())
697
+ if err := vfsObj .LinkAt (ctx , createCreds , & vfs.PathOperation {
697
698
Root : old .upperVD ,
698
699
Start : old .upperVD ,
699
700
}, & newpop ); err != nil {
@@ -702,21 +703,6 @@ func (fs *filesystem) LinkAt(ctx context.Context, rp *vfs.ResolvingPath, vd vfs.
702
703
}
703
704
return err
704
705
}
705
- creds := rp .Credentials ()
706
- if err := vfsObj .SetStatAt (ctx , fs .creds , & newpop , & vfs.SetStatOptions {
707
- Stat : linux.Statx {
708
- Mask : linux .STATX_UID | linux .STATX_GID ,
709
- UID : uint32 (creds .EffectiveKUID ),
710
- GID : uint32 (creds .EffectiveKGID ),
711
- },
712
- }); err != nil {
713
- if cleanupErr := vfsObj .UnlinkAt (ctx , fs .creds , & newpop ); cleanupErr != nil {
714
- panic (fmt .Sprintf ("unrecoverable overlayfs inconsistency: failed to delete upper layer file after LinkAt metadata update failure: %v" , cleanupErr ))
715
- } else if haveUpperWhiteout {
716
- fs .cleanupRecreateWhiteout (ctx , vfsObj , & newpop )
717
- }
718
- return err
719
- }
720
706
old .watches .Notify (ctx , "" , linux .IN_ATTRIB , 0 /* cookie */ , vfs .InodeEvent , false /* unlinked */ )
721
707
return nil
722
708
})
@@ -740,23 +726,19 @@ func (fs *filesystem) MkdirAt(ctx context.Context, rp *vfs.ResolvingPath, opts v
740
726
return err
741
727
}
742
728
}
743
- if err := vfsObj .MkdirAt (ctx , fs .creds , & pop , & opts ); err != nil {
729
+ sgidSet := parent .isSGIDSet ()
730
+ if sgidSet {
731
+ // Directories inherit the SGID bit.
732
+ opts .Mode |= linux .ModeSetGID
733
+ }
734
+ createCreds := parent .credsForCreate (rp .Credentials (), sgidSet )
735
+ if err := vfsObj .MkdirAt (ctx , createCreds , & pop , & opts ); err != nil {
744
736
if haveUpperWhiteout {
745
737
fs .cleanupRecreateWhiteout (ctx , vfsObj , & pop )
746
738
}
747
739
return err
748
740
}
749
741
750
- if err := vfsObj .SetStatAt (ctx , fs .creds , & pop , & vfs.SetStatOptions {
751
- Stat : parent .newChildOwnerStat (opts .Mode , rp .Credentials ()),
752
- }); err != nil {
753
- if cleanupErr := vfsObj .RmdirAt (ctx , fs .creds , & pop ); cleanupErr != nil {
754
- panic (fmt .Sprintf ("unrecoverable overlayfs inconsistency: failed to delete upper layer directory after MkdirAt metadata update failure: %v" , cleanupErr ))
755
- } else if haveUpperWhiteout {
756
- fs .cleanupRecreateWhiteout (ctx , vfsObj , & pop )
757
- }
758
- return err
759
- }
760
742
if haveUpperWhiteout {
761
743
// A whiteout is being replaced with this new directory. There may be
762
744
// directories on lower layers (previously hidden by the whiteout) that
@@ -807,23 +789,13 @@ func (fs *filesystem) MknodAt(ctx context.Context, rp *vfs.ResolvingPath, opts v
807
789
return err
808
790
}
809
791
}
810
- if err := vfsObj .MknodAt (ctx , fs .creds , & pop , & opts ); err != nil {
792
+ createCreds := parent .credsForCreate (rp .Credentials (), parent .isSGIDSet ())
793
+ if err := vfsObj .MknodAt (ctx , createCreds , & pop , & opts ); err != nil {
811
794
if haveUpperWhiteout {
812
795
fs .cleanupRecreateWhiteout (ctx , vfsObj , & pop )
813
796
}
814
797
return err
815
798
}
816
- creds := rp .Credentials ()
817
- if err := vfsObj .SetStatAt (ctx , fs .creds , & pop , & vfs.SetStatOptions {
818
- Stat : parent .newChildOwnerStat (opts .Mode , creds ),
819
- }); err != nil {
820
- if cleanupErr := vfsObj .UnlinkAt (ctx , fs .creds , & pop ); cleanupErr != nil {
821
- panic (fmt .Sprintf ("unrecoverable overlayfs inconsistency: failed to delete upper layer file after MknodAt metadata update failure: %v" , cleanupErr ))
822
- } else if haveUpperWhiteout {
823
- fs .cleanupRecreateWhiteout (ctx , vfsObj , & pop )
824
- }
825
- return err
826
- }
827
799
return nil
828
800
})
829
801
}
@@ -1027,7 +999,8 @@ func (fs *filesystem) createAndOpenLocked(ctx context.Context, rp *vfs.Resolving
1027
999
}
1028
1000
}
1029
1001
// Create the file on the upper layer, and get an FD representing it.
1030
- upperFD , err := vfsObj .OpenAt (ctx , fs .creds , & pop , & vfs.OpenOptions {
1002
+ createCreds := parent .credsForCreate (creds , parent .isSGIDSet ())
1003
+ upperFD , err := vfsObj .OpenAt (ctx , createCreds , & pop , & vfs.OpenOptions {
1031
1004
Flags : opts .Flags &^vfs .FileCreationFlags | linux .O_CREAT | linux .O_EXCL ,
1032
1005
Mode : opts .Mode ,
1033
1006
})
@@ -1038,18 +1011,6 @@ func (fs *filesystem) createAndOpenLocked(ctx context.Context, rp *vfs.Resolving
1038
1011
return nil , err
1039
1012
}
1040
1013
1041
- // Change the file's owner to the caller. We can't use upperFD.SetStat()
1042
- // because it will pick up creds from ctx.
1043
- if err := vfsObj .SetStatAt (ctx , fs .creds , & pop , & vfs.SetStatOptions {
1044
- Stat : parent .newChildOwnerStat (opts .Mode , creds ),
1045
- }); err != nil {
1046
- if cleanupErr := vfsObj .UnlinkAt (ctx , fs .creds , & pop ); cleanupErr != nil {
1047
- panic (fmt .Sprintf ("unrecoverable overlayfs inconsistency: failed to delete upper layer file after OpenAt(O_CREAT) metadata update failure: %v" , cleanupErr ))
1048
- } else if haveUpperWhiteout {
1049
- fs .cleanupRecreateWhiteout (ctx , vfsObj , & pop )
1050
- }
1051
- return nil , err
1052
- }
1053
1014
// Re-lookup to get a dentry representing the new file, which is needed for
1054
1015
// the returned FD.
1055
1016
child , _ , err := fs .getChildLocked (ctx , parent , childName , ds )
@@ -1609,27 +1570,13 @@ func (fs *filesystem) SymlinkAt(ctx context.Context, rp *vfs.ResolvingPath, targ
1609
1570
return err
1610
1571
}
1611
1572
}
1612
- if err := vfsObj .SymlinkAt (ctx , fs .creds , & pop , target ); err != nil {
1573
+ createCreds := parent .credsForCreate (rp .Credentials (), parent .isSGIDSet ())
1574
+ if err := vfsObj .SymlinkAt (ctx , createCreds , & pop , target ); err != nil {
1613
1575
if haveUpperWhiteout {
1614
1576
fs .cleanupRecreateWhiteout (ctx , vfsObj , & pop )
1615
1577
}
1616
1578
return err
1617
1579
}
1618
- creds := rp .Credentials ()
1619
- if err := vfsObj .SetStatAt (ctx , fs .creds , & pop , & vfs.SetStatOptions {
1620
- Stat : linux.Statx {
1621
- Mask : linux .STATX_UID | linux .STATX_GID ,
1622
- UID : uint32 (creds .EffectiveKUID ),
1623
- GID : uint32 (creds .EffectiveKGID ),
1624
- },
1625
- }); err != nil {
1626
- if cleanupErr := vfsObj .UnlinkAt (ctx , fs .creds , & pop ); cleanupErr != nil {
1627
- panic (fmt .Sprintf ("unrecoverable overlayfs inconsistency: failed to delete upper layer file after SymlinkAt metadata update failure: %v" , cleanupErr ))
1628
- } else if haveUpperWhiteout {
1629
- fs .cleanupRecreateWhiteout (ctx , vfsObj , & pop )
1630
- }
1631
- return err
1632
- }
1633
1580
return nil
1634
1581
})
1635
1582
}
0 commit comments