[PATCH] crypto: asymmetric_keys: verify_pefile: fix integer underflow in pefile_strip_sig_wrapper
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon Nov 9 17:49:34 PST 2026
> The pefile_strip_sig_wrapper() function validates the win_certificate
> wrapper that precedes the PKCS#7 signature in a PE binary. It checks
> that the wrapper length does not exceed the certificate table size
> (``wrapper.length > ctx->sig_len``) but fails to verify that the
> wrapper length is at least ``sizeof(struct win_certificate)`` (8 bytes).
>
> When a crafted PE image supplies a wrapper with ``length`` in the range
> [1, 7], the subsequent arithmetic::
>
> ctx->sig_len = wrapper.length; /* e.g. 1 */
> ctx->sig_offset += sizeof(wrapper);
> ctx->sig_len -= sizeof(wrapper); /* 1 - 8 = 0xFFFFFFF9 (unsigned) */
>
> underflows the unsigned ``ctx->sig_len`` to a value near UINT_MAX. The
> following ``sig_len < 4`` sanity check is bypassed because 0xFFFFFFF9 is
> [ ... ]
> prevent the underflow.
>
> Fixes: 09dacbbda935 ("pefile: Strip the wrapper off of the cert data block")
> Cc: stable at vger.kernel.org
> Signed-off-by: Gu Bowen <gubowen5 at huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261110015657.528337-1-gubowen5@huawei.com?part=1
More information about the kexec
mailing list