Opening a hard link of a file that currently holds a lease fails with EINVAL over SMB3. The client caches lease keys per inode, but the server ties a lease to the file name it was granted under, so reusing the inode's lease key to open a different name of the same inode is rejected with STATUS_INVALID_PARAMETER (MS-SMB2 3.3.5.9.11). Resend the open without a lease when it is rejected that way, as smb2_rename_path() already does. Fold it into the same retry loop as the FILE_READ_ATTRIBUTES fallback so either can follow the other in whichever order the server rejects them. Reacting to the server response covers every case - including a name kept open by an active handle - without racing a handle opened concurrently. Reported-by: Giuseppe Piscitelli Closes: https://lore.kernel.org/r/CACmoRBbDZR3eyEM65j73sWMS7A=T89z1QAvCP=+u0WGzZhwW6g@mail.gmail.com Fixes: 262b73ef442e ("smb3 client: fix open hardlink on deferred close file error") Cc: stable@vger.kernel.org Signed-off-by: Paulo Alcantara --- fs/smb/client/smb2file.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/smb/client/smb2file.c b/fs/smb/client/smb2file.c index 764cfd894ad0..4369621393a0 100644 --- a/fs/smb/client/smb2file.c +++ b/fs/smb/client/smb2file.c @@ -201,18 +201,27 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, } smb2_oplock = SMB2_OPLOCK_LEVEL_BATCH; - rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data, NULL, &err_iov, - &err_buftype); - if (rc == -EACCES && retry_without_read_attributes && - !oparms->pending) { + for (;;) { + rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data, NULL, + &err_iov, &err_buftype); + if (oparms->pending) + break; + if (rc == -EACCES && retry_without_read_attributes) { + retry_without_read_attributes = false; + oparms->desired_access &= ~FILE_READ_ATTRIBUTES; + } else if (rc == -EINVAL && + smb2_oplock != SMB2_OPLOCK_LEVEL_NONE) { + cifs_dbg(FYI, "%s: invalid lease key, resending request without lease\n", + __func__); + smb2_oplock = SMB2_OPLOCK_LEVEL_NONE; + } else { + break; + } free_rsp_buf(err_buftype, err_iov.iov_base); memset(&err_iov, 0, sizeof(err_iov)); err_buftype = CIFS_NO_BUFFER; - oparms->desired_access &= ~FILE_READ_ATTRIBUTES; oparms->reconnect = reconnect; oparms->replay = false; - rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, data, NULL, &err_iov, - &err_buftype); } if (rc && data) { struct smb2_hdr *hdr = err_iov.iov_base; -- 2.56.0