From: Eric Biggers <ebiggers@kernel.org>
To: Maholi Tumanggor <maholitumanggor@gmail.com>
Cc: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au,
davem@davemloft.net
Subject: Re: [PATCH v2] lib/crypto/mpi: Fix heap OOB write in mpi_powm() when res aliases input
Date: Mon, 2 Nov 2026 10:12:04 -0800 [thread overview]
Message-ID: <20261102181204.GB1935@sol> (raw)
In-Reply-To: <20261102092550.2633-1-maholitumanggor@gmail.com>
On Mon, Nov 02, 2026 at 09:25:50AM +0000, Maholi Tumanggor wrote:
> When mpi_powm() is called with res->alloced < size and res->d aliases
> base->d or exp->d, assign_rp is set to 1 and a new buffer is allocated
> for rp. However the final write-back block unconditionally writes the
> result into res->d (the original undersized buffer) instead of rp,
> causing a heap out-of-bounds write and a subsequent use-after-free when
> mpi_assign_limb_space() frees and re-assigns the corrupted buffer.
>
> The previous fix (v1) introduced a new issue: inside the exponentiation
> loop rp and xp are swapped after each squaring/multiplication step, so
> after the loop rp may point to xp_marker instead of the originally
> allocated buffer. Fix by saving the allocation pointer in rp_alloc at
> the time of allocation, then using rp_alloc as the write-back destination
> so mpi_assign_limb_space() always receives the correct buffer regardless
> of how many swaps occurred in the loop.
>
> Confirmed via SLUB debug (slub_debug=FZPU) on kernel 6.8.0-147-generic
> (Ubuntu 24.04): two BUG reports (Right Redzone overwritten and Freepointer
> corrupt) are triggered by mpi_powm(base, base, exp, mod) with base->alloced
> smaller than required, and are absent after this fix.
>
> Signed-off-by: Maholi Tumanggor <maholitumanggor@gmail.com>
Is this issue actually reachable from any existing kernel code, such as
RSA or DH? The commit message needs to mention this. If it's
reachable, explain how to reach it.
If this fixes a bug, there also needs to be a Fixes tag. Fixing a bug
in a previous, unapplied version of this same patch doesn't count.
And finally, please see the Sashiko review, which had a finding.
- Eric
prev parent reply other threads:[~2026-11-02 18:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 6:42 [PATCH] lib/crypto/mpi: Fix heap OOB write in mpi_powm() when res aliases input Maholi Tumanggor
2026-11-02 6:49 ` sashiko-bot
2026-11-02 9:25 ` [PATCH v2] " Maholi Tumanggor
2026-11-02 13:03 ` sashiko-bot
2026-11-02 18:12 ` Eric Biggers [this message]
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=20261102181204.GB1935@sol \
--to=ebiggers@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=maholitumanggor@gmail.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