From: Pierre Gondois <pierre.gondois@arm.com>
To: linux-kernel@vger.kernel.org
Cc: Ashok Raj <ashok.raj@oss.qualcomm.com>,
James Morse <james.morse@arm.com>,
Mark Brown <broonie@kernel.org>,
Pierre Gondois <pierre.gondois@arm.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>, Tony Luck <tony.luck@intel.com>,
Borislav Petkov <bp@alien8.de>, Hanjun Guo <guohanjun@huawei.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Shuai Xue <xueshuai@linux.alibaba.com>,
Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
Pawel Chmielewski <pawel.chmielewski@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>,
"Fabio M. De Francesco" <fabio.m.de.francesco@linux.intel.com>,
Breno Leitao <leitao@debian.org>,
Terry Bowman <terry.bowman@amd.com>,
Dan Williams <djbw@kernel.org>,
Morduan Zang <zhangdandan@uniontech.com>,
Ard Biesheuvel <ardb@kernel.org>,
linux-acpi@vger.kernel.org, linux-edac@vger.kernel.org,
acpica-devel@lists.linux.dev
Subject: [PATCH v5 02/13] efi/cper: Prevent buffer overflows in cper_mem_err_location()
Date: Mon, 30 Nov 2026 18:03:11 +0100 [thread overview]
Message-ID: <20261130170438.323355-3-pierre.gondois@arm.com> (raw)
In-Reply-To: <20261130170438.323355-1-pierre.gondois@arm.com>
Buffer overflows/truncated messages might happen in
cper_mem_err_location(). To prevent them, add a length parameter.
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
drivers/edac/ghes_edac.c | 2 +-
drivers/firmware/efi/cper.c | 11 +++++------
include/linux/cper.h | 2 +-
3 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
index 78eb9dccbbbe..e23a80fbdb7c 100644
--- a/drivers/edac/ghes_edac.c
+++ b/drivers/edac/ghes_edac.c
@@ -352,7 +352,7 @@ static int ghes_edac_report_mem_error(struct notifier_block *nb,
len = sizeof(e->location);
p = e->location;
- p += cper_mem_err_location(&cmem, p);
+ p += cper_mem_err_location(&cmem, p, len);
if (mem_err->validation_bits & CPER_MEM_VALID_MODULE_HANDLE) {
struct dimm_info *dimm;
diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
index 70df07a1c37d..19bc36705bad 100644
--- a/drivers/firmware/efi/cper.c
+++ b/drivers/firmware/efi/cper.c
@@ -298,15 +298,14 @@ const char *cper_mem_err_status_str(u64 status)
}
EXPORT_SYMBOL_GPL(cper_mem_err_status_str);
-int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg)
+int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg, size_t len)
{
- u32 len, n;
+ u32 n;
- if (!msg)
+ if (!msg || !len)
return 0;
n = 0;
- len = CPER_REC_LEN;
if (mem->validation_bits & CPER_MEM_VALID_NODE)
n += scnprintf(msg + n, len - n, "node:%d ", mem->node);
if (mem->validation_bits & CPER_MEM_VALID_CARD)
@@ -419,7 +418,7 @@ const char *cper_mem_err_unpack(struct trace_seq *p,
const char *ret = trace_seq_buffer_ptr(p);
char rcd_decode_str[CPER_REC_LEN];
- if (cper_mem_err_location(cmem, rcd_decode_str))
+ if (cper_mem_err_location(cmem, rcd_decode_str, sizeof(rcd_decode_str)))
trace_seq_printf(p, "%s", rcd_decode_str);
if (cper_dimm_err_location(cmem, rcd_decode_str, sizeof(rcd_decode_str)))
trace_seq_printf(p, "%s", rcd_decode_str);
@@ -451,7 +450,7 @@ static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem,
printk("%s""physical_address_mask: 0x%016llx\n",
pfx, mem->physical_addr_mask);
cper_mem_err_pack(mem, &cmem);
- if (cper_mem_err_location(&cmem, rcd_decode_str))
+ if (cper_mem_err_location(&cmem, rcd_decode_str, sizeof(rcd_decode_str)))
printk("%s%s\n", pfx, rcd_decode_str);
if (mem->validation_bits & CPER_MEM_VALID_ERROR_TYPE) {
u8 etype = mem->error_type;
diff --git a/include/linux/cper.h b/include/linux/cper.h
index c0b2c98ead45..bd3d9d3aa85d 100644
--- a/include/linux/cper.h
+++ b/include/linux/cper.h
@@ -599,7 +599,7 @@ void cper_print_proc_arm(const char *pfx,
u32 length);
void cper_print_proc_ia(const char *pfx,
const struct cper_sec_proc_ia *proc);
-int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg);
+int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg, size_t len);
int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg, size_t len);
struct acpi_hest_generic_status;
--
2.43.0
next prev parent reply other threads:[~2026-11-30 17:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 17:03 [PATCH v5 00/13] CPER: Add Memory Error Section 2 support Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 01/13] efi/cper: Prevent buffer overflows in cper_dimm_err_location() Pierre Gondois
2026-11-30 17:03 ` Pierre Gondois [this message]
2026-11-30 17:03 ` [PATCH v5 03/13] EDAC/ghes: Rationalize buffer usage in for mem other_detail helper Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 04/13] efi/cper: Use BIT_ULL() for processor and memory validation bits Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 05/13] EDAC/ghes: Extract error report initialization Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 06/13] ACPI: APEI: Extract common memory failure handling Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 07/13] efi/cper: Add Memory Error Section 2 structures Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 08/13] efi/cper: Increase memory error record buffer size Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 09/13] efi/cper: Add helpers to handle Memory Error Section 2 Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 10/13] ACPI: APEI: Handle Memory Error Section 2 records in GHES Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 11/13] EDAC/ghes: Increase memory error location and detail buffers Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 12/13] EDAC/ghes: Handle Memory Error Section 2 records Pierre Gondois
2026-11-30 17:03 ` [PATCH v5 13/13] ACPI: extlog: Add Memory Error Section 2 trace event Pierre Gondois
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=20261130170438.323355-3-pierre.gondois@arm.com \
--to=pierre.gondois@arm.com \
--cc=acpica-devel@lists.linux.dev \
--cc=ardb@kernel.org \
--cc=ashok.raj@oss.qualcomm.com \
--cc=bp@alien8.de \
--cc=broonie@kernel.org \
--cc=dave.jiang@intel.com \
--cc=djbw@kernel.org \
--cc=fabio.m.de.francesco@linux.intel.com \
--cc=guohanjun@huawei.com \
--cc=james.morse@arm.com \
--cc=jonathan.cameron@oss.qualcomm.com \
--cc=leitao@debian.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.wieczor-retman@intel.com \
--cc=mchehab@kernel.org \
--cc=pawel.chmielewski@intel.com \
--cc=rafael@kernel.org \
--cc=terry.bowman@amd.com \
--cc=tony.luck@intel.com \
--cc=xueshuai@linux.alibaba.com \
--cc=zhangdandan@uniontech.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®