From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Muhammad Bilal <meatuni001@gmail.com>
Cc: "Jorge Lopez" <jorge.lopez2@hp.com>,
"Hans de Goede" <hansg@kernel.org>,
"Thomas Weißschuh" <linux@weissschuh.net>,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH v2] platform/x86: hp-bioscfg: fix slab-out-of-bounds write in hp_convert_hexstr_to_str
Date: Tue, 15 Sep 2026 22:53:18 +0300 (EEST) [thread overview]
Message-ID: <0380b8d6-cff5-383f-b47f-700d1d17fefa@linux.intel.com> (raw)
In-Reply-To: <20260915174615.63924-1-meatuni001@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3555 bytes --]
On Tue, 15 Sep 2026, Muhammad Bilal wrote:
> hp_convert_hexstr_to_str() decodes an ACPI string made up of
> space-separated ASCII hex-byte tokens of the form "0xHH". For
> example, the four-byte input "0x41" decodes to the single
> character 'A', and the nine-byte input "0x09 0x41" decodes to
> "\tA": each token is read in a five-byte step (four characters for
> the token, one for the trailing delimiter), and produces one output
> byte, or two if that byte is '\\', '\r', '\n', or '\t', which are
> written back out as a backslash followed by the matching letter.
>
> The output buffer is sized with kmalloc(input_len, GFP_KERNEL), the
> raw encoded length of the input, not the decoded length. For
> well-formed input this is generous, since five input bytes never
> decode to more than two output bytes. But input_len comes directly
> from the ACPI string length reported by firmware and isn't
> guaranteed to respect the five-byte encoding, so a short input_len
> can undersize the allocation. With input_len == 1, only one byte is
> allocated, yet decoding still produces at least one output byte
> plus the NUL terminator written unconditionally afterwards, so two
> bytes are needed. That terminator write then lands one byte past
> the end of the allocation.
Thanks, very clear now.
I've applied this to the review-ilpo-next branch now, but please see
below for one additional thing.
> KASAN caught exactly this during BIOS attribute enumeration on
> boot, triggered by a one-byte encoded input value:
>
> BUG: KASAN: slab-out-of-bounds in hp_convert_hexstr_to_str+0x6d8/0x710 [hp_bioscfg]
> Write of size 1 at addr ffff8881032e5d81 by task (udev-worker)/520
> The buggy address is located 0 bytes to the right of
> allocated 1-byte region [ffff8881032e5d80, ffff8881032e5d81)
>
> Size the allocation to the worst-case decoded length instead of the
> raw input length: two output bytes for every five-byte input chunk
> (DIV_ROUND_UP(input_len, 5)), plus one byte for the terminator.
>
> Fixes: a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg")
> Cc: stable@vger.kernel.org
> Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
> ---
> v2: Expand the commit message to spell out the hex-token input
> format and decoded output with a worked example, and explain
> exactly how a short input_len undersizes the allocation, per
> Ilpo Järvinen's review. No code change from v1.
>
> drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> index 22c198680903..42331cf90581 100644
> --- a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> @@ -442,7 +442,7 @@ int hp_convert_hexstr_to_str(const char *input, u32 input_len, char **str, int *
> *len = 0;
> *str = NULL;
>
> - new_str = kmalloc(input_len, GFP_KERNEL);
> + new_str = kmalloc(2 * DIV_ROUND_UP(input_len, 5) + 1, GFP_KERNEL);
> if (!new_str)
> return -ENOMEM;
>
>
I think the buffer should be allocated with kzalloc() to ensure there's no
potential leakage when/if the output buffer is filled only partially
which seems well possible given your description. So it would warrant
another patch on top of this change (as I've applied this now).
And your other patches are not forgotten, I'll get to them while
processing the rest of the patch queue.
--
i.
next prev parent reply other threads:[~2026-09-15 19:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 17:46 Muhammad Bilal
2026-09-15 19:53 ` Ilpo Järvinen [this message]
2026-09-16 0:46 ` [PATCH] platform/x86: hp-bioscfg: zero the hex-string decode buffer " Muhammad Bilal
2026-09-16 10:29 ` Ilpo Järvinen
2026-09-16 10:47 ` Muhammad Bilal
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=0380b8d6-cff5-383f-b47f-700d1d17fefa@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=hansg@kernel.org \
--cc=jorge.lopez2@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=meatuni001@gmail.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®