* [BUG] Drivers/8255: Page fault in comedi_8255.c
@ 2025-11-29 13:19 李天宇
2025-12-03 13:08 ` Ian Abbott
0 siblings, 1 reply; 6+ messages in thread
From: 李天宇 @ 2025-11-29 13:19 UTC (permalink / raw)
To: linux-kernel; +Cc: abbotti, hsweeten, xujiakai2025, zhaoruilin22
Hi,
There’s a bug in the comedi_8255.c file, specifically related to a page fault. This issue occurs when an illegal address is passed as a parameter to outb() function at line 47. This illegal address is subsequently used in asm code, leading to a page fault when trying to write to -0x70(%rsi).
The bug was initially discovered via a fuzzing framework on Linux kernel version 6.18-rc6, and it was later found reproducible on Linux kernel version 6.18-rc7.
After analyzing the calling stack, I suspect that the root cause may lie in the dev_8255_attach function. Specifically, at 8255.c:70, when reading iobase from it->options[i], there seems to be no validation for the conversion from int to unsigned long. If a negative value is encountered, it is cast to an illegally large number (e.g., 0xffff…), which may be causing the issue.
I’m not entirely confident in this analysis, but fortunately, there’s enough information provided for your reference:
Kernel Source: https://git.kernel.org/torvalds/t/linux-6.18-rc7.tar.gz
Configuration: https://github.com/j1akai/KConfigFuzz_bug/raw/refs/heads/main/x86/mainline-config
Reproducible Code: https://github.com/Wxm-233/KConfigFuzz_crashes/raw/refs/heads/main/405536bde2d1b503f3903a2a3de2d6dd94cef0a3/repro.cprog
GCC Info: https://github.com/Wxm-233/KConfigFuzz_crashes/raw/refs/heads/main/405536bde2d1b503f3903a2a3de2d6dd94cef0a3/gccinfo
Kernel Log(First found): https://github.com/Wxm-233/KConfigFuzz_crashes/raw/refs/heads/main/405536bde2d1b503f3903a2a3de2d6dd94cef0a3/report0
Kernel Log(Later Repro): https://github.com/Wxm-233/KConfigFuzz_crashes/raw/refs/heads/main/405536bde2d1b503f3903a2a3de2d6dd94cef0a3/report
I hope this information is helpful in identifying and resolving the issue. Thanks for your time and attention.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [BUG] Drivers/8255: Page fault in comedi_8255.c
2025-11-29 13:19 [BUG] Drivers/8255: Page fault in comedi_8255.c 李天宇
@ 2025-12-03 13:08 ` Ian Abbott
2025-12-04 12:03 ` 李天宇
0 siblings, 1 reply; 6+ messages in thread
From: Ian Abbott @ 2025-12-03 13:08 UTC (permalink / raw)
To: 李天宇, linux-kernel
Cc: hsweeten, xujiakai2025, zhaoruilin22
On 29/11/2025 13:19, 李天宇 wrote:
> Hi,
>
> There’s a bug in the comedi_8255.c file, specifically related to a page fault. This issue occurs when an illegal address is passed as a parameter to outb() function at line 47. This illegal address is subsequently used in asm code, leading to a page fault when trying to write to -0x70(%rsi).
>
> The bug was initially discovered via a fuzzing framework on Linux kernel version 6.18-rc6, and it was later found reproducible on Linux kernel version 6.18-rc7.
>
> After analyzing the calling stack, I suspect that the root cause may lie in the dev_8255_attach function. Specifically, at 8255.c:70, when reading iobase from it->options[i], there seems to be no validation for the conversion from int to unsigned long. If a negative value is encountered, it is cast to an illegally large number (e.g., 0xffff…), which may be causing the issue.
There is validation by request_region(), which is the reason for the
reported I/O port conflicts.
Admittedly, the 8255 driver should probably reject any specified I/O
port addresses that are not aligned on 4 byte boundaries to match the
register decoding of the 8255 chip, but I don't think that's the problem
here.
>
> I’m not entirely confident in this analysis, but fortunately, there’s enough information provided for your reference:
>
> Kernel Source: https://git.kernel.org/torvalds/t/linux-6.18-rc7.tar.gz
> Configuration: https://github.com/j1akai/KConfigFuzz_bug/raw/refs/heads/main/x86/mainline-config
> Reproducible Code: https://github.com/Wxm-233/KConfigFuzz_crashes/raw/refs/heads/main/405536bde2d1b503f3903a2a3de2d6dd94cef0a3/repro.cprog
> GCC Info: https://github.com/Wxm-233/KConfigFuzz_crashes/raw/refs/heads/main/405536bde2d1b503f3903a2a3de2d6dd94cef0a3/gccinfo
> Kernel Log(First found): https://github.com/Wxm-233/KConfigFuzz_crashes/raw/refs/heads/main/405536bde2d1b503f3903a2a3de2d6dd94cef0a3/report0
> Kernel Log(Later Repro): https://github.com/Wxm-233/KConfigFuzz_crashes/raw/refs/heads/main/405536bde2d1b503f3903a2a3de2d6dd94cef0a3/report
>
> I hope this information is helpful in identifying and resolving the issue. Thanks for your time and attention.
>
Looking at the list of I/O base addresses that "repro.c" is using and
the I/O port conflict messages in the "Later Repro" report, it seems
happy enough until it tries to set up an 8255 subdevice at I/O port base
address 0x100. I don't know if there is any actual (or virtual)
hardware at that base address that may be causing problems.
Historically, IBM PS/2 systems had a set of Programmable Option Select
registers at that address.
--
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [BUG] Drivers/8255: Page fault in comedi_8255.c
2025-12-03 13:08 ` Ian Abbott
@ 2025-12-04 12:03 ` 李天宇
2025-12-04 17:11 ` Ian Abbott
0 siblings, 1 reply; 6+ messages in thread
From: 李天宇 @ 2025-12-04 12:03 UTC (permalink / raw)
To: Ian Abbott, linux-kernel; +Cc: hsweeten, xujiakai2025, zhaoruilin22
Hi Ian,
Thank you very much for the analysis and your helpful suggestions.
Following your hint, I performed additional experiments by modifying the I/O base address passed through COMEDI_DEVCONFIG. The results are quite interesting:
- Using 0x100, 0x200, or 0x300 as the base address consistently triggers a kernel panic (page fault in subdev_8255_io).
- Removing the value entirely from the options array avoids the crash (I/O port conflict remains).
- Using 0x400 also does *not* trigger the issue.
This seems to support your point that certain I/O port ranges may be problematic, and the fault is not solely caused by the conversion from negative values to an unsigned address. Instead, it may indeed be related to specific port regions conflicting or being unmapped during device initialization.
At this point, I am not sufficiently familiar with the driver internals to confidently determine whether this behavior is expected or if it should be considered a bug. Given the reproducibility and the fact that unvalidated base addresses can lead to a direct page fault, I would like to ask:
Do you think this should be treated as a bug in the 8255 driver, possibly requiring additional validation or rejection of unsupported I/O port ranges? If so, I would be happy to continue testing or assist in any way, but further guidance from someone experienced with this driver would be greatly appreciated.
Thanks again for your time and insights.
Best regards.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [BUG] Drivers/8255: Page fault in comedi_8255.c
2025-12-04 12:03 ` 李天宇
@ 2025-12-04 17:11 ` Ian Abbott
2025-12-09 13:24 ` Tianyu Li
0 siblings, 1 reply; 6+ messages in thread
From: Ian Abbott @ 2025-12-04 17:11 UTC (permalink / raw)
To: 李天宇, linux-kernel
Cc: hsweeten, xujiakai2025, zhaoruilin22
On 04/12/2025 12:03, 李天宇 wrote:
> Hi Ian,
>
> Thank you very much for the analysis and your helpful suggestions.
>
> Following your hint, I performed additional experiments by modifying the I/O base address passed through COMEDI_DEVCONFIG. The results are quite interesting:
>
> - Using 0x100, 0x200, or 0x300 as the base address consistently triggers a kernel panic (page fault in subdev_8255_io).
> - Removing the value entirely from the options array avoids the crash (I/O port conflict remains).
> - Using 0x400 also does *not* trigger the issue.
>
> This seems to support your point that certain I/O port ranges may be problematic, and the fault is not solely caused by the conversion from negative values to an unsigned address. Instead, it may indeed be related to specific port regions conflicting or being unmapped during device initialization.
There must be something special about those I/O port addresses on the
test system, but nothing that the 8255 driver should care about. It's a
non-PnP driver and the system administrator is supposed to supply the
correct information when using the COMEDI_DEVCONFIG ioctl (via the
comedi_config command).
It's not unique to comedi. For example, non-PnP serial ports can be
configured in the same way using the TIOCSSERIAL ioctl (via the
setserial command).
> At this point, I am not sufficiently familiar with the driver internals to confidently determine whether this behavior is expected or if it should be considered a bug. Given the reproducibility and the fact that unvalidated base addresses can lead to a direct page fault, I would like to ask:
>
> Do you think this should be treated as a bug in the 8255 driver, possibly requiring additional validation or rejection of unsupported I/O port ranges? If so, I would be happy to continue testing or assist in any way, but further guidance from someone experienced with this driver would be greatly appreciated.
I think it does sufficient validation on the base address, but one
improvement would be to only allow base addresses aligned to a 4-byte
boundary, because (base & 3) != 0 does not make sense for an 8255 chip.
One thing that will affect the fuzzing tests is that the "8255" driver
in "linux-next" now returns an error as soon as it fails to reserve any
I/O port region, so unless the special base addresses (0x100 etc.)
appear early in the list before the conflicting base addresses, it won't
crash.
Best regards,
Ian
--
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [BUG] Drivers/8255: Page fault in comedi_8255.c
2025-12-04 17:11 ` Ian Abbott
@ 2025-12-09 13:24 ` Tianyu Li
2025-12-10 10:06 ` Ian Abbott
0 siblings, 1 reply; 6+ messages in thread
From: Tianyu Li @ 2025-12-09 13:24 UTC (permalink / raw)
To: Ian Abbott; +Cc: linux-kernel, hsweeten, xujiakai2025, zhaoruilin22
Hi Ian,
Thank you for the detailed explanation — that clarifies the situation very well.
You mentioned that in linux-next the 8255 driver now returns an error immediately when reserving an I/O port region fails, which would also avoid the crash during fuzzing. I would like to take a closer look at that change.
> One thing that will affect the fuzzing tests is that the "8255" driver
> in "linux-next" now returns an error as soon as it fails to reserve any
> I/O port region, so unless the special base addresses (0x100 etc.)
> appear early in the list before the conflicting base addresses, it won't
> crash.
Could you please point me to the specific commit or patch where this improvement was introduced (a commit hash or link would be perfect if convenient)? This would help me better understand the context and verify the behavior on my side.
Thanks again for your guidance — I really appreciate your help.
Best regards,
Tianyu Li
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [BUG] Drivers/8255: Page fault in comedi_8255.c
2025-12-09 13:24 ` Tianyu Li
@ 2025-12-10 10:06 ` Ian Abbott
0 siblings, 0 replies; 6+ messages in thread
From: Ian Abbott @ 2025-12-10 10:06 UTC (permalink / raw)
To: Tianyu Li; +Cc: linux-kernel, hsweeten, xujiakai2025, zhaoruilin22
On 09/12/2025 13:24, Tianyu Li wrote:
> Hi Ian,
>
> Thank you for the detailed explanation — that clarifies the situation very well.
>
> You mentioned that in linux-next the 8255 driver now returns an error immediately when reserving an I/O port region fails, which would also avoid the crash during fuzzing. I would like to take a closer look at that change.
>
> > One thing that will affect the fuzzing tests is that the "8255" driver
> > in "linux-next" now returns an error as soon as it fails to reserve any
> > I/O port region, so unless the special base addresses (0x100 etc.)
> > appear early in the list before the conflicting base addresses, it won't
> > crash.
>
> Could you please point me to the specific commit or patch where this improvement was introduced (a commit hash or link would be perfect if convenient)? This would help me better understand the context and verify the behavior on my side.
It's this one:
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=98d86d87aafb01e7c60b46d327a0a32619a167ff
> Thanks again for your guidance — I really appreciate your help.
>
> Best regards,
> Tianyu Li
Kind regards,
Ian
--
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-12-10 10:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-29 13:19 [BUG] Drivers/8255: Page fault in comedi_8255.c 李天宇
2025-12-03 13:08 ` Ian Abbott
2025-12-04 12:03 ` 李天宇
2025-12-04 17:11 ` Ian Abbott
2025-12-09 13:24 ` Tianyu Li
2025-12-10 10:06 ` Ian Abbott
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®