From: sashiko-bot@kernel.org
To: "Vincent Donnefort" <vdonnefort@google.com>
Cc: "Oliver Upton" <oupton@kernel.org>,
kvmarm@lists.linux.dev, "Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace
Date: Thu, 08 Oct 2026 10:56:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-164063@kernel.org> (raw)
In-Reply-To: <20261008104212.3134550-3-vdonnefort@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] tracing: Integer overflow in trace buffer size calculation bypasses capacity check
--
commit 652836a529b433a8c0e0cb4f4308fa9b9556763d
Author: Vincent Donnefort <vdonnefort@google.com>
KVM: arm64: Fix bpages backing allocation size in hyp_trace
This commit updates the trace buffer backing allocation in hyp_trace to
calculate the required number of pages using
__calc_nr_pages_ring_buffer_desc(). This appropriately accounts for the
buffer page header and relies on trace_buffer_desc_size() for validation.
> diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c
> index 26fc13c164589..b9404496f9775 100644
> --- a/arch/arm64/kvm/hyp_trace.c
> +++ b/arch/arm64/kvm/hyp_trace.c
[ ... ]
> @@ -157,7 +157,7 @@ static int hyp_trace_buffer_alloc_bpages_backing(struct hyp_trace_buffer *trace_
> return 0;
> }
>
> - nr_bpages = (PAGE_ALIGN(size) / PAGE_SIZE) + 1;
> + nr_bpages = __calc_nr_pages_ring_buffer_desc(size);
[Severity: Low]
Does this calculation overflow if size is near SIZE_MAX?
Looking at __calc_nr_pages_ring_buffer_desc() in include/linux/ring_buffer.h:
static inline unsigned long __calc_nr_pages_ring_buffer_desc(size_t size)
{
/* Takes into account the reader page */
return max(DIV_ROUND_UP(size, PAGE_SIZE - BUF_PAGE_HDR_SIZE), 2UL) + 1;
}
If size is extremely large, the DIV_ROUND_UP macro wraps around, causing the
function to erroneously return a very small page count (e.g. 0 wrapping to 3
pages).
The commit message notes there is no need to validate nr_bpages again because
it was validated by trace_buffer_desc_size(), but could this overflow bypass
that check?
Looking at trace_buffer_desc_size() in include/linux/ring_buffer.h:
/* Capped by ring_buffer_desc::nr_page_va */
if (nr_pages > UINT_MAX)
return SIZE_MAX;
Because the wrapped nr_pages is small, this capacity check would be
circumvented, bypassing the intended -E2BIG rejection. Downstream consumers
like hyp_trace_buffer_alloc_bpages_backing(), trace_remote_alloc_buffer(),
and __tracing_load() would then operate safely on this truncated page count.
This results in a silent failure where the kernel allocates a tiny functional
trace buffer instead of returning an error for the impossibly large
allocation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261008104212.3134550-1-vdonnefort@google.com?part=2
next prev parent reply other threads:[~2026-10-08 10:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 10:42 [PATCH v1 0/2] KVM: arm64: Fixes for hyp_trace Vincent Donnefort
2026-10-08 10:42 ` [PATCH v1 1/2] KVM: arm64: Prevent 64-bit overflow when computing hyp clock rate Vincent Donnefort
2026-10-08 19:12 ` Fuad Tabba
2026-10-08 10:42 ` [PATCH v1 2/2] KVM: arm64: Fix bpages backing allocation size in hyp_trace Vincent Donnefort
2026-10-08 10:56 ` sashiko-bot [this message]
2026-10-08 19:13 ` Fuad Tabba
2026-10-09 8:39 ` Vincent Donnefort
2026-10-10 9:48 ` [PATCH v1 0/2] KVM: arm64: Fixes for hyp_trace Marc Zyngier
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=sashiko-outbox-164063@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vdonnefort@google.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