From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Muhammad Bilal <meatuni001@gmail.com>
Cc: jorge.lopez2@hp.com, Hans de Goede <hansg@kernel.org>,
linux@weissschuh.net, platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/2] platform/x86: hp-bioscfg: fix OOB read in hp_get_integer_from_buffer() on unaligned input
Date: Fri, 18 Sep 2026 16:54:11 +0300 (EEST) [thread overview]
Message-ID: <7dfd5559-5ad0-e12c-b26c-96abe139bc17@linux.intel.com> (raw)
In-Reply-To: <20260824225610.18471-2-meatuni001@gmail.com>
On Tue, 25 Aug 2026, Muhammad Bilal wrote:
> hp_get_integer_from_buffer() aligns the read pointer before dereferencing
> it:
>
> int *ptr = PTR_ALIGN((int *)*buffer, sizeof(int));
>
> When *buffer is not 4-byte aligned, PTR_ALIGN() advances ptr forward by
> 1-3 bytes to reach the next aligned address. The bounds check that
> follows does not account for that advance:
>
> if (*buffer_size < sizeof(int))
> return -EINVAL;
>
> This only confirms 4 bytes remain from the original *buffer, not from
> the aligned ptr. If *buffer is unaligned and *buffer_size is between 4
> and (pad + 3) bytes, *(ptr++) reads up to 3 bytes past the end of the
> buffer.
>
> *buffer_size is also under-decremented on every call, aligned or not:
>
> *buffer_size -= sizeof(int);
>
> *buffer is advanced to the aligned, post-read position, but
> *buffer_size only accounts for the 4 bytes of the integer itself, not
> the alignment padding skipped to reach it. Each unaligned read leaves
> *buffer_size overstating the true remaining space by the pad amount,
> an error that compounds across repeated calls against the same buffer
> (hp_get_common_data_from_buffer() calls this in a sequence), making
> later bounds checks against *buffer_size progressively less reliable.
>
> Compute the padding explicitly, check for it, and account for it when
> advancing *buffer_size, so the pointer and the remaining-length count
> stay consistent with each other.
>
> Fixes: a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg")
> Cc: stable@vger.kernel.org
> Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
> ---
> drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> index 0edc6e7cfa9a..32b99a862082 100644
> --- a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> @@ -39,14 +39,18 @@ struct kobj_attribute common_display_langcode =
> int hp_get_integer_from_buffer(u8 **buffer, u32 *buffer_size, u32 *integer)
> {
> int *ptr = PTR_ALIGN((int *)*buffer, sizeof(int));
> + u32 pad = (u8 *)ptr - *buffer;
>
> - /* Ensure there is enough space remaining to read the integer */
> - if (*buffer_size < sizeof(int))
> + /*
> + * Ensure there is enough space remaining to read the integer,
> + * including any padding PTR_ALIGN() introduced to reach it.
> + */
> + if (*buffer_size < pad + sizeof(int))
> return -EINVAL;
>
> *integer = *(ptr++);
> *buffer = (u8 *)ptr;
> - *buffer_size -= sizeof(int);
> + *buffer_size -= pad + sizeof(int);
Shouldn't all thse sizeof()s be based on sizeof(*integer) or sizeof(*ptr)
instead of unbound "int"?
And is type of ptr correct? If it is, this lacks an underflow check?
This driver is such a nightmare... :-( Thanks for helping to clean it up.
--
i.
next prev parent reply other threads:[~2026-09-18 13:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 22:56 [PATCH 0/2] platform/x86: hp-bioscfg: fix OOB reads and buffer desynchronization in buffer parsers Muhammad Bilal
2026-08-24 22:56 ` [PATCH 1/2] platform/x86: hp-bioscfg: fix OOB read in hp_get_integer_from_buffer() on unaligned input Muhammad Bilal
2026-09-18 13:54 ` Ilpo Järvinen [this message]
2026-08-24 22:56 ` [PATCH 2/2] platform/x86: hp-bioscfg: fix heap OOB read and buffer desync in hp_get_string_from_buffer() Muhammad Bilal
2026-09-18 14:17 ` Ilpo Järvinen
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=7dfd5559-5ad0-e12c-b26c-96abe139bc17@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®