[PATCH 2/3] x86: Use buffered_printk() in show_opcodes()

From: Tetsuo Handa
Date: Wed Jun 27 2018 - 03:30:18 EST


Since syzbot is confused by concurrent printk() messages,
this patch changes show_opcodes() to use buffered_printk().

When we start adding prefix to each line of printk() output,
syzbot will be able to handle concurrent printk() messages.

Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
---
arch/x86/kernel/dumpstack.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 666a284..c284dd0 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -97,22 +97,24 @@ void show_opcodes(u8 *rip, const char *loglvl)
u8 opcodes[OPCODE_BUFSIZE];
u8 *ip;
int i;
+ char tmpbuf[(2 + 6) + (3 * OPCODE_BUFSIZE + 2) + 2];
+ DEFINE_PRINTK_BUFFER(buf, sizeof(tmpbuf), tmpbuf);

- printk("%sCode: ", loglvl);
+ buffered_printk(&buf, "%sCode: ", loglvl);

ip = (u8 *)rip - code_prologue;
if (probe_kernel_read(opcodes, ip, OPCODE_BUFSIZE)) {
- pr_cont("Bad RIP value.\n");
+ buffered_printk(&buf, "Bad RIP value.\n");
return;
}

for (i = 0; i < OPCODE_BUFSIZE; i++, ip++) {
if (ip == rip)
- pr_cont("<%02x> ", opcodes[i]);
+ buffered_printk(&buf, "<%02x> ", opcodes[i]);
else
- pr_cont("%02x ", opcodes[i]);
+ buffered_printk(&buf, "%02x ", opcodes[i]);
}
- pr_cont("\n");
+ buffered_printk(&buf, "\n");
}

void show_ip(struct pt_regs *regs, const char *loglvl)
--
1.8.3.1