Skip to content

Commit

Permalink
cifs: Fix xid leak in cifs_flock()
Browse files Browse the repository at this point in the history
[ Upstream commit 575e079 ]

If not flock, before return -ENOLCK, should free the xid,
otherwise, the xid will be leaked.

Fixes: d067799 ("cifs: add support for flock")
Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
z00467499 authored and gregkh committed Oct 29, 2022
1 parent 27cfd3a commit 8905d13
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1806,11 +1806,13 @@ int cifs_flock(struct file *file, int cmd, struct file_lock *fl)
struct cifsFileInfo *cfile;
__u32 type;

rc = -EACCES;
xid = get_xid();

if (!(fl->fl_flags & FL_FLOCK))
return -ENOLCK;
if (!(fl->fl_flags & FL_FLOCK)) {
rc = -ENOLCK;
free_xid(xid);
return rc;
}

cfile = (struct cifsFileInfo *)file->private_data;
tcon = tlink_tcon(cfile->tlink);
Expand All @@ -1829,8 +1831,9 @@ int cifs_flock(struct file *file, int cmd, struct file_lock *fl)
* if no lock or unlock then nothing to do since we do not
* know what it is
*/
rc = -EOPNOTSUPP;
free_xid(xid);
return -EOPNOTSUPP;
return rc;
}

rc = cifs_setlk(file, fl, type, wait_flag, posix_lck, lock, unlock,
Expand Down

0 comments on commit 8905d13

Please sign in to comment.