Skip to content

Commit db7fb6f

Browse files
Christian BraunerSteve French
authored andcommitted
ksmbd: remove setattr preparations in set_file_basic_info()
Permission checking and copying over ownership information is the task of the underlying filesystem not ksmbd. The order is also wrong here. This modifies the inode before notify_change(). If notify_change() fails this will have changed ownership nonetheless. All of this is unnecessary though since the underlying filesystem's ->setattr handler will do all this (if required) by itself. Cc: Steve French <stfrench@microsoft.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: Namjae Jeon <namjae.jeon@samsung.com> Cc: Hyunchul Lee <hyc.lee@gmail.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: linux-cifs@vger.kernel.org Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent eb5784f commit db7fb6f

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

fs/ksmbd/smb2pdu.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5440,7 +5440,7 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf,
54405440
{
54415441
struct smb2_file_all_info *file_info;
54425442
struct iattr attrs;
5443-
struct iattr temp_attrs;
5443+
struct timespec64 ctime;
54445444
struct file *filp;
54455445
struct inode *inode;
54465446
struct user_namespace *user_ns;
@@ -5464,11 +5464,11 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf,
54645464
}
54655465

54665466
if (file_info->ChangeTime) {
5467-
temp_attrs.ia_ctime = ksmbd_NTtimeToUnix(file_info->ChangeTime);
5468-
attrs.ia_ctime = temp_attrs.ia_ctime;
5467+
attrs.ia_ctime = ksmbd_NTtimeToUnix(file_info->ChangeTime);
5468+
ctime = attrs.ia_ctime;
54695469
attrs.ia_valid |= ATTR_CTIME;
54705470
} else {
5471-
temp_attrs.ia_ctime = inode->i_ctime;
5471+
ctime = inode->i_ctime;
54725472
}
54735473

54745474
if (file_info->LastWriteTime) {
@@ -5507,28 +5507,19 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf,
55075507
rc = 0;
55085508
}
55095509

5510-
/*
5511-
* HACK : set ctime here to avoid ctime changed
5512-
* when file_info->ChangeTime is zero.
5513-
*/
5514-
attrs.ia_ctime = temp_attrs.ia_ctime;
5515-
attrs.ia_valid |= ATTR_CTIME;
5516-
55175510
if (attrs.ia_valid) {
55185511
struct dentry *dentry = filp->f_path.dentry;
55195512
struct inode *inode = d_inode(dentry);
55205513

55215514
if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
55225515
return -EACCES;
55235516

5524-
rc = setattr_prepare(user_ns, dentry, &attrs);
5525-
if (rc)
5526-
return -EINVAL;
5527-
55285517
inode_lock(inode);
5529-
setattr_copy(user_ns, inode, &attrs);
5530-
attrs.ia_valid &= ~ATTR_CTIME;
55315518
rc = notify_change(user_ns, dentry, &attrs, NULL);
5519+
if (!rc) {
5520+
inode->i_ctime = ctime;
5521+
mark_inode_dirty(inode);
5522+
}
55325523
inode_unlock(inode);
55335524
}
55345525
return rc;

0 commit comments

Comments
 (0)