Skip to contentSkip to conversation

mptsas: Remove unused MPTSASState 'pending' field (CVE-2021-3392)

PATCH In review Philippe Mathieu-Daudé 2 participants 4 messages Apr 18, 2021 – Apr 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mptsas: Remove unused MPTSASState 'pending' field (CVE-2021-3392)

From: Michael Tokarev <[email protected]>

While processing SCSI i/o requests in mptsas_process_scsi_io_request(), the Megaraid emulator appends new MPTSASRequest object 'req' to the 's->pending' queue. In case of an error, this same object gets dequeued in mptsas_free_request() only if SCSIRequest object 'req->sreq' is initialised. This may lead to a use-after-free issue.

Since s->pending is actually not used, simply remove it from MPTSASState.

Message-Id: <[email protected]>

Fixes e351b826112 ("hw: Add support for LSI SAS1068 (mptsas) device")
[PMD: Reworded description, added more tags]

---
Supersedes: <[email protected]>

MJT patch:
https://www.mail-archive.com/[email protected]/msg799236.html

Since rc4 is soon, I'm directly respining his patch with my comments addressed.

This is not a new regression (present since QEMU v2.6.0) but is a CVE...

PJP first patch:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg02660.html

---
 hw/scsi/mptsas.h | 1 -
 hw/scsi/mptsas.c | 4 ----
 2 files changed, 5 deletions(-)
hw/scsi/mptsas.h +0 -1
index b85ac1a5fcc..c046497db71 100644
@@ -79,7 +79,6 @@ struct MPTSASState {
     uint16_t reply_frame_size;
 
     SCSIBus bus;
-    QTAILQ_HEAD(, MPTSASRequest) pending;
 };
 
 void mptsas_fix_scsi_io_endianness(MPIMsgSCSIIORequest *req);
hw/scsi/mptsas.c +0 -4
index 7416e787061..5abbc742aaf 100644
@@ -257,7 +257,6 @@ static void mptsas_free_request(MPTSASRequest *req)
         req->sreq->hba_private = NULL;
         scsi_req_unref(req->sreq);
         req->sreq = NULL;
-        QTAILQ_REMOVE(&s->pending, req, next);
     }
     qemu_sglist_destroy(&req->qsg);
     g_free(req);
@@ -303,7 +302,6 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
     }
 
     req = g_new0(MPTSASRequest, 1);
-    QTAILQ_INSERT_TAIL(&s->pending, req, next);
     req->scsi_io = *scsi_io;
     req->dev = s;
 
@@ -1319,8 +1317,6 @@ static void mptsas_scsi_realize(PCIDevice *dev, Error **errp)
 
     s->request_bh = qemu_bh_new(mptsas_fetch_requests, s);
 
-    QTAILQ_INIT(&s->pending);
-
     scsi_bus_new(&s->bus, sizeof(s->bus), &dev->qdev, &mptsas_scsi_info, NULL);
 }
 
Signature · 1 line
2.26.3
#1 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé

From: Michael Tokarev <[email protected]>

While processing SCSI i/o requests in mptsas_process_scsi_io_request(), the Megaraid emulator appends new MPTSASRequest object 'req' to the 's->pending' queue. In case of an error, this same object gets dequeued in mptsas_free_request() only if SCSIRequest object 'req->sreq' is initialised. This may lead to a use-after-free issue.

Quoted 7 lines

Since s->pending is actually not used, simply remove it from MPTSASState.

Message-Id: <[email protected]>

Quoted 66 lines
Fixes e351b826112 ("hw: Add support for LSI SAS1068 (mptsas) device")
[PMD: Reworded description, added more tags]

---
Supersedes: <[email protected]>

MJT patch:
https://www.mail-archive.com/[email protected]/msg799236.html

Since rc4 is soon, I'm directly respining his patch with my comments addressed.

This is not a new regression (present since QEMU v2.6.0) but is a CVE...

PJP first patch:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg02660.html

---
 hw/scsi/mptsas.h | 1 -
 hw/scsi/mptsas.c | 4 ----
 2 files changed, 5 deletions(-)
hw/scsi/mptsas.h +0 -1
index b85ac1a5fcc..c046497db71 100644
@@ -79,7 +79,6 @@ struct MPTSASState {
     uint16_t reply_frame_size;
 
     SCSIBus bus;
-    QTAILQ_HEAD(, MPTSASRequest) pending;
 };
 
 void mptsas_fix_scsi_io_endianness(MPIMsgSCSIIORequest *req);
hw/scsi/mptsas.c +0 -4
index 7416e787061..5abbc742aaf 100644
@@ -257,7 +257,6 @@ static void mptsas_free_request(MPTSASRequest *req)
         req->sreq->hba_private = NULL;
         scsi_req_unref(req->sreq);
         req->sreq = NULL;
-        QTAILQ_REMOVE(&s->pending, req, next);
     }
     qemu_sglist_destroy(&req->qsg);
     g_free(req);
@@ -303,7 +302,6 @@ static int mptsas_process_scsi_io_request(MPTSASState *s,
     }
 
     req = g_new0(MPTSASRequest, 1);
-    QTAILQ_INSERT_TAIL(&s->pending, req, next);
     req->scsi_io = *scsi_io;
     req->dev = s;
 
@@ -1319,8 +1317,6 @@ static void mptsas_scsi_realize(PCIDevice *dev, Error **errp)
 
     s->request_bh = qemu_bh_new(mptsas_fetch_requests, s);
 
-    QTAILQ_INIT(&s->pending);
-
     scsi_bus_new(&s->bus, sizeof(s->bus), &dev->qdev, &mptsas_scsi_info, NULL);
 }
 
#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 33 lines · Philippe Mathieu-Daudé

From: Michael Tokarev <[email protected]>

While processing SCSI i/o requests in mptsas_process_scsi_io_request(), the Megaraid emulator appends new MPTSASRequest object 'req' to the 's->pending' queue. In case of an error, this same object gets dequeued in mptsas_free_request() only if SCSIRequest object 'req->sreq' is initialised. This may lead to a use-after-free issue.

Since s->pending is actually not used, simply remove it from MPTSASState.

Message-Id: <[email protected]>

Fixes e351b826112 ("hw: Add support for LSI SAS1068 (mptsas) device")
[PMD: Reworded description, added more tags]

---
Supersedes: <[email protected]>

MJT patch:
https://www.mail-archive.com/[email protected]/msg799236.html

Since rc4 is soon, I'm directly respining his patch with my comments addressed.

This is not a new regression (present since QEMU v2.6.0) but is a CVE...

Quoted 6 lines

PJP first patch:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg02660.html

---
 hw/scsi/mptsas.h | 1 -
 hw/scsi/mptsas.c | 4 ----
 2 files changed, 5 deletions(-)

This fails to compile:

../../hw/scsi/mptsas.c: In function ‘mptsas_free_request’:
../../hw/scsi/mptsas.c:254:18: error: unused variable ‘s’ [-Werror=unused-variable]

     MPTSASState *s = req->dev;
                  ^

cc1: all warnings being treated as errors

thanks
-- PMM

#3 lore raw
Quoted 41 lines · Peter Maydell
Quoted 33 lines · Philippe Mathieu-Daudé

From: Michael Tokarev <[email protected]>

While processing SCSI i/o requests in mptsas_process_scsi_io_request(), the Megaraid emulator appends new MPTSASRequest object 'req' to the 's->pending' queue. In case of an error, this same object gets dequeued in mptsas_free_request() only if SCSIRequest object 'req->sreq' is initialised. This may lead to a use-after-free issue.

Since s->pending is actually not used, simply remove it from MPTSASState.

Message-Id: <[email protected]>

Fixes e351b826112 ("hw: Add support for LSI SAS1068 (mptsas) device")
[PMD: Reworded description, added more tags]

---
Supersedes: <[email protected]>

MJT patch:
https://www.mail-archive.com/[email protected]/msg799236.html

Since rc4 is soon, I'm directly respining his patch with my comments addressed.

This is not a new regression (present since QEMU v2.6.0) but is a CVE...

Quoted 6 lines

PJP first patch:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg02660.html

---
 hw/scsi/mptsas.h | 1 -
 hw/scsi/mptsas.c | 4 ----
 2 files changed, 5 deletions(-)
Quoted 8 lines

This fails to compile:

../../hw/scsi/mptsas.c: In function ‘mptsas_free_request’:
../../hw/scsi/mptsas.c:254:18: error: unused variable ‘s’ [-Werror=unused-variable]

     MPTSASState *s = req->dev;
                  ^

cc1: all warnings being treated as errors

What a shame... Sorry, v3 coming.