mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
To: Werner Kasselman <werner@verivus.ai>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Steve French <smfrench@gmail.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	Tom Talpey <tom@talpey.com>,
	"linux-cifs@vger.kernel.org" <linux-cifs@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH] ksmbd: fix memory leaks and NULL deref in smb2_lock()
Date: Tue, 17 Mar 2026 17:01:31 +0800	[thread overview]
Message-ID: <308acd9f-58d9-4519-aaa6-be96f140177d@chenxiaosong.com> (raw)
In-Reply-To: <20260317080835.1947664-1-werner@verivus.com>

Hi Werner,

It might be better to move `locks_free_lock()` and `kfree()` to before 
`if (!rc)` statement.

```
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -7579,14 +7579,15 @@ int smb2_lock(struct ksmbd_work *work)
                 rc = vfs_lock_file(filp, smb_lock->cmd, flock, NULL);
  skip:
                 if (smb_lock->flags & SMB2_LOCKFLAG_UNLOCK) {
+                       locks_free_lock(flock);
+                       kfree(smb_lock);
                         if (!rc) {
                                 ksmbd_debug(SMB, "File unlocked\n");
                         } else if (rc == -ENOENT) {
                                 rsp->hdr.Status = STATUS_NOT_LOCKED;
+                               err = rc;
                                 goto out;
                         }
-                       locks_free_lock(flock);
-                       kfree(smb_lock);
                 } else {
                         if (rc == FILE_LOCK_DEFERRED) {
                                 void **argv;
```

Thanks,
ChenXiaoSong <chenxiaosong@kylinos.cn>

On 3/17/26 16:08, Werner Kasselman wrote:
> --- a/fs/smb/server/smb2pdu.c
> +++ b/fs/smb/server/smb2pdu.c
> @@ -7583,6 +7583,9 @@ int smb2_lock(struct ksmbd_work *work)
>   				ksmbd_debug(SMB, "File unlocked\n");
>   			} else if (rc == -ENOENT) {
>   				rsp->hdr.Status = STATUS_NOT_LOCKED;
> +				locks_free_lock(flock);
> +				kfree(smb_lock);
> +				err = -ENOENT;
>   				goto out;
>   			}
>   			locks_free_lock(flock);


  reply	other threads:[~2026-03-17  9:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17  8:08 Werner Kasselman
2026-03-17  9:01 ` ChenXiaoSong [this message]
2026-03-17  9:29 ` ChenXiaoSong
2026-03-17  9:49   ` Werner Kasselman

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=308acd9f-58d9-4519-aaa6-be96f140177d@chenxiaosong.com \
    --to=chenxiaosong@chenxiaosong.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=smfrench@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    --cc=werner@verivus.ai \
    /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

all inboxes | Powered by JetHome®