From: Jamie Nguyen <jamien@nvidia.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>, Tony Luck <tony.luck@intel.com>,
"Punit Agrawal" <punitagrawal@gmail.com>,
<linux-acpi@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] ACPI: sysfs: Map only the requested range in acpi_data_show()
Date: Tue, 13 Oct 2026 11:07:28 -0700 [thread overview]
Message-ID: <20261013180728.957618-1-jamien@nvidia.com> (raw)
acpi_data_show() maps the whole data region on every read(), although
it copies at most count bytes and sysfs passes at most PAGE_SIZE bytes
per call. acpi_os_unmap_iomem() defers the iounmap until after an RCU
grace period, so a process reading one of these files in a loop keeps
many full-size mappings in flight.
Map only the range being read. acpi_os_map_iomem() rounds the mapping
to page boundaries, so each mapping is now at most two pages, whatever
the size of the region.
A malformed table can describe a region that wraps around the end of
the physical address space. acpi_os_map_iomem() doesn't check for that,
and its lookup of existing mappings then matches an unrelated mapping,
with or without this change. Fail reads of such a region before mapping
anything.
Assisted-by: LLM
Signed-off-by: Jamie Nguyen <jamien@nvidia.com>
---
As discussed on the BDAT v2 thread:
https://lore.kernel.org/r/CAJZ5v0ixQ_5jmrfm4mz50tZtCEq6nJt1b2eMoBdhr0f3AY+k7w@mail.gmail.com
This doesn't depend on that series and applies on its own.
Tested on an arm64 server with 4K and 64K pages, with the BDAT v2
series applied:
- The BERT and BDAT data files match /dev/mem when read whole, byte by
byte, page by page, and across page boundaries.
- Each read maps at most two pages. With 4K pages, looping full reads
of the 90754-byte BDAT file kept at most 167 MiB of vmalloc space
mapped (1740 MiB before), and looping 1-byte reads at most 355 MiB
(3090 MiB before).
- Malformed BERT tables loaded via initrd table upgrade, with regions
that wrap around the end of the physical address space, fail every
read with -EINVAL.
drivers/acpi/sysfs.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index dd4a99f09efea65..138009659a7b55f 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -419,6 +419,7 @@ static ssize_t acpi_data_show(struct file *filp, struct kobject *kobj,
struct acpi_data_attr *data_attr;
void __iomem *base;
ssize_t size;
+ u64 end;
data_attr = container_of(bin_attr, struct acpi_data_attr, attr);
size = data_attr->attr.size;
@@ -432,13 +433,17 @@ static ssize_t acpi_data_show(struct file *filp, struct kobject *kobj,
if (count > size - offset)
count = size - offset;
- base = acpi_os_map_iomem(data_attr->addr, size);
+ /* acpi_os_map_iomem() can't handle a range that wraps around */
+ if (check_add_overflow(data_attr->addr, size, &end))
+ return -EINVAL;
+
+ base = acpi_os_map_iomem(data_attr->addr + offset, count);
if (!base)
return -ENOMEM;
- memcpy_fromio(buf, base + offset, count);
+ memcpy_fromio(buf, base, count);
- acpi_os_unmap_iomem(base, size);
+ acpi_os_unmap_iomem(base, count);
return count;
}
--
2.43.0
reply other threads:[~2026-10-13 18:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261013180728.957618-1-jamien@nvidia.com \
--to=jamien@nvidia.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=punitagrawal@gmail.com \
--cc=rafael@kernel.org \
--cc=tony.luck@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
all inboxes | Powered by JetHome®