Re: [PATCH 1/4] PCI: Align proc_bus_pci_write() with pci_write_config()
From: Krzysztof Wilczyński
Date: Sun May 03 2026 - 19:02:21 EST
Hello,
> - if (pos >= size)
> + if (off >= dev->cfg_size)
> return 0;
> - if (nbytes >= size)
> + if (off + size > dev->cfg_size) {
> + size = dev->cfg_size - off;
> nbytes = size;
> - if (pos + nbytes > size)
> - nbytes = size - pos;
> - cnt = nbytes;
> + }
Some of these boundary checks have issues on the sysfs side, where for some
offsets, a gratuitous pci_config_pm_runtime_get()/put() invocation would take
place, even though there would be no real work done. Something to fix, too,
since you are looking to align both implementations.
> - if ((pos & 1) && cnt) {
> + if ((off & 1) && size) {
> unsigned char val;
> __get_user(val, buf);
Sashiko is complaining about __get_user() here. However, the following
patch was sent recently, which aims to fix this (seems Syzkaller found
this, too):
https://lore.kernel.org/linux-pci/20260502011446.125268-1-kartikey406@xxxxxxxxx/
If this one is accepted, then there is nothing to do here. Otherwise, you
could consider moving to get_user(), etc., here, too.
> - while (cnt >= 4) {
> + while (size >= 4) {
This can still be aligned between here and sysfs. Have a look there.
There is also the resource_is_exclusive() check on the sysfs side which
adds a warning and a taint when write is accessing some address ranges
which some driver claimed for itself. procfs does not have this at the
moment (not sure if on purpose or it simly wasn't ever added).
Thank you!
Krzysztof