From: Klaus Jensen <its@irrelevant.dk>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
qemu-block@nongnu.org, Klaus Jensen <k.jensen@samsung.com>,
Max Reitz <mreitz@redhat.com>, Keith Busch <kbusch@kernel.org>,
Stefan Hajnoczi <stefanha@redhat.com>,
Klaus Jensen <its@irrelevant.dk>
Subject: [PULL 01/11] hw/block/nvme: fix potential overflow
Date: Tue, 16 Mar 2021 22:47:43 +0100 [thread overview]
Message-ID: <20210316214753.399389-2-its@irrelevant.dk> (raw)
In-Reply-To: <20210316214753.399389-1-its@irrelevant.dk>
From: Klaus Jensen <k.jensen@samsung.com>
page_size is a uint32_t, and zasl is a uint8_t, so the expression
`page_size << zasl` is done using 32-bit arithmetic and might overflow.
Since we then compare this against a 64 bit data_size value, Coverity
complains that we might overflow unintentionally. An MDTS/ZASL value in
excess of 4GiB is probably impractical, but it is not entirely
unrealistic, so add a cast such that we handle that case properly.
Fixes: 578d914b263c ("hw/block/nvme: align zoned.zasl with mdts")
Fixes: CID 1450756
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
hw/block/nvme.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index d439e44db839..0d9b980151ae 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -2188,7 +2188,8 @@ static uint16_t nvme_do_write(NvmeCtrl *n, NvmeRequest *req, bool append,
goto invalid;
}
- if (n->params.zasl && data_size > n->page_size << n->params.zasl) {
+ if (n->params.zasl &&
+ data_size > (uint64_t)n->page_size << n->params.zasl) {
trace_pci_nvme_err_zasl(data_size);
return NVME_INVALID_FIELD | NVME_DNR;
}
--
2.30.1
next prev parent reply other threads:[~2021-03-16 21:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 21:47 [PULL 00/11] emulated nvme updates and fixes Klaus Jensen
2021-03-16 21:47 ` Klaus Jensen [this message]
2021-03-16 21:47 ` [PULL 02/11] hw/block/nvme: assert namespaces array indices Klaus Jensen
2021-03-16 21:47 ` [PULL 03/11] hw/block/nvme: fix zone management receive reporting too many zones Klaus Jensen
2021-03-16 21:47 ` [PULL 04/11] hw/block/nvme: add metadata support Klaus Jensen
2021-03-16 21:47 ` [PULL 05/11] hw/block/nvme: end-to-end data protection Klaus Jensen
2021-03-16 21:47 ` [PULL 06/11] hw/block/nvme: add verify command Klaus Jensen
2021-03-16 21:47 ` [PULL 07/11] hw/block/nvme: add non-mdts command size limit for verify Klaus Jensen
2021-03-16 21:47 ` [PULL 08/11] hw/block/nvme: support multiple lba formats Klaus Jensen
2021-03-16 21:47 ` [PULL 09/11] hw/block/nvme: prefer runtime helpers instead of device parameters Klaus Jensen
2021-03-16 21:47 ` [PULL 10/11] hw/block/nvme: pull lba format initialization Klaus Jensen
2021-03-16 21:47 ` [PULL 11/11] hw/block/nvme: add support for the format nvm command Klaus Jensen
2021-03-18 11:26 ` [PULL 00/11] emulated nvme updates and fixes Peter Maydell
2021-03-18 11:27 ` Klaus Jensen
2021-03-18 11:28 ` Peter Maydell
2021-03-18 12:01 ` Klaus Jensen
2021-03-18 12:11 ` Daniel P. Berrangé
2021-03-22 19:27 ` Klaus Jensen
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=20210316214753.399389-2-its@irrelevant.dk \
--to=its@irrelevant.dk \
--cc=fam@euphon.net \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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;
as well as URLs for NNTP newsgroup(s).