Skip to contentSkip to conversation

ksmbd: grant a POSIX ACL group entry only to the group's members

PATCH Applied Ian Bridges 2 participants 2 messages Nov 2

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: grant a POSIX ACL group entry only to the group's members

When no ACE of the DACL matches the caller, Everyone or Authenticated Users, smb_check_perm_dacl() falls back to the file's POSIX ACL. It takes the first ACL_USER or ACL_GROUP entry whose id equals the caller's uid. For ACL_GROUP, this compares a gid with the caller's uid. A numerical match grants the group's permissions even when the caller is not a member.

Match a group entry only when the caller is also in the group.

---

Notes:
Reachable on a share with "vfs objects = acl_xattr" when the fallback runs and the POSIX ACL has a group entry whose gid equals the caller's uid. Such entries come from setfacl or from ksmbd's own mapping of a DACL to POSIX. A guest account reaches it the same way on a share with "guest ok = yes".

The fallback retains its existing id match and adds a group membership check.

Tested on ksmbd-for-next d13da43938d1 with KASAN. Generated DACLs of one or two allow or deny ACEs were probed on files and directories as the owner, other users, group members, a guest and an anonymous session. In the tested cases, only the results of the guest account with the uid/gid collision change. It no longer gets the rights of the file's group, which it is not in. Its MAXIMUM_ALLOWED opens were granted with no access and are now refused, matching the maximal access reply. smbtorture gives the same results as on the base.

A reproducer is available on request.

This fix was developed with LLM assistance.

 fs/smb/server/smbacl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/smb/server/smbacl.c +4 -1
index 664f01263611..d9ceeb84d8da 100644
@@ -1625,7 +1625,10 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
 				else
 					continue;
 
-				if (id == uid) {
+				/* A group entry grants only to the group's members */
+				if (id == uid &&
+				    (pa_entry->e_tag == ACL_USER ||
+				     in_group_p(make_kgid(&init_user_ns, id)))) {
 					mode_to_access_flags(pa_entry->e_perm,
 							     0777,
 							     &access_bits);

base-commit: d13da43938d15b0b719827d8f2b32df8eaec5def

Signature · 1 line
2.47.3
maintainer Applied
#1 lore raw
Quoted 8 lines · Ian Bridges

When no ACE of the DACL matches the caller, Everyone or Authenticated Users, smb_check_perm_dacl() falls back to the file's POSIX ACL. It takes the first ACL_USER or ACL_GROUP entry whose id equals the caller's uid. For ACL_GROUP, this compares a gid with the caller's uid. A numerical match grants the group's permissions even when the caller is not a member.

Quoted 7 lines

Match a group entry only when the caller is also in the group.

Applied it to #ksmbd-for-next.
Thanks!