All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ksmbd: fix slab-out-of-bounds read in smb2_handle_negotiate
@ 2023-05-17  9:59 HexRabbit
  2023-05-17 10:17 ` Namjae Jeon
  2023-05-17 11:05 ` Sergey Senozhatsky
  0 siblings, 2 replies; 7+ messages in thread
From: HexRabbit @ 2023-05-17  9:59 UTC (permalink / raw)
  To: linkinjeon; +Cc: sfrench, senozhatsky, tom, linux-cifs, HexRabbit

Check request_buf length first to avoid out-of-bounds read by
req->DialectCount.

[ 3350.990282] BUG: KASAN: slab-out-of-bounds in smb2_handle_negotiate+0x35d7/0x3e60
[ 3350.990282] Read of size 2 at addr ffff88810ad61346 by task kworker/5:0/276
[ 3351.000406] Workqueue: ksmbd-io handle_ksmbd_work
[ 3351.003499] Call Trace:
[ 3351.006473]  <TASK>
[ 3351.006473]  dump_stack_lvl+0x8d/0xe0
[ 3351.006473]  print_report+0xcc/0x620
[ 3351.006473]  kasan_report+0x92/0xc0
[ 3351.006473]  smb2_handle_negotiate+0x35d7/0x3e60
[ 3351.014760]  ksmbd_smb_negotiate_common+0x7a7/0xf00
[ 3351.014760]  handle_ksmbd_work+0x3f7/0x12d0
[ 3351.014760]  process_one_work+0xa85/0x1780

Signed-off-by: HexRabbit <h3xrabbit@gmail.com>
---
 fs/ksmbd/smb2pdu.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index cb93fd231..972176bff 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -1057,16 +1057,16 @@ int smb2_handle_negotiate(struct ksmbd_work *work)
 		return rc;
 	}
 
-	if (req->DialectCount == 0) {
-		pr_err("malformed packet\n");
+	smb2_buf_len = get_rfc1002_len(work->request_buf);
+	smb2_neg_size = offsetof(struct smb2_negotiate_req, Dialects);
+	if (smb2_neg_size > smb2_buf_len) {
 		rsp->hdr.Status = STATUS_INVALID_PARAMETER;
 		rc = -EINVAL;
 		goto err_out;
 	}
 
-	smb2_buf_len = get_rfc1002_len(work->request_buf);
-	smb2_neg_size = offsetof(struct smb2_negotiate_req, Dialects);
-	if (smb2_neg_size > smb2_buf_len) {
+	if (req->DialectCount == 0) {
+		pr_err("malformed packet\n");
 		rsp->hdr.Status = STATUS_INVALID_PARAMETER;
 		rc = -EINVAL;
 		goto err_out;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-05-18  8:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-17  9:59 [PATCH] ksmbd: fix slab-out-of-bounds read in smb2_handle_negotiate HexRabbit
2023-05-17 10:17 ` Namjae Jeon
2023-05-17 11:02   ` Sergey Senozhatsky
2023-05-17 11:05 ` Sergey Senozhatsky
2023-05-17 11:13   ` Sergey Senozhatsky
     [not found]     ` <CAF3ZFef4gmEVZR5riwdB1bkB4CccziGw3g18cyz7Sim4xw+ZDw@mail.gmail.com>
2023-05-18  0:33       ` Sergey Senozhatsky
2023-05-18  8:43         ` Hex Rabbit

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.