* [PULL 0/2] hw/nvme fixes @ 2023-08-07 11:54 Klaus Jensen 2023-08-07 11:54 ` [PULL 1/2] hw/nvme: fix oob memory read in fdp events log Klaus Jensen ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Klaus Jensen @ 2023-08-07 11:54 UTC (permalink / raw) To: Peter Maydell, qemu-devel Cc: Philippe Mathieu-Daudé, Keith Busch, Hanna Reitz, qemu-block, Klaus Jensen, Stefan Hajnoczi, Fam Zheng, Kevin Wolf, Klaus Jensen From: Klaus Jensen <k.jensen@samsung.com> Hi, The following changes since commit 9400601a689a128c25fa9c21e932562e0eeb7a26: Merge tag 'pull-tcg-20230806-3' of https://gitlab.com/rth7680/qemu into staging (2023-08-06 16:47:48 -0700) are available in the Git repository at: https://gitlab.com/birkelund/qemu.git tags/nvme-next-pull-request for you to fetch changes up to 6a33f2e920ec0b489a77200888e3692664077f2d: hw/nvme: fix compliance issue wrt. iosqes/iocqes (2023-08-07 12:27:24 +0200) ---------------------------------------------------------------- hw/nvme fixes - two fixes for hw/nvme -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEUigzqnXi3OaiR2bATeGvMW1PDekFAmTQ2y4ACgkQTeGvMW1P DenpWQf/WFgEljzgTcgxlfZhCyzWGwVNgKqRxlTuF6ELqm8BajCuCeA5ias6AXOr x/gZ0VqrL91L5tRIH5Q0sdC+HBFC1yMs66jopdzc1oL1eYu1HTrLIqMDtkXp/K/P PyGah2t4qEMtacSkad+hmB68ViUkkmhkxrWYIeufUQTfLNF5pBqNvB1kQON3jmXE a1jI/PabYxi8Km0rfFJD6SUGmL9+m7MY/SyZAy+4EZZ1OEnp5jb3o9lbdwbhIU5e dRX4NW4BEDiOJeIcNVDiQkXv2/Lna1B51RVMvM4owpk0eRvRXMSqs2DQ5/jp/nGb 8uChUJ0QW68I4e9ptTfxmBsr4pSktg== =0nwp -----END PGP SIGNATURE----- ---------------------------------------------------------------- Klaus Jensen (2): hw/nvme: fix oob memory read in fdp events log hw/nvme: fix compliance issue wrt. iosqes/iocqes hw/nvme/ctrl.c | 51 +++++++++++++++----------------------------- hw/nvme/nvme.h | 9 ++++++-- hw/nvme/trace-events | 1 + 3 files changed, 25 insertions(+), 36 deletions(-) -- 2.41.0 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PULL 1/2] hw/nvme: fix oob memory read in fdp events log 2023-08-07 11:54 [PULL 0/2] hw/nvme fixes Klaus Jensen @ 2023-08-07 11:54 ` Klaus Jensen 2023-08-07 11:54 ` [PULL 2/2] hw/nvme: fix compliance issue wrt. iosqes/iocqes Klaus Jensen 2023-08-07 20:36 ` [PULL 0/2] hw/nvme fixes Richard Henderson 2 siblings, 0 replies; 8+ messages in thread From: Klaus Jensen @ 2023-08-07 11:54 UTC (permalink / raw) To: Peter Maydell, qemu-devel Cc: Philippe Mathieu-Daudé, Keith Busch, Hanna Reitz, qemu-block, Klaus Jensen, Stefan Hajnoczi, Fam Zheng, Kevin Wolf, Klaus Jensen From: Klaus Jensen <k.jensen@samsung.com> As reported by Trend Micro's Zero Day Initiative, an oob memory read vulnerability exists in nvme_fdp_events(). The host-provided offset is not verified. Fix this. This is only exploitable when Flexible Data Placement mode (fdp=on) is enabled. Fixes: CVE-2023-4135 Fixes: 73064edfb864 ("hw/nvme: flexible data placement emulation") Reported-by: Trend Micro's Zero Day Initiative Signed-off-by: Klaus Jensen <k.jensen@samsung.com> --- hw/nvme/ctrl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index f2e5a2fa737b..e9b5a55811b8 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -5120,6 +5120,11 @@ static uint16_t nvme_fdp_events(NvmeCtrl *n, uint32_t endgrpid, } log_size = sizeof(NvmeFdpEventsLog) + ebuf->nelems * sizeof(NvmeFdpEvent); + + if (off >= log_size) { + return NVME_INVALID_FIELD | NVME_DNR; + } + trans_len = MIN(log_size - off, buf_len); elog = g_malloc0(log_size); elog->num_events = cpu_to_le32(ebuf->nelems); -- 2.41.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PULL 2/2] hw/nvme: fix compliance issue wrt. iosqes/iocqes 2023-08-07 11:54 [PULL 0/2] hw/nvme fixes Klaus Jensen 2023-08-07 11:54 ` [PULL 1/2] hw/nvme: fix oob memory read in fdp events log Klaus Jensen @ 2023-08-07 11:54 ` Klaus Jensen 2023-08-07 20:36 ` [PULL 0/2] hw/nvme fixes Richard Henderson 2 siblings, 0 replies; 8+ messages in thread From: Klaus Jensen @ 2023-08-07 11:54 UTC (permalink / raw) To: Peter Maydell, qemu-devel Cc: Philippe Mathieu-Daudé, Keith Busch, Hanna Reitz, qemu-block, Klaus Jensen, Stefan Hajnoczi, Fam Zheng, Kevin Wolf, Klaus Jensen From: Klaus Jensen <k.jensen@samsung.com> As of prior to this patch, the controller checks the value of CC.IOCQES and CC.IOSQES prior to enabling the controller. As reported by Ben in GitLab issue #1691, this is not spec compliant. The controller should only check these values when queues are created. This patch moves these checks to nvme_create_cq(). We do not need to check it in nvme_create_sq() since that will error out if the completion queue is not already created. Also, since the controller exclusively supports SQEs of size 64 bytes and CQEs of size 16 bytes, hard code that. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1691 Signed-off-by: Klaus Jensen <k.jensen@samsung.com> --- hw/nvme/ctrl.c | 46 ++++++++++++-------------------------------- hw/nvme/nvme.h | 9 +++++++-- hw/nvme/trace-events | 1 + 3 files changed, 20 insertions(+), 36 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index e9b5a55811b8..d217ae91b506 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -1507,7 +1507,7 @@ static void nvme_post_cqes(void *opaque) req->cqe.status = cpu_to_le16((req->status << 1) | cq->phase); req->cqe.sq_id = cpu_to_le16(sq->sqid); req->cqe.sq_head = cpu_to_le16(sq->head); - addr = cq->dma_addr + cq->tail * n->cqe_size; + addr = cq->dma_addr + (cq->tail << NVME_CQES); ret = pci_dma_write(PCI_DEVICE(n), addr, (void *)&req->cqe, sizeof(req->cqe)); if (ret) { @@ -5300,10 +5300,18 @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeRequest *req) uint16_t qsize = le16_to_cpu(c->qsize); uint16_t qflags = le16_to_cpu(c->cq_flags); uint64_t prp1 = le64_to_cpu(c->prp1); + uint32_t cc = ldq_le_p(&n->bar.cc); + uint8_t iocqes = NVME_CC_IOCQES(cc); + uint8_t iosqes = NVME_CC_IOSQES(cc); trace_pci_nvme_create_cq(prp1, cqid, vector, qsize, qflags, NVME_CQ_FLAGS_IEN(qflags) != 0); + if (iosqes != NVME_SQES || iocqes != NVME_CQES) { + trace_pci_nvme_err_invalid_create_cq_entry_size(iosqes, iocqes); + return NVME_MAX_QSIZE_EXCEEDED | NVME_DNR; + } + if (unlikely(!cqid || cqid > n->conf_ioqpairs || n->cq[cqid] != NULL)) { trace_pci_nvme_err_invalid_create_cq_cqid(cqid); return NVME_INVALID_QID | NVME_DNR; @@ -7000,7 +7008,7 @@ static void nvme_process_sq(void *opaque) } while (!(nvme_sq_empty(sq) || QTAILQ_EMPTY(&sq->req_list))) { - addr = sq->dma_addr + sq->head * n->sqe_size; + addr = sq->dma_addr + (sq->head << NVME_SQES); if (nvme_addr_read(n, addr, (void *)&cmd, sizeof(cmd))) { trace_pci_nvme_err_addr_read(addr); trace_pci_nvme_err_cfs(); @@ -7225,34 +7233,6 @@ static int nvme_start_ctrl(NvmeCtrl *n) NVME_CAP_MPSMAX(cap)); return -1; } - if (unlikely(NVME_CC_IOCQES(cc) < - NVME_CTRL_CQES_MIN(n->id_ctrl.cqes))) { - trace_pci_nvme_err_startfail_cqent_too_small( - NVME_CC_IOCQES(cc), - NVME_CTRL_CQES_MIN(cap)); - return -1; - } - if (unlikely(NVME_CC_IOCQES(cc) > - NVME_CTRL_CQES_MAX(n->id_ctrl.cqes))) { - trace_pci_nvme_err_startfail_cqent_too_large( - NVME_CC_IOCQES(cc), - NVME_CTRL_CQES_MAX(cap)); - return -1; - } - if (unlikely(NVME_CC_IOSQES(cc) < - NVME_CTRL_SQES_MIN(n->id_ctrl.sqes))) { - trace_pci_nvme_err_startfail_sqent_too_small( - NVME_CC_IOSQES(cc), - NVME_CTRL_SQES_MIN(cap)); - return -1; - } - if (unlikely(NVME_CC_IOSQES(cc) > - NVME_CTRL_SQES_MAX(n->id_ctrl.sqes))) { - trace_pci_nvme_err_startfail_sqent_too_large( - NVME_CC_IOSQES(cc), - NVME_CTRL_SQES_MAX(cap)); - return -1; - } if (unlikely(!NVME_AQA_ASQS(aqa))) { trace_pci_nvme_err_startfail_asqent_sz_zero(); return -1; @@ -7265,8 +7245,6 @@ static int nvme_start_ctrl(NvmeCtrl *n) n->page_bits = page_bits; n->page_size = page_size; n->max_prp_ents = n->page_size / sizeof(uint64_t); - n->cqe_size = 1 << NVME_CC_IOCQES(cc); - n->sqe_size = 1 << NVME_CC_IOSQES(cc); nvme_init_cq(&n->admin_cq, n, acq, 0, 0, NVME_AQA_ACQS(aqa) + 1, 1); nvme_init_sq(&n->admin_sq, n, asq, 0, 0, NVME_AQA_ASQS(aqa) + 1); @@ -8235,8 +8213,8 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) id->wctemp = cpu_to_le16(NVME_TEMPERATURE_WARNING); id->cctemp = cpu_to_le16(NVME_TEMPERATURE_CRITICAL); - id->sqes = (0x6 << 4) | 0x6; - id->cqes = (0x4 << 4) | 0x4; + id->sqes = (NVME_SQES << 4) | NVME_SQES; + id->cqes = (NVME_CQES << 4) | NVME_CQES; id->nn = cpu_to_le32(NVME_MAX_NAMESPACES); id->oncs = cpu_to_le16(NVME_ONCS_WRITE_ZEROES | NVME_ONCS_TIMESTAMP | NVME_ONCS_FEATURES | NVME_ONCS_DSM | diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 209e8f5b4c08..5f2ae7b28b9c 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -30,6 +30,13 @@ #define NVME_FDP_MAX_EVENTS 63 #define NVME_FDP_MAXPIDS 128 +/* + * The controller only supports Submission and Completion Queue Entry Sizes of + * 64 and 16 bytes respectively. + */ +#define NVME_SQES 6 +#define NVME_CQES 4 + QEMU_BUILD_BUG_ON(NVME_MAX_NAMESPACES > NVME_NSID_BROADCAST - 1); typedef struct NvmeCtrl NvmeCtrl; @@ -530,8 +537,6 @@ typedef struct NvmeCtrl { uint32_t page_size; uint16_t page_bits; uint16_t max_prp_ents; - uint16_t cqe_size; - uint16_t sqe_size; uint32_t max_q_ents; uint8_t outstanding_aers; uint32_t irq_status; diff --git a/hw/nvme/trace-events b/hw/nvme/trace-events index 9afddf3b951c..3a67680c6ad1 100644 --- a/hw/nvme/trace-events +++ b/hw/nvme/trace-events @@ -168,6 +168,7 @@ pci_nvme_err_invalid_create_cq_size(uint16_t size) "failed creating completion q pci_nvme_err_invalid_create_cq_addr(uint64_t addr) "failed creating completion queue, addr=0x%"PRIx64"" pci_nvme_err_invalid_create_cq_vector(uint16_t vector) "failed creating completion queue, vector=%"PRIu16"" pci_nvme_err_invalid_create_cq_qflags(uint16_t qflags) "failed creating completion queue, qflags=%"PRIu16"" +pci_nvme_err_invalid_create_cq_entry_size(uint8_t iosqes, uint8_t iocqes) "iosqes %"PRIu8" iocqes %"PRIu8"" pci_nvme_err_invalid_identify_cns(uint16_t cns) "identify, invalid cns=0x%"PRIx16"" pci_nvme_err_invalid_getfeat(int dw10) "invalid get features, dw10=0x%"PRIx32"" pci_nvme_err_invalid_setfeat(uint32_t dw10) "invalid set features, dw10=0x%"PRIx32"" -- 2.41.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PULL 0/2] hw/nvme fixes 2023-08-07 11:54 [PULL 0/2] hw/nvme fixes Klaus Jensen 2023-08-07 11:54 ` [PULL 1/2] hw/nvme: fix oob memory read in fdp events log Klaus Jensen 2023-08-07 11:54 ` [PULL 2/2] hw/nvme: fix compliance issue wrt. iosqes/iocqes Klaus Jensen @ 2023-08-07 20:36 ` Richard Henderson 2 siblings, 0 replies; 8+ messages in thread From: Richard Henderson @ 2023-08-07 20:36 UTC (permalink / raw) To: Klaus Jensen, Peter Maydell, qemu-devel Cc: Philippe Mathieu-Daudé, Keith Busch, Hanna Reitz, qemu-block, Stefan Hajnoczi, Fam Zheng, Kevin Wolf, Klaus Jensen On 8/7/23 04:54, Klaus Jensen wrote: > From: Klaus Jensen<k.jensen@samsung.com> > > Hi, > > The following changes since commit 9400601a689a128c25fa9c21e932562e0eeb7a26: > > Merge tag 'pull-tcg-20230806-3' ofhttps://gitlab.com/rth7680/qemu into staging (2023-08-06 16:47:48 -0700) > > are available in the Git repository at: > > https://gitlab.com/birkelund/qemu.git tags/nvme-next-pull-request > > for you to fetch changes up to 6a33f2e920ec0b489a77200888e3692664077f2d: > > hw/nvme: fix compliance issue wrt. iosqes/iocqes (2023-08-07 12:27:24 +0200) > > ---------------------------------------------------------------- > hw/nvme fixes Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate. r~ ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PULL 0/2] hw/nvme fixes @ 2023-03-27 17:09 Klaus Jensen 2023-03-28 16:00 ` Peter Maydell 0 siblings, 1 reply; 8+ messages in thread From: Klaus Jensen @ 2023-03-27 17:09 UTC (permalink / raw) To: Peter Maydell, qemu-devel Cc: Kevin Wolf, Philippe Mathieu-Daudé, Fam Zheng, qemu-block, Hanna Reitz, Stefan Hajnoczi, Keith Busch, Klaus Jensen, Klaus Jensen From: Klaus Jensen <k.jensen@samsung.com> Hi Peter, The following changes since commit e3debd5e7d0ce031356024878a0a18b9d109354a: Merge tag 'pull-request-2023-03-24' of https://gitlab.com/thuth/qemu into staging (2023-03-24 16:08:46 +0000) are available in the Git repository at: https://gitlab.com/birkelund/qemu.git tags/nvme-next-pull-request for you to fetch changes up to ca2a091802872b265bc6007a2d36276d51d8e4b3: hw/nvme: fix missing DNR on compare failure (2023-03-27 19:05:23 +0200) ---------------------------------------------------------------- hw/nvme fixes ---------------------------------------------------------------- Klaus Jensen (1): hw/nvme: fix missing DNR on compare failure Mateusz Kozlowski (1): hw/nvme: Change alignment in dma functions for nvme_blk_* hw/nvme/ctrl.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) -- 2.39.2 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PULL 0/2] hw/nvme fixes 2023-03-27 17:09 Klaus Jensen @ 2023-03-28 16:00 ` Peter Maydell 0 siblings, 0 replies; 8+ messages in thread From: Peter Maydell @ 2023-03-28 16:00 UTC (permalink / raw) To: Klaus Jensen Cc: qemu-devel, Kevin Wolf, Philippe Mathieu-Daudé, Fam Zheng, qemu-block, Hanna Reitz, Stefan Hajnoczi, Keith Busch, Klaus Jensen On Mon, 27 Mar 2023 at 18:09, Klaus Jensen <its@irrelevant.dk> wrote: > > From: Klaus Jensen <k.jensen@samsung.com> > > Hi Peter, > > The following changes since commit e3debd5e7d0ce031356024878a0a18b9d109354a: > > Merge tag 'pull-request-2023-03-24' of https://gitlab.com/thuth/qemu into staging (2023-03-24 16:08:46 +0000) > > are available in the Git repository at: > > https://gitlab.com/birkelund/qemu.git tags/nvme-next-pull-request > > for you to fetch changes up to ca2a091802872b265bc6007a2d36276d51d8e4b3: > > hw/nvme: fix missing DNR on compare failure (2023-03-27 19:05:23 +0200) > > ---------------------------------------------------------------- > hw/nvme fixes > > ---------------------------------------------------------------- > > Klaus Jensen (1): > hw/nvme: fix missing DNR on compare failure > > Mateusz Kozlowski (1): > hw/nvme: Change alignment in dma functions for nvme_blk_* > > hw/nvme/ctrl.c | 26 +++++++++++++------------- > 1 file changed, 13 insertions(+), 13 deletions(-) Applied, thanks. Please update the changelog at https://wiki.qemu.org/ChangeLog/8.0 for any user-visible changes. -- PMM ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PULL 0/2] hw/nvme fixes @ 2022-11-02 8:25 Klaus Jensen 2022-11-03 21:26 ` Stefan Hajnoczi 0 siblings, 1 reply; 8+ messages in thread From: Klaus Jensen @ 2022-11-02 8:25 UTC (permalink / raw) To: qemu-devel; +Cc: qemu-block, Klaus Jensen, Keith Busch, Klaus Jensen From: Klaus Jensen <k.jensen@samsung.com> Hi, The following changes since commit a11f65ec1b8adcb012b89c92819cbda4dc25aaf1: Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2022-11-01 13:49:33 -0400) are available in the Git repository at: git://git.infradead.org/qemu-nvme.git tags/nvme-fixes-pull-request for you to fetch changes up to 632cb6cf07122b330d8ef419ec2f4aab561a9fba: hw/nvme: Abort copy command when format is one while pif (2022-11-02 09:23:05 +0100) ---------------------------------------------------------------- hw/nvme fixes Two small fixes. ---------------------------------------------------------------- Francis Pravin Antony Michael Raj (1): hw/nvme: Abort copy command when format is one while pif Klaus Jensen (1): hw/nvme: reenable cqe batching hw/nvme/ctrl.c | 29 +++++++++++++---------------- hw/nvme/nvme.h | 4 ++-- 2 files changed, 15 insertions(+), 18 deletions(-) -- 2.38.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PULL 0/2] hw/nvme fixes 2022-11-02 8:25 Klaus Jensen @ 2022-11-03 21:26 ` Stefan Hajnoczi 0 siblings, 0 replies; 8+ messages in thread From: Stefan Hajnoczi @ 2022-11-03 21:26 UTC (permalink / raw) To: Klaus Jensen Cc: qemu-devel, qemu-block, Klaus Jensen, Keith Busch, Klaus Jensen [-- Attachment #1: Type: text/plain, Size: 115 bytes --] Applied, thanks. Please update the changelog at https://wiki.qemu.org/ChangeLog/7.2 for any user-visible changes. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-08-07 20:37 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-07 11:54 [PULL 0/2] hw/nvme fixes Klaus Jensen 2023-08-07 11:54 ` [PULL 1/2] hw/nvme: fix oob memory read in fdp events log Klaus Jensen 2023-08-07 11:54 ` [PULL 2/2] hw/nvme: fix compliance issue wrt. iosqes/iocqes Klaus Jensen 2023-08-07 20:36 ` [PULL 0/2] hw/nvme fixes Richard Henderson -- strict thread matches above, loose matches on Subject: below -- 2023-03-27 17:09 Klaus Jensen 2023-03-28 16:00 ` Peter Maydell 2022-11-02 8:25 Klaus Jensen 2022-11-03 21:26 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).