smb/client: fix nlink of an overwritten open file
Subsystems (2)
PATCH 1/1 smb/client: fix nlink of an overwritten open file
From: ChenXiaoSong <[email protected]>
Reproducer:
1. server: systemctl start ksmbd
2. client: mount with posix option
mount -t cifs -o posix //${server_ip}/export /mnt 3. client: touch /mnt/file1 /mnt/file2
4. client: C program: int fd = open("/mnt/file2", O_RDONLY);
5. client: C program: rename("/mnt/file1", "/mnt/file2");
6. client: C program: struct stat stbuf; fstat(fd, &stbuf); stbuf.st_nlink is 1, should be 0
This patch fixes xfstests generic/035 when mounted with posix option.
--- fs/smb/client/inode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
fs/smb/client/inode.c +6 -5
@@ -2648,11 +2648,8 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir,if (d_really_is_positive (target_dentry)) {if (!rc) {struct inode *inode =d_inode (target_dentry); -/* -* Samba and ksmbd servers allow renaming a target -* directory that is open, so make sure to update -* ->i_nlink and then mark it as delete pending. -*/ + +/* Update the target link count after rename. */ if (S_ISDIR (inode->i_mode)) {drop_cached_dir_by_name (xid, tcon, to_name, cifs_sb);spin_lock (&inode->i_lock);
@@ -2663,6 +2660,10 @@ cifs_rename2(struct mnt_idmap *idmap, struct inode *source_dir,CIFS_I (inode)->time =0 ;/* force reval */ inode_set_ctime_current (inode);inode_set_mtime_to_ts (inode,inode_set_ctime_current (inode)); + }else { +cifs_mark_open_handles_for_deleted_file (inode, to_name); +cifs_drop_nlink (inode); +inode_set_ctime_current (inode); } }else if (rc == -EACCES || rc == -EEXIST ) {/*
Signature · 1 line
2.53.0
Namjae Jeon
maintainerQuoted 14 lines · Steve French
From: ChenXiaoSong <[email protected]>
Reproducer:
1. server: systemctl start ksmbd
2. client: mount withposixoptionmount -t cifs -o posix //${server_ip}/export /mnt3. client: touch
/mnt/file1/mnt/file2
4. client: C program: int fd =open("/mnt/file2", O_RDONLY);
5. client: C program:rename("/mnt/file1", "/mnt/file2");
6. client: C program: struct stat stbuf;fstat(fd, &stbuf); stbuf.st_nlink is 1, should be 0
Quoted 4 lines
This patch fixes xfstests generic/035 when mounted with
posixoption.Signed-off-by ChenXiaoSong <[email protected]>Signed-off-by Steve French <[email protected]>
Will apply it to #for-next.
Thanks!