Skip to content

Commit

Permalink
fix/acl: clear sgid in some cases (#4551)
Browse files Browse the repository at this point in the history
Signed-off-by: jiefenghuang <[email protected]>
  • Loading branch information
jiefenghuang authored Mar 21, 2024
1 parent 249ea17 commit a190f55
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -2930,3 +2930,12 @@ func (m *baseMeta) GetFacl(ctx Context, ino Ino, aclType uint8, rule *aclAPI.Rul

return m.en.doGetFacl(ctx, ino, aclType, aclAPI.None, rule)
}

func inGroup(ctx Context, gid uint32) bool {
for _, egid := range ctx.Gids() {
if egid == gid {
return true
}
}
return false
}
8 changes: 8 additions & 0 deletions pkg/meta/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4647,6 +4647,14 @@ func (m *redisMeta) doSetFacl(ctx Context, ino Ino, aclType uint8, rule *aclAPI.
}

oriACL, oriMode := getAttrACLId(attr, aclType), attr.Mode

// https://github.com/torvalds/linux/blob/480e035fc4c714fb5536e64ab9db04fedc89e910/fs/fuse/acl.c#L143-L151
// TODO: check linux capabilities
if ctx.Uid() != 0 && !inGroup(ctx, attr.Gid) {
// clear sgid
attr.Mode &= 05777
}

if rule.IsEmpty() {
// remove acl
setAttrACLId(attr, aclType, aclAPI.None)
Expand Down
8 changes: 8 additions & 0 deletions pkg/meta/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4571,6 +4571,14 @@ func (m *dbMeta) doSetFacl(ctx Context, ino Ino, aclType uint8, rule *aclAPI.Rul
}

oriACL, oriMode := getAttrACLId(attr, aclType), attr.Mode

// https://github.com/torvalds/linux/blob/480e035fc4c714fb5536e64ab9db04fedc89e910/fs/fuse/acl.c#L143-L151
// TODO: check linux capabilities
if ctx.Uid() != 0 && !inGroup(ctx, attr.Gid) {
// clear sgid
attr.Mode &= 05777
}

if rule.IsEmpty() {
// remove acl
setAttrACLId(attr, aclType, aclAPI.None)
Expand Down
8 changes: 8 additions & 0 deletions pkg/meta/tkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,14 @@ func (m *kvMeta) doSetFacl(ctx Context, ino Ino, aclType uint8, rule *aclAPI.Rul
}

oriACL, oriMode := getAttrACLId(attr, aclType), attr.Mode

// https://github.com/torvalds/linux/blob/480e035fc4c714fb5536e64ab9db04fedc89e910/fs/fuse/acl.c#L143-L151
// TODO: check linux capabilities
if ctx.Uid() != 0 && !inGroup(ctx, attr.Gid) {
// clear sgid
attr.Mode &= 05777
}

if rule.IsEmpty() {
// remove acl
setAttrACLId(attr, aclType, aclAPI.None)
Expand Down

0 comments on commit a190f55

Please sign in to comment.