All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Marios Makassikis <mmakassikis@freebox.fr>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Steve French <stfrench@microsoft.com>,
	Sasha Levin <sashal@kernel.org>,
	sfrench@samba.org, linux-cifs@vger.kernel.org
Subject: [PATCH AUTOSEL 6.0 15/18] ksmbd: Fix resource leak in smb2_lock()
Date: Fri, 23 Dec 2022 20:30:31 -0500	[thread overview]
Message-ID: <20221224013034.392810-15-sashal@kernel.org> (raw)
In-Reply-To: <20221224013034.392810-1-sashal@kernel.org>

From: Marios Makassikis <mmakassikis@freebox.fr>

[ Upstream commit 01f6c61bae3d658058ee6322af77acea26a5ee3a ]

"flock" is leaked if an error happens before smb2_lock_init(), as the
lock is not added to the lock_list to be cleaned up.

Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ksmbd/smb2pdu.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index 7a9497a7b0a3..4e6e55714f4b 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -6835,6 +6835,7 @@ int smb2_lock(struct ksmbd_work *work)
 		if (lock_start > U64_MAX - lock_length) {
 			pr_err("Invalid lock range requested\n");
 			rsp->hdr.Status = STATUS_INVALID_LOCK_RANGE;
+			locks_free_lock(flock);
 			goto out;
 		}
 
@@ -6854,6 +6855,7 @@ int smb2_lock(struct ksmbd_work *work)
 				    "the end offset(%llx) is smaller than the start offset(%llx)\n",
 				    flock->fl_end, flock->fl_start);
 			rsp->hdr.Status = STATUS_INVALID_LOCK_RANGE;
+			locks_free_lock(flock);
 			goto out;
 		}
 
@@ -6865,6 +6867,7 @@ int smb2_lock(struct ksmbd_work *work)
 				    flock->fl_type != F_UNLCK) {
 					pr_err("conflict two locks in one request\n");
 					err = -EINVAL;
+					locks_free_lock(flock);
 					goto out;
 				}
 			}
@@ -6873,6 +6876,7 @@ int smb2_lock(struct ksmbd_work *work)
 		smb_lock = smb2_lock_init(flock, cmd, flags, &lock_list);
 		if (!smb_lock) {
 			err = -EINVAL;
+			locks_free_lock(flock);
 			goto out;
 		}
 	}
-- 
2.35.1


  parent reply	other threads:[~2022-12-24  1:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-24  1:30 [PATCH AUTOSEL 6.0 01/18] kset: fix memory leak when kset_register() returns error Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 02/18] USB: core: Change configuration warnings to notices Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 03/18] usb: core: stop USB enumeration if too many retries Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 04/18] usb: gadget: aspeed: fix buffer overflow Sasha Levin
2022-12-24  1:30   ` Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 05/18] usb: gadget: u_ether: Do not make UDC parent of the net device Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 06/18] usb: gadget: f_ecm: Always set current gadget in ecm_bind() Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 07/18] chardev: Fix potential memory leak when cdev_add() failed Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 08/18] usb/usbip: Fix v_recv_cmd_submit() to use PIPE_BULK define Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 09/18] char: xillybus: Prevent use-after-free due to race condition Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 10/18] habanalabs: zero ts registration buff when allocated Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 11/18] char: xillybus: Fix trivial bug with mutex Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 12/18] iio: filter: admv8818: close potential out-of-bounds read in __admv8818_read_[h|l]pf_freq() Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 13/18] xhci: disable U3 suspended ports in S4 hibernate poweroff_late stage Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 14/18] ACPICA: Fix operand resolution Sasha Levin
2022-12-24  1:30 ` Sasha Levin [this message]
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 16/18] writeback: Add asserts for adding freed inode to lists Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 17/18] exfat: fix overflow in sector and cluster conversion Sasha Levin
2022-12-24  1:30 ` [PATCH AUTOSEL 6.0 18/18] fbdev: smscufx: fix error handling code in ufx_usb_probe Sasha Levin
2022-12-24  1:30   ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221224013034.392810-15-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmakassikis@freebox.fr \
    --cc=sfrench@samba.org \
    --cc=stable@vger.kernel.org \
    --cc=stfrench@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.