From: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
To: linkinjeon@kernel.org, tom@talpey.com, senozhatsky@chromium.org,
chenxiaosong@chenxiaosong.com
Cc: linux-cifs@vger.kernel.org, ChenXiaoSong <chenxiaosong@kylinos.cn>
Subject: [PATCH 02/12] smb/server: add more validation for change notify requests
Date: Sat, 26 Sep 2026 09:05:08 +0000 [thread overview]
Message-ID: <20260926090518.78547-3-chenxiaosong@chenxiaosong.com> (raw)
In-Reply-To: <20260926090518.78547-1-chenxiaosong@chenxiaosong.com>
From: ChenXiaoSong <chenxiaosong@kylinos.cn>
Add validation for the file type, directory list access and output
buffer length before setting up a change notify watch.
Suggested-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/server/notify.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/fs/smb/server/notify.c b/fs/smb/server/notify.c
index 7e324af36b47..18cf0005a037 100644
--- a/fs/smb/server/notify.c
+++ b/fs/smb/server/notify.c
@@ -48,6 +48,7 @@ ksmbd_notify_validate_req(struct ksmbd_work *work,
struct smb2_change_notify_rsp *rsp)
{
struct ksmbd_file *fp;
+ int err;
if (work->next_smb2_rcv_hdr_off && req->hdr.NextCommand) {
pr_err("Notify request is not the last compound command\n");
@@ -65,7 +66,37 @@ ksmbd_notify_validate_req(struct ksmbd_work *work,
return ERR_PTR(-ENOENT);
}
+ if (le32_to_cpu(req->OutputBufferLength) >
+ work->conn->vals->max_trans_size) {
+ pr_err("Notify output buffer length %u exceeds maximum %u\n",
+ le32_to_cpu(req->OutputBufferLength),
+ work->conn->vals->max_trans_size);
+ rsp->hdr.Status = STATUS_INVALID_PARAMETER;
+ err = -EINVAL;
+ goto err_put_fp;
+ }
+
+ if (!S_ISDIR(file_inode(fp->filp)->i_mode)) {
+ pr_err("Notify file id is not a directory, fid %llu:%llu\n",
+ fp->persistent_id, fp->volatile_id);
+ rsp->hdr.Status = STATUS_INVALID_PARAMETER;
+ err = -EINVAL;
+ goto err_put_fp;
+ }
+
+ if (!(fp->daccess & FILE_LIST_DIRECTORY_LE)) {
+ pr_err("No permission to monitor directory, fid %llu:%llu\n",
+ fp->persistent_id, fp->volatile_id);
+ rsp->hdr.Status = STATUS_ACCESS_DENIED;
+ err = -EACCES;
+ goto err_put_fp;
+ }
+
return fp;
+
+err_put_fp:
+ ksmbd_fd_put(work, fp);
+ return ERR_PTR(err);
}
static int ksmbd_notify_wait(struct ksmbd_work *work,
--
2.55.0
next prev parent reply other threads:[~2026-09-26 9:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 9:05 [PATCH 00/12] smb/server: change notify support ChenXiaoSong
2026-09-26 9:05 ` [PATCH 01/12] smb/server: move change notify handling into notify.c ChenXiaoSong
2026-09-26 9:05 ` ChenXiaoSong [this message]
2026-09-26 9:05 ` [PATCH 03/12] smb/server: add debug type for change notify ChenXiaoSong
2026-09-26 9:05 ` [PATCH 04/12] smb/server: support non-recursive directory change watches ChenXiaoSong
2026-09-27 10:51 ` Namjae Jeon
2026-09-28 0:38 ` ChenXiaoSong
2026-09-26 9:05 ` [PATCH 05/12] smb/server: support recursive " ChenXiaoSong
2026-09-26 9:05 ` [PATCH 06/12] smb/server: keep notify watches on file handles ChenXiaoSong
2026-09-26 9:05 ` [PATCH 07/12] smb/server: save simple notify events ChenXiaoSong
2026-09-27 10:31 ` Namjae Jeon
2026-09-28 1:27 ` ChenXiaoSong
2026-09-26 9:05 ` [PATCH 08/12] smb/server: save old names for rename " ChenXiaoSong
2026-09-26 9:05 ` [PATCH 09/12] smb/server: match " ChenXiaoSong
2026-09-26 9:05 ` [PATCH 10/12] smb/server: encode " ChenXiaoSong
2026-09-26 9:05 ` [PATCH 11/12] smb/server: send notify events to the client ChenXiaoSong
2026-09-26 9:05 ` [PATCH 12/12] smb/server: break directory leases before sending notify events ChenXiaoSong
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=20260926090518.78547-3-chenxiaosong@chenxiaosong.com \
--to=chenxiaosong@chenxiaosong.com \
--cc=chenxiaosong@kylinos.cn \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=senozhatsky@chromium.org \
--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