Skip to content

Commit 3fc11ff

Browse files
sfu2gregkh
authored andcommitted
fs/smb: Fix inconsistent refcnt update
commit ab529e6 upstream. A possible inconsistent update of refcount was identified in `smb2_compound_op`. Such inconsistent update could lead to possible resource leaks. Why it is a possible bug: 1. In the comment section of the function, it clearly states that the reference to `cfile` should be dropped after calling this function. 2. Every control flow path would check and drop the reference to `cfile`, except the patched one. 3. Existing callers would not handle refcount update of `cfile` if -ENOMEM is returned. To fix the bug, an extra goto label "out" is added, to make sure that the cleanup logic would always be respected. As the problem is caused by the allocation failure of `vars`, the cleanup logic between label "finished" and "out" can be safely ignored. According to the definition of function `is_replayable_error`, the error code of "-ENOMEM" is not recoverable. Therefore, the replay logic also gets ignored. Signed-off-by: Shuhao Fu <sfual@cse.ust.hk> Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.org> Cc: stable@vger.kernel.org Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7623279 commit 3fc11ff

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

fs/smb/client/smb2inode.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
8181
int len;
8282

8383
vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
84-
if (vars == NULL)
85-
return -ENOMEM;
84+
if (vars == NULL) {
85+
rc = -ENOMEM;
86+
goto out;
87+
}
8688
rqst = &vars->rqst[0];
8789
rsp_iov = &vars->rsp_iov[0];
8890

@@ -510,6 +512,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
510512
break;
511513
}
512514

515+
out:
513516
if (cfile)
514517
cifsFileInfo_put(cfile);
515518

0 commit comments

Comments
 (0)