]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
smb/server: do not require delete access for non-replacing links
authorChenXiaoSong <chenxiaosong@kylinos.cn>
Sun, 28 Jun 2026 07:42:43 +0000 (07:42 +0000)
committerSteve French <stfrench@microsoft.com>
Wed, 1 Jul 2026 02:29:46 +0000 (21:29 -0500)
Reproducer:

  1. server: systemctl start ksmbd
  2. client: mount -t cifs //${server_ip}/export /mnt
  3. client: touch /mnt/file; ln /mnt/file /mnt/hardlink
  4. client err log: ln: failed to create hard link 'hardlink' =>
     'file': Permission denied
  5. server err log: ksmbd: no right to delete : 0x80

Fixes: 13f3942f2bf4 ("ksmbd: add per-handle permission check to FILE_LINK_INFORMATION")
Cc: stable@vger.kernel.org
Reported-by: Steve French <stfrench@microsoft.com>
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/smb2pdu.c

index 727ba86ede36e6c5dd068a316605ee05086560e5..097f51fc7ed6a5926462a19dab17da077fff7b22 100644 (file)
@@ -6921,16 +6921,18 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp,
        }
        case FILE_LINK_INFORMATION:
        {
-               if (!(fp->daccess & FILE_DELETE_LE)) {
-                       pr_err("no right to delete : 0x%x\n", fp->daccess);
-                       return -EACCES;
-               }
+               struct smb2_file_link_info *file_info;
 
                if (buf_len < sizeof(struct smb2_file_link_info))
                        return -EMSGSIZE;
 
-               return smb2_create_link(work, work->tcon->share_conf,
-                                       (struct smb2_file_link_info *)buffer,
+               file_info = (struct smb2_file_link_info *)buffer;
+               if (file_info->ReplaceIfExists && !(fp->daccess & FILE_DELETE_LE)) {
+                       pr_err("no right to delete : 0x%x\n", fp->daccess);
+                       return -EACCES;
+               }
+
+               return smb2_create_link(work, work->tcon->share_conf, file_info,
                                        buf_len, fp->filp,
                                        work->conn->local_nls);
        }