Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Jaskaran Singh <jsingh@cloudlinux.com>
To: stable@vger.kernel.org
Cc: gregkh@linuxfoundation.org, sashal@kernel.org,
	linkinjeon@kernel.org, sfrench@samba.org, stfrench@microsoft.com,
	senozhatsky@chromium.org, tom@talpey.com, mmakassikis@freebox.fr,
	linux-cifs@vger.kernel.org, jsingh@cloudlinux.com
Subject: [PATCH 6.1.y] ksmbd: fix NULL pointer dereference in opinfo_put()
Date: Sat, 14 Nov 2026 11:49:43 +0000	[thread overview]
Message-ID: <20261114114943.5122-1-jsingh@cloudlinux.com> (raw)

Commit e1b21e606661 ("smb: server: fix use-after-free in smb2_open()")
is the 6.1.y backport of upstream commit 1e689a561738 ("smb: server: fix
use-after-free in smb2_open()"). It calls opinfo_put(opinfo)
unconditionally at the end of smb2_open(). Upstream
opinfo_put() returns early on a NULL opinfo since commit ee426bfb9d09
("ksmbd: add refcnt to ksmbd_conn struct"), which is not in 6.1.y, so
here it dereferences NULL whenever the open got no oplock info.

smb_grant_oplock() allocates none for a directory opened without a v2
lease, which is how clients open the share root, so the first
"smbclient -c ls" or cifs mount against ksmbd oopses:

  BUG: kernel NULL pointer dereference, address: 000000000000003c
  RIP: 0010:opinfo_put+0x5/0x30 [ksmbd]
  Call Trace:
   smb2_open+0xbf9/0x1f80 [ksmbd]
   handle_ksmbd_work+0x164/0x430 [ksmbd]
   process_one_work+0x1c7/0x380
   worker_thread+0x4d/0x380

Return early from opinfo_put() on a NULL opinfo, as upstream does.

The problem does not exist upstream; this fix is for 6.1.y only.

Fixes: e1b21e606661 ("smb: server: fix use-after-free in smb2_open()")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jaskaran Singh <jsingh@cloudlinux.com>
---
 fs/smb/server/oplock.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/smb/server/oplock.c b/fs/smb/server/oplock.c
index 932e31a20216..f4ed5bbbeb6e 100644
--- a/fs/smb/server/oplock.c
+++ b/fs/smb/server/oplock.c
@@ -196,6 +196,9 @@ static void opinfo_conn_put(struct oplock_info *opinfo)
 
 void opinfo_put(struct oplock_info *opinfo)
 {
+	if (!opinfo)
+		return;
+
 	if (!atomic_dec_and_test(&opinfo->refcount))
 		return;
 
-- 
2.43.7


                 reply	other threads:[~2026-11-14 11:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261114114943.5122-1-jsingh@cloudlinux.com \
    --to=jsingh@cloudlinux.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=mmakassikis@freebox.fr \
    --cc=sashal@kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=sfrench@samba.org \
    --cc=stable@vger.kernel.org \
    --cc=stfrench@microsoft.com \
    --cc=tom@talpey.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox