Skip to contentSkip to conversation

edac: Use scnprintf() for safer buffer handling

PATCH In review Wang Haoran 3 participants 3 messages Jul 14, 2025 – Jul 15, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 edac: Use scnprintf() for safer buffer handling

snprintf() is fragile when its return value will be used to append additional data to a buffer. Use scnprintf() instead.

---
 drivers/edac/i10nm_base.c | 18 +++++++++---------
 drivers/edac/skx_common.c |  4 ++--
 2 files changed, 11 insertions(+), 11 deletions(-)
drivers/edac/i10nm_base.c +9 -9
index a3fca2567752..679d34c097c0 100644
@@ -343,7 +343,7 @@ static void show_retry_rd_err_log(struct decoded_addr *res, char *msg,
 
 	status_mask = rrl->over_mask | rrl->uc_mask | rrl->v_mask;
 
-	n = snprintf(msg, len, " retry_rd_err_log[");
+	n = scnprintf(msg, len, " retry_rd_err_log[");
 	for (i = 0; i < rrl->set_num; i++) {
 		scrub = (rrl->modes[i] == FRE_SCRUB || rrl->modes[i] == LRE_SCRUB);
 		if (scrub_err != scrub)
@@ -355,9 +355,9 @@ static void show_retry_rd_err_log(struct decoded_addr *res, char *msg,
 			log = read_imc_reg(imc, ch, offset, width);
 
 			if (width == 4)
-				n += snprintf(msg + n, len - n, "%.8llx ", log);
+				n += scnprintf(msg + n, len - n, "%.8llx ", log);
 			else
-				n += snprintf(msg + n, len - n, "%.16llx ", log);
+				n += scnprintf(msg + n, len - n, "%.16llx ", log);
 
 			/* Clear RRL status if RRL in Linux control mode. */
 			if (retry_rd_err_log == 2 && !j && (log & status_mask))
@@ -367,10 +367,10 @@ static void show_retry_rd_err_log(struct decoded_addr *res, char *msg,
 
 	/* Move back one space. */
 	n--;
-	n += snprintf(msg + n, len - n, "]");
+	n += scnprintf(msg + n, len - n, "]");
 
 	if (len - n > 0) {
-		n += snprintf(msg + n, len - n, " correrrcnt[");
+		n += scnprintf(msg + n, len - n, " correrrcnt[");
 		for (i = 0; i < rrl->cecnt_num && len - n > 0; i++) {
 			offset = rrl->cecnt_offsets[i];
 			width = rrl->cecnt_widths[i];
@@ -378,20 +378,20 @@ static void show_retry_rd_err_log(struct decoded_addr *res, char *msg,
 
 			/* CPUs {ICX,SPR} encode two counters per 4-byte CORRERRCNT register. */
 			if (res_cfg->type <= SPR) {
-				n += snprintf(msg + n, len - n, "%.4llx %.4llx ",
+				n += scnprintf(msg + n, len - n, "%.4llx %.4llx ",
 					      corr & 0xffff, corr >> 16);
 			} else {
 			/* CPUs {GNR} encode one counter per CORRERRCNT register. */
 				if (width == 4)
-					n += snprintf(msg + n, len - n, "%.8llx ", corr);
+					n += scnprintf(msg + n, len - n, "%.8llx ", corr);
 				else
-					n += snprintf(msg + n, len - n, "%.16llx ", corr);
+					n += scnprintf(msg + n, len - n, "%.16llx ", corr);
 			}
 		}
 
 		/* Move back one space. */
 		n--;
-		n += snprintf(msg + n, len - n, "]");
+		n += scnprintf(msg + n, len - n, "]");
 	}
 }
 
drivers/edac/skx_common.c +2 -2
index c9ade45c1a99..39c733dbc5b9 100644
@@ -670,12 +670,12 @@ static void skx_mce_output_error(struct mem_ctl_info *mci,
 	}
 
 	if (res->decoded_by_adxl) {
-		len = snprintf(skx_msg, MSG_SIZE, "%s%s err_code:0x%04x:0x%04x %s",
+		len = scnprintf(skx_msg, MSG_SIZE, "%s%s err_code:0x%04x:0x%04x %s",
 			 overflow ? " OVERFLOW" : "",
 			 (uncorrected_error && recoverable) ? " recoverable" : "",
 			 mscod, errcode, adxl_msg);
 	} else {
-		len = snprintf(skx_msg, MSG_SIZE,
+		len = scnprintf(skx_msg, MSG_SIZE,
 			 "%s%s err_code:0x%04x:0x%04x ProcessorSocketId:0x%x MemoryControllerId:0x%x PhysicalRankId:0x%x Row:0x%x Column:0x%x Bank:0x%x BankGroup:0x%x",
 			 overflow ? " OVERFLOW" : "",
 			 (uncorrected_error && recoverable) ? " recoverable" : "",
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 3 lines

snprintf() is fragile when its return value will be used to append additional data to a buffer. Use scnprintf() instead.

Patch looks good. But what does the "(Vul337)" in your Signed-off-by signify?

The scripts/checkpatch.pl tool complains:

CHECK: From:/Signed-off-by: email comments mismatch:
'From: Wang Haoran <[email protected]>' != 'Signed-off-by: Wang Haoran (Vul337) <[email protected]>'

May I just drop that from the Signed-off-by line? Or is it important to you?

-Tony

Tested-by Reviewed-by on v1 1/1
#2 lore raw
In reply to Wang Haoran

Hi Haoran,

Thanks for the patch.

Quoted 7 lines

From: Wang Haoran <[email protected]>
Sent: Monday, July 14, 2025 10:02 PM
To: Luck, Tony <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; Wang Haoran <[email protected]>
Subject: [PATCH] edac: Use scnprintf() for safer buffer handling

Please specify the subject with the prefix 'EDAC/{skx_common,i10nm}', to match the previous commit style, as follows:

EDAC/{skx_common,i10nm}: Use scnprintf() for safer buffer handling

Quoted 4 lines

snprintf() is fragile when its return value will be used to append additional data to a buffer. Use scnprintf() instead.

This lengthy commit message can be split into two lines for easy parsing. Please do so.
[ The tool scripts/checkpatch.pl suggests a max of 75 characters per line. ]

Quoted 1 line

I tested this patch on an Intel Granite Rapids server with error injections, and the i10nm_edac functioned well w/o any regression.

Please address Tony's comments about "Vul337" inside your SoB. Other than that: