Skip to content

Commit 475d6f9

Browse files
Christian Braunersmfrench
authored andcommitted
ksmbd: fix translation in smb2_populate_readdir_entry()
When transferring ownership information to the client the k*ids are translated into raw *ids before they are sent over the wire. The function currently erroneously translates the k*ids according to the mount's idmapping. Instead, reporting the owning *ids to userspace the underlying k*ids need to be mapped up in the caller's user namespace. This is how stat() works. The caller in this instance is ksmbd itself and ksmbd always runs in the initial user namespace. Translate according to that. The idmapping of the mount is already taken into account by the lower filesystem and so kstat->*id will contain the mapped k*ids. Switch to from_k*id_munged() which ensures that the overflow*id is returned instead of the (*id_t)-1 when the k*id can't be translated. 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 da1e7ad commit 475d6f9

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

fs/ksmbd/smb2pdu.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,7 +3324,6 @@ static int dentry_name(struct ksmbd_dir_info *d_info, int info_level)
33243324
*/
33253325
static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
33263326
struct ksmbd_dir_info *d_info,
3327-
struct user_namespace *user_ns,
33283327
struct ksmbd_kstat *ksmbd_kstat)
33293328
{
33303329
int next_entry_offset = 0;
@@ -3478,9 +3477,9 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
34783477
S_ISDIR(ksmbd_kstat->kstat->mode) ? ATTR_DIRECTORY_LE : ATTR_ARCHIVE_LE;
34793478
if (d_info->hide_dot_file && d_info->name[0] == '.')
34803479
posix_info->DosAttributes |= ATTR_HIDDEN_LE;
3481-
id_to_sid(from_kuid(user_ns, ksmbd_kstat->kstat->uid),
3480+
id_to_sid(from_kuid_munged(&init_user_ns, ksmbd_kstat->kstat->uid),
34823481
SIDNFS_USER, (struct smb_sid *)&posix_info->SidBuffer[0]);
3483-
id_to_sid(from_kgid(user_ns, ksmbd_kstat->kstat->gid),
3482+
id_to_sid(from_kgid_munged(&init_user_ns, ksmbd_kstat->kstat->gid),
34843483
SIDNFS_GROUP, (struct smb_sid *)&posix_info->SidBuffer[20]);
34853484
memcpy(posix_info->name, conv_name, conv_len);
34863485
posix_info->name_len = cpu_to_le32(conv_len);
@@ -3571,7 +3570,6 @@ static int process_query_dir_entries(struct smb2_query_dir_private *priv)
35713570
rc = smb2_populate_readdir_entry(priv->work->conn,
35723571
priv->info_level,
35733572
priv->d_info,
3574-
user_ns,
35753573
&ksmbd_kstat);
35763574
dput(dent);
35773575
if (rc)

fs/ksmbd/smb_common.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level,
291291
char *search_pattern,
292292
int (*fn)(struct ksmbd_conn *, int,
293293
struct ksmbd_dir_info *,
294-
struct user_namespace *,
295294
struct ksmbd_kstat *))
296295
{
297296
int i, rc = 0;
@@ -322,8 +321,7 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level,
322321
user_ns,
323322
dir->filp->f_path.dentry->d_parent,
324323
&ksmbd_kstat);
325-
rc = fn(conn, info_level, d_info,
326-
user_ns, &ksmbd_kstat);
324+
rc = fn(conn, info_level, d_info, &ksmbd_kstat);
327325
if (rc)
328326
break;
329327
if (d_info->out_buf_len <= 0)

fs/ksmbd/smb_common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work,
511511
int (*fn)(struct ksmbd_conn *,
512512
int,
513513
struct ksmbd_dir_info *,
514-
struct user_namespace *,
515514
struct ksmbd_kstat *));
516515

517516
int ksmbd_extract_shortname(struct ksmbd_conn *conn,

0 commit comments

Comments
 (0)