Skip to content

Commit cc82c6d

Browse files
Shuhao Fugregkh
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 f09b0b4 commit cc82c6d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/smb/client/smb2inode.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
207207
server = cifs_pick_channel(ses);
208208

209209
vars = kzalloc(sizeof(*vars), GFP_ATOMIC);
210-
if (vars == NULL)
211-
return -ENOMEM;
210+
if (vars == NULL) {
211+
rc = -ENOMEM;
212+
goto out;
213+
}
212214
rqst = &vars->rqst[0];
213215
rsp_iov = &vars->rsp_iov[0];
214216

@@ -864,6 +866,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
864866
smb2_should_replay(tcon, &retries, &cur_sleep))
865867
goto replay_again;
866868

869+
out:
867870
if (cfile)
868871
cifsFileInfo_put(cfile);
869872

0 commit comments

Comments
 (0)