Skip to content

Commit 55cd04d

Browse files
Christian Braunersmfrench
authored andcommitted
ksmbd: fix translation in sid_to_id()
The sid_to_id() functions is relevant when changing ownership of filesystem objects based on acl information. In this case we need to first translate the relevant s*ids into k*ids in ksmbd's user namespace and account for any idmapped mounts. Requesting a change in ownership requires the inverse translation to be applied when we would report ownership to userspace. So k*id_from_mnt() must be used here. Cc: Steve French <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Namjae Jeon <[email protected]> Cc: Hyunchul Lee <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Cc: [email protected] Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent f0bb29d commit 55cd04d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

fs/ksmbd/smbacl.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,15 @@ static int sid_to_id(struct user_namespace *user_ns,
275275

276276
id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]);
277277
if (id >= 0) {
278-
uid = make_kuid(user_ns, id);
279-
if (uid_valid(uid) && kuid_has_mapping(user_ns, uid)) {
278+
/*
279+
* Translate raw sid into kuid in the server's user
280+
* namespace.
281+
*/
282+
uid = make_kuid(&init_user_ns, id);
283+
284+
/* If this is an idmapped mount, apply the idmapping. */
285+
uid = kuid_from_mnt(user_ns, uid);
286+
if (uid_valid(uid)) {
280287
fattr->cf_uid = uid;
281288
rc = 0;
282289
}
@@ -287,8 +294,15 @@ static int sid_to_id(struct user_namespace *user_ns,
287294

288295
id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]);
289296
if (id >= 0) {
290-
gid = make_kgid(user_ns, id);
291-
if (gid_valid(gid) && kgid_has_mapping(user_ns, gid)) {
297+
/*
298+
* Translate raw sid into kgid in the server's user
299+
* namespace.
300+
*/
301+
gid = make_kgid(&init_user_ns, id);
302+
303+
/* If this is an idmapped mount, apply the idmapping. */
304+
gid = kgid_from_mnt(user_ns, gid);
305+
if (gid_valid(gid)) {
292306
fattr->cf_gid = gid;
293307
rc = 0;
294308
}

0 commit comments

Comments
 (0)