Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3562462imm; Tue, 17 Jul 2018 06:55:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfAppfLzC9Q5cyUtjEoB6YeoFEY9eVC7HWQK/8d4f+DPs1Wg6drDN2VrJRCiRUse6QHgmYk X-Received: by 2002:a17:902:bcc5:: with SMTP id o5-v6mr1744971pls.336.1531835725717; Tue, 17 Jul 2018 06:55:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531835725; cv=none; d=google.com; s=arc-20160816; b=IZUUmg5b5H7xmZiVga2aThlxcnvLyg8vrP89b6/OfaEKQ8P56DGv2183xtw7IsizUx 0m8U9wSVglj5l8pa+RmhDpOGF/3BdNuCqjKpuqb5jUSVwutP7uEMatTTWSIYH7gahAzm YK7XK2ckaiFcW9A5WA3BMTaMK+IRZfNyMaIV0EtehOMnn13YmudAgNtvtHS3ewoxBfb9 giemjXjRx/90DR0sV6IQO3khwyAf7HwqRoRK63LNyROMyEJ/2zaVLEI9qfFiQmTIif8M dSSPohPsk/2J3PRkB4P0m7Hr6isrODCnVUYc5/UTjoA+ov1Aw4V7aoIUxIeFtL3tr50k YOHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=9HTA8aBwQisWatMeq/3UJJopRExXBts4M1rGf0AKckM=; b=cjDgrtL0wxJjGN9MHgnYN9RHWm/upl4Wc7Nbx9UTIeg8ziR+ik0DMVGAUKdwjwyFGF tCMdN77jIW1Pey/0EaNtXLJzIqcbColWrVSxOpjaNr05OW3+AI/voUdneklwEwmEiqgR TSv/qIX/IKruiZlYy12hTXeSWY/yMkwITtDPLTlc/9T+hjLtX9nEUF5UkCGyaPgkoF8D fYEO0qjyYJ/dwgd9uKFJxmVBxzx+J+VJa/svrUtBbY3WpxY6Q4VoU0/iTaxc/a/Jga4Y umCrdUFz6H7dnkic52bkwuufuJpefAnTWLjXyPQaMVea/PLFr+EBVnErAhZOKiSJyC3K LzqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1-v6si820319pgv.652.2018.07.17.06.55.10; Tue, 17 Jul 2018 06:55:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731800AbeGQO04 (ORCPT + 99 others); Tue, 17 Jul 2018 10:26:56 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:43853 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731615AbeGQO0z (ORCPT ); Tue, 17 Jul 2018 10:26:55 -0400 Received: from fsav104.sakura.ne.jp (fsav104.sakura.ne.jp [27.133.134.231]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w6HDs7qw011951; Tue, 17 Jul 2018 22:54:07 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav104.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav104.sakura.ne.jp); Tue, 17 Jul 2018 22:54:07 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav104.sakura.ne.jp) Received: from [192.168.1.8] (softbank126074194044.bbtec.net [126.74.194.44]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id w6HDs0FX011917 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 17 Jul 2018 22:54:07 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: Re: [PATCH] x86: Avoid pr_cont() in show_opcodes() To: Rasmus Villemoes , Ingo Molnar Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, Tetsuo Handa , Andy Lutomirski , Borislav Petkov , Josh Poimboeuf , Linus Torvalds , Peter Zijlstra , Thomas Gleixner References: <1530943625-3288-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> <20180707111209.GA27768@gmail.com> <12409dc4-c10a-d77a-f88d-165aa92b489e@rasmusvillemoes.dk> From: Tetsuo Handa Message-ID: Date: Tue, 17 Jul 2018 22:53:55 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <12409dc4-c10a-d77a-f88d-165aa92b489e@rasmusvillemoes.dk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/07/17 18:01, Rasmus Villemoes wrote: > Why not this instead? Less stack use, less code, no intermediary > snprintfs, no pr_cont... Excellent! I didn't notice %ph extension. > Not compile-tested, probably whitespace-damaged, but you get the idea. Yes, it works well. From 96d9d4d135994a081e54d33d23f5007c53d9b5dd Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Tue, 17 Jul 2018 22:47:11 +0900 Subject: [PATCH v3] x86: Avoid pr_cont() in show_opcodes() Since syzbot is confused by concurrent printk() messages [1], this patch changes show_opcodes() to use %*ph format string. When we start adding prefix to each line of printk() output, we will be able to handle concurrent printk() messages. [1] https://syzkaller.appspot.com/text?tag=CrashReport&x=139d342c400000 Signed-off-by: Tetsuo Handa Signed-off-by: Rasmus Villemoes Cc: Borislav Petkov Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Andy Lutomirski --- arch/x86/kernel/dumpstack.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index 666a284..ffdd484 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -93,26 +93,15 @@ static void printk_stack_address(unsigned long address, int reliable, */ void show_opcodes(u8 *rip, const char *loglvl) { - unsigned int code_prologue = OPCODE_BUFSIZE * 2 / 3; + const unsigned int prologue = OPCODE_BUFSIZE * 2 / 3; u8 opcodes[OPCODE_BUFSIZE]; - u8 *ip; - int i; - printk("%sCode: ", loglvl); - - ip = (u8 *)rip - code_prologue; - if (probe_kernel_read(opcodes, ip, OPCODE_BUFSIZE)) { - pr_cont("Bad RIP value.\n"); - return; - } - - for (i = 0; i < OPCODE_BUFSIZE; i++, ip++) { - if (ip == rip) - pr_cont("<%02x> ", opcodes[i]); - else - pr_cont("%02x ", opcodes[i]); - } - pr_cont("\n"); + if (probe_kernel_read(opcodes, rip - prologue, OPCODE_BUFSIZE)) + printk("%sCode: Bad RIP value.\n", loglvl); + else + printk("%sCode: %*ph <%02x> %*ph\n", loglvl, prologue, opcodes, + opcodes[prologue], OPCODE_BUFSIZE - prologue - 1, + &opcodes[prologue + 1]); } void show_ip(struct pt_regs *regs, const char *loglvl) -- 1.8.3.1