* [PATCH] platform/x86: ibm_rtl: Fix potential OOB read at signature search
@ 2026-10-20 13:02 Takashi Iwai
2026-10-20 13:52 ` Ilpo Järvinen
0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2026-10-20 13:02 UTC (permalink / raw)
To: platform-driver-x86
Cc: Hans de Goede, Ilpo Järvinen, Junrui Luo, linux-kernel
The loop for signature search fetches 8 bytes at each check, while the
loop count is calculated in 4 bytes unit, which means that, at the
last entry, it fetches over the limit.
Correct the boundary condition to "ebda_size/sizeof(unsigned int)-1"
for avoiding the potential OOB access.
Fixes: 15dd100349b8 ("platform/x86: ibm_rtl: fix EBDA signature search pointer arithmetic")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
drivers/platform/x86/ibm_rtl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/x86/ibm_rtl.c b/drivers/platform/x86/ibm_rtl.c
index 139956168cf9..6d6998049d8c 100644
--- a/drivers/platform/x86/ibm_rtl.c
+++ b/drivers/platform/x86/ibm_rtl.c
@@ -271,7 +271,7 @@ static int __init ibm_rtl_init(void) {
return -ENOMEM;
/* search for the _RTL_ signature at the start of the table */
- for (i = 0 ; i < ebda_size/sizeof(unsigned int); i++) {
+ for (i = 0 ; i < ebda_size/sizeof(unsigned int) - 1; i++) {
struct ibm_rtl_table __iomem * tmp;
tmp = (struct ibm_rtl_table __iomem *) (ebda_map + i*sizeof(unsigned int));
if ((readq(&tmp->signature) & RTL_MASK) == RTL_SIGNATURE) {
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] platform/x86: ibm_rtl: Fix potential OOB read at signature search
2026-10-20 13:02 [PATCH] platform/x86: ibm_rtl: Fix potential OOB read at signature search Takashi Iwai
@ 2026-10-20 13:52 ` Ilpo Järvinen
2026-10-20 14:17 ` Takashi Iwai
0 siblings, 1 reply; 3+ messages in thread
From: Ilpo Järvinen @ 2026-10-20 13:52 UTC (permalink / raw)
To: Takashi Iwai; +Cc: platform-driver-x86, Hans de Goede, Junrui Luo, LKML
On Tue, 20 Oct 2026, Takashi Iwai wrote:
> The loop for signature search fetches 8 bytes at each check,
But that's not all it's going to access??
> while the
> loop count is calculated in 4 bytes unit, which means that, at the
> last entry, it fetches over the limit.
>
> Correct the boundary condition to "ebda_size/sizeof(unsigned int)-1"
This seems even more obfuscated than this code already is!
I think it should do this instead:
(ebda_size - sizeof(*rtl_table)) / sizeof(u32)
Admittedly, it a logical change too but why you think only partial RTL
table is good enough just because signature can be checked? After the sig
check, it will read the struct beyond that.
...And that other sizeof() should use u32 as well.
Unrelated to this change and if you have this HW and can test changes, it
would be nice to also get rid of the debug parameter and use dynamic
debugging instead of RTL_DEBUG() for consistency.
I also don't understand why it's mixing readq() and ioread*() for reading
from the same area.
> for avoiding the potential OOB access.
>
> Fixes: 15dd100349b8 ("platform/x86: ibm_rtl: fix EBDA signature search pointer arithmetic")
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> drivers/platform/x86/ibm_rtl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/ibm_rtl.c b/drivers/platform/x86/ibm_rtl.c
> index 139956168cf9..6d6998049d8c 100644
> --- a/drivers/platform/x86/ibm_rtl.c
> +++ b/drivers/platform/x86/ibm_rtl.c
> @@ -271,7 +271,7 @@ static int __init ibm_rtl_init(void) {
> return -ENOMEM;
>
> /* search for the _RTL_ signature at the start of the table */
> - for (i = 0 ; i < ebda_size/sizeof(unsigned int); i++) {
> + for (i = 0 ; i < ebda_size/sizeof(unsigned int) - 1; i++) {
Also remove that extra space after i = 0.
> struct ibm_rtl_table __iomem * tmp;
> tmp = (struct ibm_rtl_table __iomem *) (ebda_map + i*sizeof(unsigned int));
> if ((readq(&tmp->signature) & RTL_MASK) == RTL_SIGNATURE) {
>
--
i.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] platform/x86: ibm_rtl: Fix potential OOB read at signature search
2026-10-20 13:52 ` Ilpo Järvinen
@ 2026-10-20 14:17 ` Takashi Iwai
0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2026-10-20 14:17 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Takashi Iwai, platform-driver-x86, Hans de Goede, Junrui Luo, LKML
On Tue, 20 Oct 2026 15:52:28 +0200,
Ilpo Järvinen wrote:
>
> On Tue, 20 Oct 2026, Takashi Iwai wrote:
>
> > The loop for signature search fetches 8 bytes at each check,
>
> But that's not all it's going to access??
Oh indeed it access further.
> > while the
> > loop count is calculated in 4 bytes unit, which means that, at the
> > last entry, it fetches over the limit.
> >
> > Correct the boundary condition to "ebda_size/sizeof(unsigned int)-1"
>
> This seems even more obfuscated than this code already is!
Yeah, the driver code is really ugly, and I made a whip cream on the
top :)
> I think it should do this instead:
>
> (ebda_size - sizeof(*rtl_table)) / sizeof(u32)
Hrm, this will result in the omit of the last loop entry?
I guess it'd be better understandable rather by directly adding the
offset in the loop instead of the counter. Something like below.
> Admittedly, it a logical change too but why you think only partial RTL
> table is good enough just because signature can be checked? After the sig
> check, it will read the struct beyond that.
>
> ...And that other sizeof() should use u32 as well.
>
>
> Unrelated to this change and if you have this HW and can test changes, it
> would be nice to also get rid of the debug parameter and use dynamic
> debugging instead of RTL_DEBUG() for consistency.
No, I don't. It was caught only through reviews at backporting to the
distro kernels.
> I also don't understand why it's mixing readq() and ioread*() for reading
> from the same area.
I guess it's just an optimization for the signature check.
The driver needs significant code cleanup, in anyway...
thanks,
Takashi
-- 8< --
From: Takashi Iwai <tiwai@suse.de>
Subject: [PATCH v2] platform/x86: ibm_rtl: Fix potential OOB read at signature
search
The loop for signature search fetches 22 bytes of struct ibm_rtl_table
at each check, while the loop count is calculated in 4 bytes unit,
which means that, at the last entry, it fetches over the limit.
Rewrite the loop to use the byte offset and correct the boundary
condition check for avoiding the potential OOB access.
Fixes: 15dd100349b8 ("platform/x86: ibm_rtl: fix EBDA signature search pointer arithmetic")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
drivers/platform/x86/ibm_rtl.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/ibm_rtl.c b/drivers/platform/x86/ibm_rtl.c
index 139956168cf9..6f0a10e1d81e 100644
--- a/drivers/platform/x86/ibm_rtl.c
+++ b/drivers/platform/x86/ibm_rtl.c
@@ -234,9 +234,9 @@ static const struct dmi_system_id ibm_rtl_dmi_table[] __initconst = {
};
static int __init ibm_rtl_init(void) {
- unsigned long ebda_addr, ebda_size;
+ unsigned long ebda_addr, ebda_size, offset;
unsigned int ebda_kb;
- int ret = -ENODEV, i;
+ int ret = -ENODEV;
if (force)
pr_warn("module loaded by force\n");
@@ -271,9 +271,9 @@ static int __init ibm_rtl_init(void) {
return -ENOMEM;
/* search for the _RTL_ signature at the start of the table */
- for (i = 0 ; i < ebda_size/sizeof(unsigned int); i++) {
+ for (offset = 0 ; offset + sizeof(*rtl_table) <= ebda_size; offset += 4) {
struct ibm_rtl_table __iomem * tmp;
- tmp = (struct ibm_rtl_table __iomem *) (ebda_map + i*sizeof(unsigned int));
+ tmp = (struct ibm_rtl_table __iomem *) (ebda_map + offset);
if ((readq(&tmp->signature) & RTL_MASK) == RTL_SIGNATURE) {
phys_addr_t addr;
unsigned int plen;
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-20 14:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 13:02 [PATCH] platform/x86: ibm_rtl: Fix potential OOB read at signature search Takashi Iwai
2026-10-20 13:52 ` Ilpo Järvinen
2026-10-20 14:17 ` Takashi Iwai
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®