From: "Krzysztof Wilczyński" <kwilczynski@kernel.org>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: "Bjorn Helgaas" <helgaas@kernel.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
"Narendra K" <Narendra_K@dell.com>, "Martin Mareš" <mj@ucw.cz>,
linux-pci@vger.kernel.org
Subject: Re: [PATCH 0/4] PCI/sysfs: Fix the ACPI device name attributes
Date: Fri, 14 Aug 2026 18:45:31 +0900 [thread overview]
Message-ID: <20260814094122.GC3463973@rocinante> (raw)
In-Reply-To: <20260814070522.2327975-1-kwilczynski@kernel.org>
Hello,
Adding Martin Mareš for visibility.
> Currently, the "label" and "acpi_index" attributes are created whenever
> the _DSM function 0 bitmap advertises the Device Name function, and
> dsm_get_label() returns the literal -1 on every failure path. Firmware
> that advertises the function but returns an object that cannot be
> parsed therefore produces two attributes that exist and fail every read
> with -EPERM:
>
> $ cat /sys/bus/pci/devices/0000:00:08.3/label
> cat: /sys/bus/pci/devices/0000:00:08.3/label: Operation not permitted
>
> Nothing in that path performs a permission check. Tools that read the
> attribute print the failure on every invocation, which is how this
> surfaced in a pciutils report:
>
> https://github.com/pciutils/pciutils/issues/175
>
> Patch 1 returns error codes that describe what failed. Patch 2 stops a
> malformed optional device name element from also failing "acpi_index",
> which exports the mandatory instance number and does not depend on the
> name. Patch 3 evaluates the function when deciding visibility, so that
> an attribute exists only when the element it exports has a type the read
> path accepts. The documented ABI already describes the behaviour patch
> 3 implements, and the SMBIOS attribute group in the same file already
> works that way.
>
> Patch 4 corrects the length dsm_label_utf16s_to_utf8s() passes to
> utf16s_to_utf8s(). The ACPI buffer length counts bytes, while the
> converter counts wchar_t elements. For a buffer holding no NUL code
> unit the conversion reads past the end of the object allocated by
> ACPICA. The bytes it finds there are decoded into the world readable
> "label" attribute.
>
> Note that patch 2 changes behaviour on platforms that have a valid
> instance number together with a malformed name element: "acpi_index"
> starts returning data there. Because udev derives the onboard
> interface name from "acpi_index", an interface on such a platform may
> be renamed once, on the first boot after this change. The same
> mechanism, in the other direction, is recorded in dcfa9be83866 ("ACPI /
> PCI: Fix sysfs acpi_index and label errors").
>
> No ACPI dump accompanies the report, so the object that platform returns
> is not known. The malformed results tested below are constructed.
>
> Tested under QEMU with an SSDT that overrides _DSM on the ACPI companion
> of a PCI device. Function 0 advertises the Device Name function, and
> function 7 returns a chosen object. Nine cases, on the series and on
> v7.2-rc1, with CONFIG_KASAN=y:
>
> Function 7 returns label acpi_index
> ---------------------------------------- ---------- ----------
> Package(2){1, "TESTLABEL"} TESTLABEL 1
> Package(2){1, ""} empty 1
> Package(2){1, Buffer{"BUF", terminated}} BUF 1
> Package(2){1, Buffer{NUL}} empty 1
> Package(2){0, 0} absent 0
> Package(2){"BAD", "NAME"} absent absent
> Package(2){1, Buffer(0x40)} unterminated 32 chars 1
> valid twice, then an integer -EIO -EIO
> QEMU acpi-index=7 empty 7
>
> On v7.2-rc1 the first four and the last behave identically, so
> compliant firmware is unaffected, including the generator QEMU uses for
> stable interface names. Package(2){0, 0} reproduces the reported
> failure there, with both attributes returning -EPERM.
>
> For patch 4, the unterminated buffer case on v7.2-rc1 leaked two bytes
> of adjacent memory into the attribute, and under KASAN:
>
> BUG: KASAN: slab-out-of-bounds in utf16s_to_utf8s+0x21f/0x250
> Read of size 2 at addr ffff88800e77b088 by task cat/109
> ...
> allocated 136-byte region [ffff88800e77b000, ffff88800e77b088)
> ...
> acpi_ut_initialize_buffer+0xc7/0x190
> acpi_evaluate_object+0x694/0x920
> acpi_evaluate_dsm+0x16e/0x230
> dsm_get_label.isra.0+0x6b/0x300
>
> With the series applied the same case reads correctly and KASAN stays
> silent. The two terminated buffer cases produce no splat before or
> after. Reaching the read needs the missing terminator, not the buffer
> form as such.
Thank you!
Krzysztof
prev parent reply other threads:[~2026-08-14 9:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 7:05 [PATCH 0/4] PCI/sysfs: Fix the ACPI device name attributes Krzysztof Wilczyński
2026-08-14 7:05 ` [PATCH 1/4] PCI/sysfs: Stop reporting _DSM failures as -EPERM Krzysztof Wilczyński
2026-08-14 7:19 ` sashiko-bot
2026-08-14 9:36 ` Krzysztof Wilczyński
2026-08-14 7:05 ` [PATCH 2/4] PCI/sysfs: Decouple acpi_index from the optional device name element Krzysztof Wilczyński
2026-08-14 7:11 ` sashiko-bot
2026-08-14 7:05 ` [PATCH 3/4] PCI/sysfs: Handle a malformed _DSM result in acpi_attr_is_visible() Krzysztof Wilczyński
2026-08-14 7:19 ` sashiko-bot
2026-08-14 9:35 ` Krzysztof Wilczyński
2026-08-14 7:05 ` [PATCH 4/4] PCI/sysfs: Pass the device name length in UTF-16 code units Krzysztof Wilczyński
2026-08-14 7:14 ` sashiko-bot
2026-08-14 10:22 ` Krzysztof Wilczyński
2026-08-14 9:45 ` Krzysztof Wilczyński [this message]
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=20260814094122.GC3463973@rocinante \
--to=kwilczynski@kernel.org \
--cc=Narendra_K@dell.com \
--cc=bhelgaas@google.com \
--cc=helgaas@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=mj@ucw.cz \
--cc=rafael.j.wysocki@intel.com \
/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