From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6F18C65BA7 for ; Fri, 5 Oct 2018 13:56:10 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E901206B2 for ; Fri, 5 Oct 2018 13:56:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E901206B2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=c-s.fr Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42RWWC0kYJzF3Mp for ; Fri, 5 Oct 2018 23:56:07 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42RWRW1XSZzF13T for ; Fri, 5 Oct 2018 23:52:55 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) by bilbo.ozlabs.org (Postfix) with ESMTP id 42RWRV6wjJz8t2L for ; Fri, 5 Oct 2018 23:52:54 +1000 (AEST) Received: by ozlabs.org (Postfix) id 42RWRV5zJzz9s8J; Fri, 5 Oct 2018 23:52:54 +1000 (AEST) Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=c-s.fr (client-ip=93.17.236.30; helo=pegase1.c-s.fr; envelope-from=christophe.leroy@c-s.fr; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42RWRT6N0Yz9s7W for ; Fri, 5 Oct 2018 23:52:53 +1000 (AEST) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 42RWRL45cyz9ttS1; Fri, 5 Oct 2018 15:52:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id TvAeHsBS6nkP; Fri, 5 Oct 2018 15:52:46 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 42RWRL3YKxz9ttRn; Fri, 5 Oct 2018 15:52:46 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 1B3A08BB9B; Fri, 5 Oct 2018 15:52:51 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id P50ly5jUTWKY; Fri, 5 Oct 2018 15:52:51 +0200 (CEST) Received: from PO15451 (po15451.idsi0.si.c-s.fr [172.25.231.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id D5FFE8BB99; Fri, 5 Oct 2018 15:52:50 +0200 (CEST) Subject: Re: [PATCH] powerpc: Don't print kernel instructions in show_user_instructions() To: Michael Ellerman , linuxppc-dev@ozlabs.org References: <20181005132123.6038-1-mpe@ellerman.id.au> From: Christophe LEROY Message-ID: <73301bba-c675-a930-83d6-5b258c07c26e@c-s.fr> Date: Fri, 5 Oct 2018 15:52:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181005132123.6038-1-mpe@ellerman.id.au> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jannh@google.com, muriloo@linux.ibm.com Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Le 05/10/2018 à 15:21, Michael Ellerman a écrit : > Recently we implemented show_user_instructions() which dumps the code > around the NIP when a user space process dies with an unhandled > signal. This was modelled on the x86 code, and we even went so far as > to implement the exact same bug, namely that if the user process > crashed with its NIP pointing into the kernel we will dump kernel text > to dmesg. eg: > > bad-bctr[2996]: segfault (11) at c000000000010000 nip c000000000010000 lr 12d0b0894 code 1 > bad-bctr[2996]: code: fbe10068 7cbe2b78 7c7f1b78 fb610048 38a10028 38810020 fb810050 7f8802a6 > bad-bctr[2996]: code: 3860001c f8010080 48242371 60000000 <7c7b1b79> 4082002c e8010080 eb610048 > > This was discovered on x86 by Jann Horn and fixed in commit > 342db04ae712 ("x86/dumpstack: Don't dump kernel memory based on usermode RIP"). > > Fix it by checking the adjusted NIP value (pc) and number of > instructions against USER_DS, and bail if we fail the check, eg: > > bad-bctr[2969]: segfault (11) at c000000000010000 nip c000000000010000 lr 107930894 code 1 > bad-bctr[2969]: Bad NIP, not dumping instructions. > > Fixes: 88b0fe175735 ("powerpc: Add show_user_instructions()") > Signed-off-by: Michael Ellerman > --- > arch/powerpc/kernel/process.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c > index 913c5725cdb2..bb6ac471a784 100644 > --- a/arch/powerpc/kernel/process.c > +++ b/arch/powerpc/kernel/process.c > @@ -1306,6 +1306,16 @@ void show_user_instructions(struct pt_regs *regs) > > pc = regs->nip - (instructions_to_print * 3 / 4 * sizeof(int)); > > + /* > + * Make sure the NIP points at userspace, not kernel text/data or > + * elsewhere. > + */ > + if (!__access_ok(pc, instructions_to_print * sizeof(int), USER_DS)) { > + pr_info("%s[%d]: Bad NIP, not dumping instructions.\n", > + current->comm, current->pid); > + return; > + } > + This will conflict with my serie https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=64611 which changes instructions_to_print to a constant. Will you merge it or do you expect me to rebase my serie ? Reviewed-by: Christophe Leroy Christophe > pr_info("%s[%d]: code: ", current->comm, current->pid); > > for (i = 0; i < instructions_to_print; i++) { >