Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Tomas Henzl <thenzl@redhat.com>
To: linux-scsi@vger.kernel.org
Cc: mikoxyzzz@gmail.com
Subject: [PATCH v2 4/4] ses: fix slab-out-of-bounds reported by KASAN in ses_intf_remove
Date: Thu,  2 Feb 2023 17:24:51 +0100	[thread overview]
Message-ID: <20230202162451.15346-5-thenzl@redhat.com> (raw)
In-Reply-To: <20230202162451.15346-1-thenzl@redhat.com>

A fix for:
BUG: KASAN: slab-out-of-bounds in ses_intf_remove+0x23f/0x270 [ses]
Read of size 8 at addr ffff88a10d32e5d8 by task rmmod/12013
When edev->components is zero, accessing edev->component[0]
members is wrong.

Signed-off-by: Tomas Henzl <thenzl@redhat.com>
---
 drivers/scsi/ses.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index dbfe12f63c98..7a9eb54e8808 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -850,7 +850,8 @@ static void ses_intf_remove_enclosure(struct scsi_device *sdev)
 	kfree(ses_dev->page2);
 	kfree(ses_dev);
 
-	kfree(edev->component[0].scratch);
+	if (edev->components)
+		kfree(edev->component[0].scratch);
 
 	put_device(&edev->edev);
 	enclosure_unregister(edev);
-- 
2.38.1


  parent reply	other threads:[~2023-02-02 16:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 16:24 [PATCH v2 0/4] ses: prevent from out of bounds accesses Tomas Henzl
2023-02-02 16:24 ` [PATCH v2 1/4] ses: fix slab-out-of-bounds reported by KASAN in ses_enclosure_data_process Tomas Henzl
2023-02-02 16:24 ` [PATCH v2 2/4] ses: fix possible addl_desc_ptr out-of-bounds accesses " Tomas Henzl
2023-02-02 16:24 ` [PATCH v2 3/4] ses: fix possible desc_ptr " Tomas Henzl
2023-02-02 16:24 ` Tomas Henzl [this message]
2023-02-21 22:59 ` [PATCH v2 0/4] ses: prevent from out of bounds accesses Martin K. Petersen
2023-02-22 15:24   ` Tomas Henzl

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=20230202162451.15346-5-thenzl@redhat.com \
    --to=thenzl@redhat.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mikoxyzzz@gmail.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