From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Jan Kiszka <jan.kiszka@siemens.com>,
qemu-block@nongnu.org, GuoHan Zhao <zhaoguohan@kylinos.cn>
Cc: Peter Maydell <peter.maydell@linaro.org>,
qemu-devel <qemu-devel@nongnu.org>, Bin Meng <bmeng.cn@gmail.com>
Subject: Re: [PATCH] hw/sd/sdcard: Avoid confusing address calculation in rpmb_calc_hmac
Date: Sun, 16 Nov 2025 18:43:38 +0100 [thread overview]
Message-ID: <663acd8d-5c39-4f1c-b5b1-569e36e4ff95@linaro.org> (raw)
In-Reply-To: <4f7e1952-ecbd-4484-b128-9d02de3a7935@siemens.com>
Hi Jan,
On 14/11/25 22:27, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
>
> From the source frame, we initially need to copy out all fields after
> data, thus starting from nonce on. Avoid expressing this indirectly by
> pointing to the end of the data field - which also raised the attention
> of Coverity (out-of-bound read /wrt data).
>
Resolves: CID 1642869
Fixes: 3acf956ea1a ("hw/sd/sdcard: Handle RPMB MAC field")
> Reported-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>
> Tested, not causing any regression. Please check again if Coverity is
> happy as well. Thanks!
>
> hw/sd/sd.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index 9c86c016cc..7fdb9195e0 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -1161,7 +1161,8 @@ static bool rpmb_calc_hmac(SDState *sd, const RPMBDataFrame *frame,
>
> assert(RPMB_HASH_LEN <= sizeof(sd->data));
>
> - memcpy((uint8_t *)buf + RPMB_DATA_LEN, &frame->data[RPMB_DATA_LEN],
> + memcpy((uint8_t *)buf + RPMB_DATA_LEN,
> + (uint8_t *)frame + offsetof(RPMBDataFrame, nonce),
> RPMB_HASH_LEN - RPMB_DATA_LEN);
Having:
#define RPMB_HASH_LEN (RPMB_DATA_LEN + RPMB_NONCE_LEN)
then
RPMB_HASH_LEN - RPMB_DATA_LEN = RPMB_NONCE_LEN.
So this is equivalent to:
memcpy((uint8_t *)buf + RPMB_DATA_LEN,
(uint8_t *)frame + offsetof(RPMBDataFrame, nonce),
RPMB_NONCE_LEN);
How is this not equivalent to my previous "broken" suggestion?
memcpy((uint8_t *)buf + RPMB_DATA_LEN,
frame->nonce,
RPMB_NONCE_LEN);
(Yet again late here...)
> offset = lduw_be_p(&frame->address) * RPMB_DATA_LEN + sd_part_offset(sd);
> do {
next prev parent reply other threads:[~2025-11-16 17:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 21:27 [PATCH] hw/sd/sdcard: Avoid confusing address calculation in rpmb_calc_hmac Jan Kiszka
2025-11-16 17:43 ` Philippe Mathieu-Daudé [this message]
2025-11-17 6:09 ` Jan Kiszka
2025-11-18 18:36 ` Philippe Mathieu-Daudé
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=663acd8d-5c39-4f1c-b5b1-569e36e4ff95@linaro.org \
--to=philmd@linaro.org \
--cc=bmeng.cn@gmail.com \
--cc=jan.kiszka@siemens.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=zhaoguohan@kylinos.cn \
/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).