Skip to contentSkip to conversation

signal: Use %*ph for printing hexdump of a small buffer

PATCH Superseded Andy Shevchenko 2 participants 2 messages Jun 12, 2023 – Jun 13, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 signal: Use %*ph for printing hexdump of a small buffer

The kernel already has a helper to print a hexdump of a small buffer via pointer extension. Use that instead of open coded variant.

In long term it helps to kill pr_cont() or at least narrow down its use.

---
 kernel/signal.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
kernel/signal.c +5 -6
index b5370fe5c198..6be2df76f0b4 100644
@@ -1259,18 +1259,17 @@ static void print_fatal_signal(int signr)
 	pr_info("potentially unexpected fatal signal %d.\n", signr);
 
 #if defined(__i386__) && !defined(__arch_um__)
-	pr_info("code at %08lx: ", regs->ip);
 	{
+		unsigned char insn[16];
 		int i;
+
 		for (i = 0; i < 16; i++) {
-			unsigned char insn;
-
-			if (get_user(insn, (unsigned char *)(regs->ip + i)))
+			if (get_user(insn[i], (unsigned char __user *)(regs->ip + i)))
 				break;
-			pr_cont("%02x ", insn);
 		}
+
+		pr_info("code at %08lx: %*ph\n", regs->ip, i, insn);
 	}
-	pr_cont("\n");
 #endif
 	preempt_disable();
 	show_regs(regs);
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw

From: Andy Shevchenko

Quoted 25 lines

Sent: 12 June 2023 23:04

The kernel already has a helper to print a hexdump of a small buffer via pointer extension. Use that instead of open coded variant.

In long term it helps to kill pr_cont() or at least narrow down its use.

---
 kernel/signal.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
kernel/signal.c +1 -1
index b5370fe5c198..6be2df76f0b4 100644
@@ -1259,18 +1259,17 @@ static void print_fatal_signal(int signr)
 	pr_info("potentially unexpected fatal signal %d.\n", signr);
 
 #if defined(__i386__) && !defined(__arch_um__)
-	pr_info("code at %08lx: ", regs->ip);
 	{
+		unsigned char insn[16];

kernel/signal.c static void print_fatal_signal(int signr) · line 1269

Quoted 10 lines
kernel/signal.c +2 -4
 		int i;
+
 		for (i = 0; i < 16; i++) {
-			unsigned char insn;
-
-			if (get_user(insn, (unsigned char *)(regs->ip + i)))
+			if (get_user(insn[i], (unsigned char __user *)(regs->ip + i)))
 				break;
-			pr_cont("%02x ", insn);
 		}

Isn't that just:

		i = 16 - copy_from_user(insn, (unsigned char __user *)regs->ip, 16);

(the 16 should be sizeof (insn))

David

Quoted 9 lines
kernel/signal.c +2 -2
+
+		pr_info("code at %08lx: %*ph\n", regs->ip, i, insn);
 	}
-	pr_cont("\n");
 #endif
 	preempt_disable();
 	show_regs(regs);
--

2.40.0.1.gaa8946217a0b

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)