From: chenxiaosong@chenxiaosong.com
To: linkinjeon@kernel.org, sfrench@samba.org,
senozhatsky@chromium.org, tom@talpey.com,
linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org,
pc@manguebit.com, ronniesahlberg@gmail.com,
sprasad@microsoft.com, bharathsm@microsoft.com
Cc: chenxiaosong@kylinos.cn, liuzhengyuan@kylinos.cn,
huhai@kylinos.cn, liuyun01@kylinos.cn,
ChenXiaoSong <chenxiaosong@chenxiaosong.com>
Subject: [PATCH 2/8] smb/server: fix potential null-ptr-deref of lease_ctx_info in smb2_open()
Date: Tue, 20 Aug 2024 14:33:13 +0000 [thread overview]
Message-ID: <20240820143319.274033-3-chenxiaosong@chenxiaosong.com> (raw)
In-Reply-To: <20240820143319.274033-1-chenxiaosong@chenxiaosong.com>
From: ChenXiaoSong <chenxiaosong@kylinos.cn>
null-ptr-deref will occur when (req_op_level == SMB2_OPLOCK_LEVEL_LEASE)
and parse_lease_state() return NULL.
Fix this by returning error pointer on parse_lease_state() and checking
error.
Signed-off-by: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
---
fs/smb/server/oplock.c | 11 +++++++----
fs/smb/server/smb2pdu.c | 17 ++++++++++++-----
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/fs/smb/server/oplock.c b/fs/smb/server/oplock.c
index a8f52c4ebbda..e8591686a037 100644
--- a/fs/smb/server/oplock.c
+++ b/fs/smb/server/oplock.c
@@ -1510,7 +1510,8 @@ void create_lease_buf(u8 *rbuf, struct lease *lease)
* parse_lease_state() - parse lease context containted in file open request
* @open_req: buffer containing smb2 file open(create) request
*
- * Return: oplock state, -ENOENT if create lease context not found
+ * Return: allocated lease context object on success, otherwise error pointer.
+ * -ENOENT pointer if create lease context not found.
*/
struct lease_ctx_info *parse_lease_state(void *open_req)
{
@@ -1519,12 +1520,14 @@ struct lease_ctx_info *parse_lease_state(void *open_req)
struct lease_ctx_info *lreq;
cc = smb2_find_context_vals(req, SMB2_CREATE_REQUEST_LEASE, 4);
- if (IS_ERR_OR_NULL(cc))
- return NULL;
+ if (!cc)
+ return ERR_PTR(-ENOENT);
+ if (IS_ERR(cc))
+ return ERR_CAST(cc);
lreq = kzalloc(sizeof(struct lease_ctx_info), GFP_KERNEL);
if (!lreq)
- return NULL;
+ return ERR_PTR(-ENOMEM);
if (sizeof(struct lease_context_v2) == le32_to_cpu(cc->DataLength)) {
struct create_lease_v2 *lc = (struct create_lease_v2 *)cc;
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index d8a827e0dced..119c1ba5f255 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -2767,8 +2767,9 @@ static int parse_durable_handle_context(struct ksmbd_work *work,
}
}
- if (((lc && (lc->req_state & SMB2_LEASE_HANDLE_CACHING_LE)) ||
- req_op_level == SMB2_OPLOCK_LEVEL_BATCH)) {
+ if ((!IS_ERR_OR_NULL(lc) > 0 &&
+ (lc->req_state & SMB2_LEASE_HANDLE_CACHING_LE)) ||
+ req_op_level == SMB2_OPLOCK_LEVEL_BATCH) {
dh_info->CreateGuid =
durable_v2_blob->CreateGuid;
dh_info->persistent =
@@ -2788,8 +2789,9 @@ static int parse_durable_handle_context(struct ksmbd_work *work,
goto out;
}
- if (((lc && (lc->req_state & SMB2_LEASE_HANDLE_CACHING_LE)) ||
- req_op_level == SMB2_OPLOCK_LEVEL_BATCH)) {
+ if ((!IS_ERR_OR_NULL(lc) &&
+ (lc->req_state & SMB2_LEASE_HANDLE_CACHING_LE)) ||
+ req_op_level == SMB2_OPLOCK_LEVEL_BATCH) {
ksmbd_debug(SMB, "Request for durable open\n");
dh_info->type = dh_idx;
}
@@ -2935,8 +2937,13 @@ int smb2_open(struct ksmbd_work *work)
ksmbd_put_durable_fd(fp);
goto reconnected_fp;
}
- } else if (req_op_level == SMB2_OPLOCK_LEVEL_LEASE)
+ } else if (req_op_level == SMB2_OPLOCK_LEVEL_LEASE) {
lc = parse_lease_state(req);
+ if (IS_ERR(lc)) {
+ rc = PTR_ERR(lc);
+ goto err_out2;
+ }
+ }
if (le32_to_cpu(req->ImpersonationLevel) > le32_to_cpu(IL_DELEGATE)) {
pr_err("Invalid impersonationlevel : 0x%x\n",
--
2.34.1
next prev parent reply other threads:[~2024-08-20 14:37 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 14:33 [PATCH 0/8] smb: fix some bugs, move duplicate definitions to common header file, and some small cleanups chenxiaosong
2024-08-20 14:33 ` [PATCH 1/8] smb/server: fix return value of smb2_open() chenxiaosong
2024-08-22 0:49 ` Namjae Jeon
2024-08-20 14:33 ` chenxiaosong [this message]
2024-08-22 0:41 ` [PATCH 2/8] smb/server: fix potential null-ptr-deref of lease_ctx_info in smb2_open() Namjae Jeon
2024-08-22 0:59 ` ChenXiaoSong
2024-08-20 14:33 ` [PATCH 3/8] smb/server: remove useless variable assignment " chenxiaosong
2024-08-22 0:47 ` Namjae Jeon
2024-08-20 14:33 ` [PATCH 4/8] smb/client: fix typo: GlobalMid_Sem -> GlobalMid_Lock chenxiaosong
2024-08-22 0:21 ` Namjae Jeon
2024-08-20 14:33 ` [PATCH 5/8] smb/server: update misguided comment of smb2_allocate_rsp_buf() chenxiaosong
2024-08-22 0:48 ` Namjae Jeon
2024-08-20 14:33 ` [PATCH 6/8] smb: move some duplicate definitions to common/smbacl.h chenxiaosong
2024-08-21 19:51 ` Steve French
2024-08-21 23:48 ` Namjae Jeon
2024-08-22 0:16 ` chenxiaosong
2024-08-20 14:33 ` [PATCH 7/8] smb/client: fix typo: STATUS_MCA_OCCURED -> STATUS_MCA_OCCURRED chenxiaosong
2024-08-21 17:53 ` Steve French
2024-08-21 23:57 ` Namjae Jeon
2024-08-22 0:10 ` chenxiaosong
2024-08-22 0:11 ` Steve French
2024-08-20 14:33 ` [PATCH 8/8] smb: move SMB2 Status code to common header file chenxiaosong
2024-08-21 19:51 ` Steve French
2024-08-21 23:40 ` Namjae Jeon
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=20240820143319.274033-3-chenxiaosong@chenxiaosong.com \
--to=chenxiaosong@chenxiaosong.com \
--cc=bharathsm@microsoft.com \
--cc=chenxiaosong@kylinos.cn \
--cc=huhai@kylinos.cn \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuyun01@kylinos.cn \
--cc=liuzhengyuan@kylinos.cn \
--cc=pc@manguebit.com \
--cc=ronniesahlberg@gmail.com \
--cc=senozhatsky@chromium.org \
--cc=sfrench@samba.org \
--cc=sprasad@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