Skip to content

Commit c175360

Browse files
ayushr2gvisor-bot
authored andcommitted
gofer: Skip making SetStat RPC if UID/GID is not changing.
PiperOrigin-RevId: 764809066
1 parent 74b20fc commit c175360

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

pkg/sentry/fsimpl/gofer/gofer.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,12 +1278,26 @@ func (d *dentry) setStat(ctx context.Context, creds *auth.Credentials, opts *vfs
12781278
d.metadataMu.Lock()
12791279
defer d.metadataMu.Unlock()
12801280

1281+
isOwnerChanging := false
1282+
if stat.Mask&linux.STATX_UID != 0 {
1283+
if stat.UID == d.uid.RacyLoad() {
1284+
stat.Mask &^= linux.STATX_UID
1285+
} else {
1286+
isOwnerChanging = true
1287+
}
1288+
}
1289+
if stat.Mask&linux.STATX_GID != 0 {
1290+
if stat.GID == d.gid.RacyLoad() {
1291+
stat.Mask &^= linux.STATX_GID
1292+
} else {
1293+
isOwnerChanging = true
1294+
}
1295+
}
1296+
12811297
// As with Linux, if the UID, GID, or file size is changing, we have to
12821298
// clear permission bits. Note that when set, clearSGID may cause
12831299
// permissions to be updated.
1284-
clearSGID := (stat.Mask&linux.STATX_UID != 0 && stat.UID != d.uid.Load()) ||
1285-
(stat.Mask&linux.STATX_GID != 0 && stat.GID != d.gid.Load()) ||
1286-
stat.Mask&linux.STATX_SIZE != 0
1300+
clearSGID := isOwnerChanging || stat.Mask&linux.STATX_SIZE != 0
12871301
if clearSGID {
12881302
if stat.Mask&linux.STATX_MODE != 0 {
12891303
stat.Mode = uint16(vfs.ClearSUIDAndSGID(uint32(stat.Mode)))

0 commit comments

Comments
 (0)