Skip to content

Commit bf9f243

Browse files
committed
Merge tag '5.15-rc-ksmbd-part2' of git://git.samba.org/ksmbd
Pull ksmbd fixes from Steve French: - various fixes pointed out by coverity, and a minor cleanup patch - id mapping and ownership fixes - an smbdirect fix * tag '5.15-rc-ksmbd-part2' of git://git.samba.org/ksmbd: ksmbd: fix control flow issues in sid_to_id() ksmbd: fix read of uninitialized variable ret in set_file_basic_info ksmbd: add missing assignments to ret on ndr_read_int64 read calls ksmbd: add validation for ndr read/write functions ksmbd: remove unused ksmbd_file_table_flush function ksmbd: smbd: fix dma mapping error in smb_direct_post_send_data ksmbd: Reduce error log 'speed is unknown' to debug ksmbd: defer notify_change() call ksmbd: remove setattr preparations in set_file_basic_info() ksmbd: ensure error is surfaced in set_file_basic_info() ndr: fix translation in ndr_encode_posix_acl() ksmbd: fix translation in sid_to_id() ksmbd: fix subauth 0 handling in sid_to_id() ksmbd: fix translation in acl entries ksmbd: fix translation in ksmbd_acls_fattr() ksmbd: fix translation in create_posix_rsp_buf() ksmbd: fix translation in smb2_populate_readdir_entry() ksmbd: fix lookup on idmapped mounts
2 parents 8dde208 + 4cf0ccd commit bf9f243

File tree

12 files changed

+413
-223
lines changed

12 files changed

+413
-223
lines changed

fs/ksmbd/ndr.c

Lines changed: 274 additions & 109 deletions
Large diffs are not rendered by default.

fs/ksmbd/oplock.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,9 +1614,11 @@ void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp)
16141614
buf->nlink = cpu_to_le32(inode->i_nlink);
16151615
buf->reparse_tag = cpu_to_le32(fp->volatile_id);
16161616
buf->mode = cpu_to_le32(inode->i_mode);
1617-
id_to_sid(from_kuid(user_ns, inode->i_uid),
1617+
id_to_sid(from_kuid_munged(&init_user_ns,
1618+
i_uid_into_mnt(user_ns, inode)),
16181619
SIDNFS_USER, (struct smb_sid *)&buf->SidBuffer[0]);
1619-
id_to_sid(from_kgid(user_ns, inode->i_gid),
1620+
id_to_sid(from_kgid_munged(&init_user_ns,
1621+
i_gid_into_mnt(user_ns, inode)),
16201622
SIDNFS_GROUP, (struct smb_sid *)&buf->SidBuffer[20]);
16211623
}
16221624

fs/ksmbd/smb2pdu.c

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,10 +2381,12 @@ static int smb2_create_sd_buffer(struct ksmbd_work *work,
23812381
le32_to_cpu(sd_buf->ccontext.DataLength), true);
23822382
}
23832383

2384-
static void ksmbd_acls_fattr(struct smb_fattr *fattr, struct inode *inode)
2384+
static void ksmbd_acls_fattr(struct smb_fattr *fattr,
2385+
struct user_namespace *mnt_userns,
2386+
struct inode *inode)
23852387
{
2386-
fattr->cf_uid = inode->i_uid;
2387-
fattr->cf_gid = inode->i_gid;
2388+
fattr->cf_uid = i_uid_into_mnt(mnt_userns, inode);
2389+
fattr->cf_gid = i_gid_into_mnt(mnt_userns, inode);
23882390
fattr->cf_mode = inode->i_mode;
23892391
fattr->cf_acls = NULL;
23902392
fattr->cf_dacls = NULL;
@@ -2893,7 +2895,7 @@ int smb2_open(struct ksmbd_work *work)
28932895
struct smb_ntsd *pntsd;
28942896
int pntsd_size, ace_num = 0;
28952897

2896-
ksmbd_acls_fattr(&fattr, inode);
2898+
ksmbd_acls_fattr(&fattr, user_ns, inode);
28972899
if (fattr.cf_acls)
28982900
ace_num = fattr.cf_acls->a_count;
28992901
if (fattr.cf_dacls)
@@ -3324,7 +3326,6 @@ static int dentry_name(struct ksmbd_dir_info *d_info, int info_level)
33243326
*/
33253327
static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
33263328
struct ksmbd_dir_info *d_info,
3327-
struct user_namespace *user_ns,
33283329
struct ksmbd_kstat *ksmbd_kstat)
33293330
{
33303331
int next_entry_offset = 0;
@@ -3478,9 +3479,9 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level,
34783479
S_ISDIR(ksmbd_kstat->kstat->mode) ? ATTR_DIRECTORY_LE : ATTR_ARCHIVE_LE;
34793480
if (d_info->hide_dot_file && d_info->name[0] == '.')
34803481
posix_info->DosAttributes |= ATTR_HIDDEN_LE;
3481-
id_to_sid(from_kuid(user_ns, ksmbd_kstat->kstat->uid),
3482+
id_to_sid(from_kuid_munged(&init_user_ns, ksmbd_kstat->kstat->uid),
34823483
SIDNFS_USER, (struct smb_sid *)&posix_info->SidBuffer[0]);
3483-
id_to_sid(from_kgid(user_ns, ksmbd_kstat->kstat->gid),
3484+
id_to_sid(from_kgid_munged(&init_user_ns, ksmbd_kstat->kstat->gid),
34843485
SIDNFS_GROUP, (struct smb_sid *)&posix_info->SidBuffer[20]);
34853486
memcpy(posix_info->name, conv_name, conv_len);
34863487
posix_info->name_len = cpu_to_le32(conv_len);
@@ -3543,9 +3544,9 @@ static int process_query_dir_entries(struct smb2_query_dir_private *priv)
35433544
return -EINVAL;
35443545

35453546
lock_dir(priv->dir_fp);
3546-
dent = lookup_one_len(priv->d_info->name,
3547-
priv->dir_fp->filp->f_path.dentry,
3548-
priv->d_info->name_len);
3547+
dent = lookup_one(user_ns, priv->d_info->name,
3548+
priv->dir_fp->filp->f_path.dentry,
3549+
priv->d_info->name_len);
35493550
unlock_dir(priv->dir_fp);
35503551

35513552
if (IS_ERR(dent)) {
@@ -3571,7 +3572,6 @@ static int process_query_dir_entries(struct smb2_query_dir_private *priv)
35713572
rc = smb2_populate_readdir_entry(priv->work->conn,
35723573
priv->info_level,
35733574
priv->d_info,
3574-
user_ns,
35753575
&ksmbd_kstat);
35763576
dput(dent);
35773577
if (rc)
@@ -5008,7 +5008,7 @@ static int smb2_get_info_sec(struct ksmbd_work *work,
50085008

50095009
user_ns = file_mnt_user_ns(fp->filp);
50105010
inode = file_inode(fp->filp);
5011-
ksmbd_acls_fattr(&fattr, inode);
5011+
ksmbd_acls_fattr(&fattr, user_ns, inode);
50125012

50135013
if (test_share_config_flag(work->tcon->share_conf,
50145014
KSMBD_SHARE_FLAG_ACL_XATTR))
@@ -5246,7 +5246,9 @@ int smb2_echo(struct ksmbd_work *work)
52465246
return 0;
52475247
}
52485248

5249-
static int smb2_rename(struct ksmbd_work *work, struct ksmbd_file *fp,
5249+
static int smb2_rename(struct ksmbd_work *work,
5250+
struct ksmbd_file *fp,
5251+
struct user_namespace *user_ns,
52505252
struct smb2_file_rename_info *file_info,
52515253
struct nls_table *local_nls)
52525254
{
@@ -5310,7 +5312,7 @@ static int smb2_rename(struct ksmbd_work *work, struct ksmbd_file *fp,
53105312
if (rc)
53115313
goto out;
53125314

5313-
rc = ksmbd_vfs_setxattr(file_mnt_user_ns(fp->filp),
5315+
rc = ksmbd_vfs_setxattr(user_ns,
53145316
fp->filp->f_path.dentry,
53155317
xattr_stream_name,
53165318
NULL, 0, 0);
@@ -5438,11 +5440,11 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf,
54385440
{
54395441
struct smb2_file_all_info *file_info;
54405442
struct iattr attrs;
5441-
struct iattr temp_attrs;
5443+
struct timespec64 ctime;
54425444
struct file *filp;
54435445
struct inode *inode;
54445446
struct user_namespace *user_ns;
5445-
int rc;
5447+
int rc = 0;
54465448

54475449
if (!(fp->daccess & FILE_WRITE_ATTRIBUTES_LE))
54485450
return -EACCES;
@@ -5462,11 +5464,11 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf,
54625464
}
54635465

54645466
if (file_info->ChangeTime) {
5465-
temp_attrs.ia_ctime = ksmbd_NTtimeToUnix(file_info->ChangeTime);
5466-
attrs.ia_ctime = temp_attrs.ia_ctime;
5467+
attrs.ia_ctime = ksmbd_NTtimeToUnix(file_info->ChangeTime);
5468+
ctime = attrs.ia_ctime;
54675469
attrs.ia_valid |= ATTR_CTIME;
54685470
} else {
5469-
temp_attrs.ia_ctime = inode->i_ctime;
5471+
ctime = inode->i_ctime;
54705472
}
54715473

54725474
if (file_info->LastWriteTime) {
@@ -5505,31 +5507,22 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf,
55055507
rc = 0;
55065508
}
55075509

5508-
/*
5509-
* HACK : set ctime here to avoid ctime changed
5510-
* when file_info->ChangeTime is zero.
5511-
*/
5512-
attrs.ia_ctime = temp_attrs.ia_ctime;
5513-
attrs.ia_valid |= ATTR_CTIME;
5514-
55155510
if (attrs.ia_valid) {
55165511
struct dentry *dentry = filp->f_path.dentry;
55175512
struct inode *inode = d_inode(dentry);
55185513

55195514
if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
55205515
return -EACCES;
55215516

5522-
rc = setattr_prepare(user_ns, dentry, &attrs);
5523-
if (rc)
5524-
return -EINVAL;
5525-
55265517
inode_lock(inode);
5527-
setattr_copy(user_ns, inode, &attrs);
5528-
attrs.ia_valid &= ~ATTR_CTIME;
55295518
rc = notify_change(user_ns, dentry, &attrs, NULL);
5519+
if (!rc) {
5520+
inode->i_ctime = ctime;
5521+
mark_inode_dirty(inode);
5522+
}
55305523
inode_unlock(inode);
55315524
}
5532-
return 0;
5525+
return rc;
55335526
}
55345527

55355528
static int set_file_allocation_info(struct ksmbd_work *work,
@@ -5624,6 +5617,7 @@ static int set_end_of_file_info(struct ksmbd_work *work, struct ksmbd_file *fp,
56245617
static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp,
56255618
char *buf)
56265619
{
5620+
struct user_namespace *user_ns;
56275621
struct ksmbd_file *parent_fp;
56285622
struct dentry *parent;
56295623
struct dentry *dentry = fp->filp->f_path.dentry;
@@ -5634,11 +5628,12 @@ static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp,
56345628
return -EACCES;
56355629
}
56365630

5631+
user_ns = file_mnt_user_ns(fp->filp);
56375632
if (ksmbd_stream_fd(fp))
56385633
goto next;
56395634

56405635
parent = dget_parent(dentry);
5641-
ret = ksmbd_vfs_lock_parent(parent, dentry);
5636+
ret = ksmbd_vfs_lock_parent(user_ns, parent, dentry);
56425637
if (ret) {
56435638
dput(parent);
56445639
return ret;
@@ -5655,7 +5650,7 @@ static int set_rename_info(struct ksmbd_work *work, struct ksmbd_file *fp,
56555650
}
56565651
}
56575652
next:
5658-
return smb2_rename(work, fp,
5653+
return smb2_rename(work, fp, user_ns,
56595654
(struct smb2_file_rename_info *)buf,
56605655
work->sess->conn->local_nls);
56615656
}
@@ -7116,8 +7111,8 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
71167111
netdev->ethtool_ops->get_link_ksettings(netdev, &cmd);
71177112
speed = cmd.base.speed;
71187113
} else {
7119-
pr_err("%s %s\n", netdev->name,
7120-
"speed is unknown, defaulting to 1Gb/sec");
7114+
ksmbd_debug(SMB, "%s %s\n", netdev->name,
7115+
"speed is unknown, defaulting to 1Gb/sec");
71217116
speed = SPEED_1000;
71227117
}
71237118

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)