Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4529794imu; Tue, 8 Jan 2019 01:40:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN7HWXQyd/snJ+8k3+bt/yLEelf32IIHHt4x+5ORZFfC2meKKduXymYjzbovMRV8biWbHnhy X-Received: by 2002:a63:ff16:: with SMTP id k22mr900820pgi.244.1546940441626; Tue, 08 Jan 2019 01:40:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546940441; cv=none; d=google.com; s=arc-20160816; b=vuaQTeIxWiofCGAwEVxkXqMpqgaafJDcjXeCfpEDECnY5cRL6snQuyrxD8RvCYWg4o 1m8scafim7aQADyskQren2jqZZEZaFuLLKXgAsHOgaEOmClQb4LqVDALRtW+r0KWNsL6 pkE1FG7yDbWgJGpmIAXRFwpYtLGxaiYTvNVuJkt5P6I+A+x3hw7CNC+119e6aFinkE9S /g8TdegVGF5ywKKvn3OF75Wi8bLpSvC4CcQ8kCqLvPu1P8H8+hlP/v6ZxTB0N6e5PBPD pla5o6ZlubOwgLb6BdrRN2icOuqXVVgdSxgMvVJYbAeRkwIsW0SeGeZNFQoLQqJfFAWX +/YQ== 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:references:cc:to:from:subject; bh=WHXjSdEyQOqLmzitVJMTlLsI0O1bgv3wXezdxOjPVbs=; b=j4H6j8aPCEnKyV2JgRpOhMr5w5I/QowCpu7BCZ2OOkjjGJYAWwsWxVOB9SnMJx05kS RT5xYm7yFqXLkZzkBlWIlZK5CHemAS1EBWT3XHxGM/1HZvCr4yTrJfuylD37WwLF1gM5 xJ34kDckb3fLVwM+tWvMAYWhxH+gi/28dAV3POiOc3607Dmr8CjNOb2b5ZkoW7VGX6Ne ntF8qQDCqUbANX38AQU7AaQmW++6m5xFZnhYUS64q/3jlWvGV39ldkz5Dj6qZNA7iksm eVw0tSkfPCGGCux2ZPZ7WY5AOTzHlNtMOVUUjX1DUkK1i4oYDkrDovbLYlR+NQnWw8XC iDcA== 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 l7si46988220plg.390.2019.01.08.01.40.26; Tue, 08 Jan 2019 01:40:41 -0800 (PST) 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 S1728182AbfAHJhy (ORCPT + 99 others); Tue, 8 Jan 2019 04:37:54 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:62128 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727236AbfAHJhy (ORCPT ); Tue, 8 Jan 2019 04:37:54 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 43YnHM1psYz9v1Hf; Tue, 8 Jan 2019 10:37:51 +0100 (CET) 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 cA4zH0foTH8r; Tue, 8 Jan 2019 10:37:51 +0100 (CET) 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 43YnHM14gfz9v1Hc; Tue, 8 Jan 2019 10:37:51 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 21B668B7CB; Tue, 8 Jan 2019 10:37:52 +0100 (CET) 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 B9UCLNJ6RJx1; Tue, 8 Jan 2019 10:37:52 +0100 (CET) Received: from PO15451 (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 66F8D8B7C9; Tue, 8 Jan 2019 10:37:51 +0100 (CET) Subject: Re: [PATCH v2 2/2] powerpc: use probe_user_read() From: Christophe Leroy To: Michael Ellerman , Russell Currey Cc: Kees Cook , Andrew Morton , Benjamin Herrenschmidt , Paul Mackerras , Mike Rapoport , linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <0b0db24e18063076e9d9f4e376994af83da05456.1546932949.git.christophe.leroy@c-s.fr> Message-ID: <293a653c-52aa-6326-4022-73fb25590354@c-s.fr> Date: Tue, 8 Jan 2019 10:37:51 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Michael and Russell, Any idea why: - checkpatch reports missing Signed-off-by: - Snowpatch build fails on PPC64 (it seems unrelated to the patch, something wrong in lib/genalloc.c) Thanks Christophe Le 08/01/2019 à 08:37, Christophe Leroy a écrit : > Instead of opencoding, use probe_user_read() to failessly > read a user location. > > Signed-off-by: Christophe Leroy > --- > v2: Using probe_user_read() instead of probe_user_address() > > arch/powerpc/kernel/process.c | 12 +----------- > arch/powerpc/mm/fault.c | 6 +----- > arch/powerpc/perf/callchain.c | 20 +++----------------- > arch/powerpc/perf/core-book3s.c | 8 +------- > arch/powerpc/sysdev/fsl_pci.c | 10 ++++------ > 5 files changed, 10 insertions(+), 46 deletions(-) > > diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c > index ce393df243aa..6a4b59d574c2 100644 > --- a/arch/powerpc/kernel/process.c > +++ b/arch/powerpc/kernel/process.c > @@ -1298,16 +1298,6 @@ void show_user_instructions(struct pt_regs *regs) > > pc = regs->nip - (NR_INSN_TO_PRINT * 3 / 4 * sizeof(int)); > > - /* > - * Make sure the NIP points at userspace, not kernel text/data or > - * elsewhere. > - */ > - if (!__access_ok(pc, NR_INSN_TO_PRINT * sizeof(int), USER_DS)) { > - pr_info("%s[%d]: Bad NIP, not dumping instructions.\n", > - current->comm, current->pid); > - return; > - } > - > seq_buf_init(&s, buf, sizeof(buf)); > > while (n) { > @@ -1318,7 +1308,7 @@ void show_user_instructions(struct pt_regs *regs) > for (i = 0; i < 8 && n; i++, n--, pc += sizeof(int)) { > int instr; > > - if (probe_kernel_address((const void *)pc, instr)) { > + if (probe_user_read(&instr, (void __user *)pc, sizeof(instr))) { > seq_buf_printf(&s, "XXXXXXXX "); > continue; > } > diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c > index 887f11bcf330..ec74305fa330 100644 > --- a/arch/powerpc/mm/fault.c > +++ b/arch/powerpc/mm/fault.c > @@ -276,12 +276,8 @@ static bool bad_stack_expansion(struct pt_regs *regs, unsigned long address, > if ((flags & FAULT_FLAG_WRITE) && (flags & FAULT_FLAG_USER) && > access_ok(nip, sizeof(*nip))) { > unsigned int inst; > - int res; > > - pagefault_disable(); > - res = __get_user_inatomic(inst, nip); > - pagefault_enable(); > - if (!res) > + if (!probe_user_read(&inst, nip, sizeof(inst))) > return !store_updates_sp(inst); > *must_retry = true; > } > diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c > index 0af051a1974e..0680efb2237b 100644 > --- a/arch/powerpc/perf/callchain.c > +++ b/arch/powerpc/perf/callchain.c > @@ -159,12 +159,8 @@ static int read_user_stack_64(unsigned long __user *ptr, unsigned long *ret) > ((unsigned long)ptr & 7)) > return -EFAULT; > > - pagefault_disable(); > - if (!__get_user_inatomic(*ret, ptr)) { > - pagefault_enable(); > + if (!probe_user_read(ret, ptr, sizeof(*ret))) > return 0; > - } > - pagefault_enable(); > > return read_user_stack_slow(ptr, ret, 8); > } > @@ -175,12 +171,8 @@ static int read_user_stack_32(unsigned int __user *ptr, unsigned int *ret) > ((unsigned long)ptr & 3)) > return -EFAULT; > > - pagefault_disable(); > - if (!__get_user_inatomic(*ret, ptr)) { > - pagefault_enable(); > + if (!probe_user_read(ret, ptr, sizeof(*ret))) > return 0; > - } > - pagefault_enable(); > > return read_user_stack_slow(ptr, ret, 4); > } > @@ -307,17 +299,11 @@ static inline int current_is_64bit(void) > */ > static int read_user_stack_32(unsigned int __user *ptr, unsigned int *ret) > { > - int rc; > - > if ((unsigned long)ptr > TASK_SIZE - sizeof(unsigned int) || > ((unsigned long)ptr & 3)) > return -EFAULT; > > - pagefault_disable(); > - rc = __get_user_inatomic(*ret, ptr); > - pagefault_enable(); > - > - return rc; > + return probe_user_read(ret, ptr, sizeof(*ret)); > } > > static inline void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry, > diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c > index b0723002a396..4b64ddf0db68 100644 > --- a/arch/powerpc/perf/core-book3s.c > +++ b/arch/powerpc/perf/core-book3s.c > @@ -416,7 +416,6 @@ static void power_pmu_sched_task(struct perf_event_context *ctx, bool sched_in) > static __u64 power_pmu_bhrb_to(u64 addr) > { > unsigned int instr; > - int ret; > __u64 target; > > if (is_kernel_addr(addr)) { > @@ -427,13 +426,8 @@ static __u64 power_pmu_bhrb_to(u64 addr) > } > > /* Userspace: need copy instruction here then translate it */ > - pagefault_disable(); > - ret = __get_user_inatomic(instr, (unsigned int __user *)addr); > - if (ret) { > - pagefault_enable(); > + if (probe_user_read(&instr, (unsigned int __user *)addr, sizeof(instr))) > return 0; > - } > - pagefault_enable(); > > target = branch_target(&instr); > if ((!target) || (instr & BRANCH_ABSOLUTE)) > diff --git a/arch/powerpc/sysdev/fsl_pci.c b/arch/powerpc/sysdev/fsl_pci.c > index 918be816b097..c8a1b26489f5 100644 > --- a/arch/powerpc/sysdev/fsl_pci.c > +++ b/arch/powerpc/sysdev/fsl_pci.c > @@ -1068,13 +1068,11 @@ int fsl_pci_mcheck_exception(struct pt_regs *regs) > addr += mfspr(SPRN_MCAR); > > if (is_in_pci_mem_space(addr)) { > - if (user_mode(regs)) { > - pagefault_disable(); > - ret = get_user(inst, (__u32 __user *)regs->nip); > - pagefault_enable(); > - } else { > + if (user_mode(regs)) > + ret = probe_user_read(&inst, (void __user *)regs->nip, > + sizeof(inst)); > + else > ret = probe_kernel_address((void *)regs->nip, inst); > - } > > if (!ret && mcheck_handle_load(regs, inst)) { > regs->nip += 4; >