All of lore.kernel.org
 help / color / mirror / Atom feed
From: gerben@altlinux.org
To: qemu-devel@nongnu.org, richard.henderson@linaro.org
Cc: sdl.qemu@linuxtesting.org
Subject: [PATCH] target/hppa: prevent overflow in BTLB entry size calculation
Date: Thu, 14 Aug 2025 13:43:22 +0300	[thread overview]
Message-ID: <20250814104511.12823-1-gerben@altlinux.org> (raw)
In-Reply-To: <5ab2be93-2551-4c82-886d-3cdf47360322@linaro.org>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 1155 bytes --]

1) I’m not entirely sure why using long long is considered “always wrong,”
especially since just a few lines above there’s a similar usage here:

qemu_log_mask(CPU_LOG_MMU, "PDC_BLOCK_TLB: PDC_BTLB_INSERT "
                    "0x%08llx-0x%08llx: vpage 0x%llx for phys page 0x%04x len %d "
                    "into slot %d\n",
                    (long long) virt_page << TARGET_PAGE_BITS,
                    (long long) (virt_page + len) << TARGET_PAGE_BITS,
                    (long long) virt_page, phys_page, len, slot);

That said, I do agree that using long long here might not be the best approach, and I’ll fix it.

2) If len can approach INT32_MAX, why wouldn’t the calculation len * TARGET_PAGE_SIZE cause an overflow?
This operation is done between an unsigned int and a constant, and uses 32-bit arithmetic.
I agree this patch likely doesn’t affect real scenarios — when running the Debian image
I saw only values where len <= 2048 and TARGET_PAGE_SIZE = 4096, so no overflow would occur.
However, as I understand it, these values come from outside and are not validated anywhere,
so theoretically they could be arbitrary.


  reply	other threads:[~2025-08-14 10:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-22 10:18 [PATCH] target/hppa: prevent overflow in BTLB entry size calculation gerben
2025-07-22 14:35 ` Richard Henderson
2025-08-14 10:43   ` gerben [this message]
2025-08-14 23:24     ` Richard Henderson

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=20250814104511.12823-1-gerben@altlinux.org \
    --to=gerben@altlinux.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=sdl.qemu@linuxtesting.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.