Commit ef53451e authored by Zhang Xiaoxu's avatar Zhang Xiaoxu Committed by Lipeng Sang
Browse files

cifs: Fix xid leak in cifs_flock()

stable inclusion
from stable-v5.10.152
commit 2d08311aa3056a84bfdc09bc47777de6a9b16c30
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I73HJ0

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=2d08311aa3056a84bfdc09bc47777de6a9b16c30



--------------------------------

[ Upstream commit 575e079c ]

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

Fixes: d0677992 ("cifs: add support for flock")
Reviewed-by: default avatarPaulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: default avatarZhang Xiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarLipeng Sang <sanglipeng1@jd.com>
parent 822053fa
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -1735,11 +1735,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);
@@ -1758,8 +1760,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,