From patchwork Mon Dec 3 17:06:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10710081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A56B14BD for ; Mon, 3 Dec 2018 17:06:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 632202A6BB for ; Mon, 3 Dec 2018 17:06:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5734D2AD12; Mon, 3 Dec 2018 17:06:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97D292A6BB for ; Mon, 3 Dec 2018 17:06:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7ED136B6A4E; Mon, 3 Dec 2018 12:06:46 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 79CCA6B6A4F; Mon, 3 Dec 2018 12:06:46 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68C7A6B6A50; Mon, 3 Dec 2018 12:06:46 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by kanga.kvack.org (Postfix) with ESMTP id 0DB906B6A4E for ; Mon, 3 Dec 2018 12:06:46 -0500 (EST) Received: by mail-wm1-f69.google.com with SMTP id t62-v6so4538766wmg.6 for ; Mon, 03 Dec 2018 09:06:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:message-id :from:subject:to:cc:date; bh=f6E/TiWEYMLxyLhMFHwh9hK9B/RVSByGvDVXegjlwLM=; b=DhR7CEeZlFo+z8AdiNMH1BImb4DdgWGkX7BCP0LELo/49qIEZFLMutFK24hHDtj2KH aig2uY6ZGfUdSQLm2dzDWqAY0yzxVcmKCG43ZEFZ+iLwX5qd0YeJTM4hUnZ+ngzpFVqR 2wI/LqEPnv/t01SG1aVQf9I/H4TbjonsFTsZoX+orkZaRocGWciugj4ml23dyoSKNvXG JbvhO5NDPU2HAtPw9bsv10zWFLhZYjBHVuQxQZ9izhIxkCLqom2z81IutZKc2G8abIYK +fCCuZULHV7YOZFDBM2HPorDgEqrrjo8qV1cMd0z/nXXChokxGpCq2eOcJl+n0gzCpII hSIA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr X-Gm-Message-State: AA+aEWYcsxlxpAd+EXiPXCX0TGgIolQEx6y5KFt6Zz73iH/iiZ1qE4ak WNzkvNt4z246xt6JQqv5qX90D/M1fx7G0sr+mnwNcAbATm0ZOOCfLCLmHB8s41cBpEAQ/TFDDor RdOd+BWIBMu79GuyDtU71BviyNJd9w2NO0T3JbEsSamoXXy4uMYYs5dEiV9LeFTGRqA== X-Received: by 2002:a1c:b0f:: with SMTP id 15mr9384522wml.128.1543856805546; Mon, 03 Dec 2018 09:06:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/VMLejLq8vs0fv4ntKJH4bq76nHTg1R+zfVwZkEbLd/TJld2yDs01cELuQnLzDtP6UCUMAX X-Received: by 2002:a1c:b0f:: with SMTP id 15mr9384462wml.128.1543856804516; Mon, 03 Dec 2018 09:06:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543856804; cv=none; d=google.com; s=arc-20160816; b=yHFxU2i22aV/1HgljJ6zoaC7QG24acTuVDAslVvSc1HW1XI6rDzUplNsY1PTMMADle oY/h9YKq1SPsYW9oxj1K4ANudU3m3DwldO2znIalzrv2pqM6UjFcHqzA2vXTYMsLUk0v n9hSbhboasM+txRGKd34iJEepTBk9whgptKt5aGJ6uV6xH6kUeHcbhIeOFggHmsIotOf /epeF8n/a2fxJVL2FVMFieRuHa2jBFHQfnvmZJL71AM4yYwtUmwD7OW0sdpTOiEnnPGO ozTuDBO/AtE9DINuKc1HGBR22Sz5LcbvnOvcM6aOsra2bBQZwC2fzEM+PPjN3xe2XsoH KoAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:message-id; bh=f6E/TiWEYMLxyLhMFHwh9hK9B/RVSByGvDVXegjlwLM=; b=0Z47FfSYkzvPG+1ZWtkIBP0iGawbuZe01OLFmN+KknLpX9dzQKxnBAjXLuWYge31xf mt1z5mn9p+4Pk51H7HB94gi1lg11Kyzg9X7LA5cUOlaypbbRbTLKS8uRllOC6MT1LmUT nkZ/l3PhZBnnc4ATygGwGV9ai9cTS2QtU9rsq8fB7Di2EYcuq5tip9LvC64rC3bnL+1G xHVgqxZhFQOcWwvszOBFlisEn6Jaz7G0wuwST6Xw8BXjS+67qaO2oqWeQYbB0wzFjKcF x+T1cxs3Fhd3zA4eTjRHpzXieRm0/7GWkgrj2cYoF045WV0zFmG8MLFnKGDnzdz8mwf9 WgTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id x12si11016001wrt.114.2018.12.03.09.06.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 09:06:44 -0800 (PST) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 437rxr4Hkpz9tyyG; Mon, 3 Dec 2018 18:06:40 +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 SWiAnz58A0pf; Mon, 3 Dec 2018 18:06:40 +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 437rxr3f1rz9tyyF; Mon, 3 Dec 2018 18:06:40 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C54FA8B7B8; Mon, 3 Dec 2018 18:06:43 +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 kV2y1tG9fbml; Mon, 3 Dec 2018 18:06:43 +0100 (CET) Received: from po14163vm.idsi0.si.c-s.fr (unknown [192.168.232.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6704A8B79E; Mon, 3 Dec 2018 18:06:43 +0100 (CET) Received: by po14163vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 0508F6BEF5; Mon, 3 Dec 2018 17:06:42 +0000 (UTC) Message-Id: From: Christophe Leroy Subject: [PATCH 1/2] mm: add probe_user_read() and probe_user_address() To: Kees Cook , Andrew Morton , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org Date: Mon, 3 Dec 2018 17:06:42 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In the powerpc, there are several places implementing safe access to user data. This is sometimes implemented using probe_kernel_address() with additional access_ok() verification, sometimes with get_user() enclosed in a pagefault_disable()/enable() pair, etc... : show_user_instructions() bad_stack_expansion() p9_hmi_special_emu() fsl_pci_mcheck_exception() read_user_stack_64() read_user_stack_32() on PPC64 read_user_stack_32() on PPC32 power_pmu_bhrb_to() In the same spirit as probe_kernel_read() and probe_kernel_address(), this patch adds probe_user_read() and probe_user_address(). probe_user_read() does the same as probe_kernel_read() but first checks that it is really a user address. probe_user_address() is a shortcut to probe_user_read() Signed-off-by: Christophe Leroy --- Changes since RFC: Made a static inline function instead of weak function as recommended by Kees. include/linux/uaccess.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index efe79c1cdd47..83ea8aefca75 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -266,6 +266,48 @@ extern long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count); #define probe_kernel_address(addr, retval) \ probe_kernel_read(&retval, addr, sizeof(retval)) +/** + * probe_user_read(): safely attempt to read from a user location + * @dst: pointer to the buffer that shall take the data + * @src: address to read from + * @size: size of the data chunk + * + * Safely read from address @src to the buffer at @dst. If a kernel fault + * happens, handle that and return -EFAULT. + * + * We ensure that the copy_from_user is executed in atomic context so that + * do_page_fault() doesn't attempt to take mmap_sem. This makes + * probe_user_read() suitable for use within regions where the caller + * already holds mmap_sem, or other locks which nest inside mmap_sem. + */ + +#ifndef probe_user_read +static __always_inline long probe_user_read(void *dst, const void __user *src, + size_t size) +{ + long ret; + + if (!access_ok(VERIFY_READ, src, size)) + return -EFAULT; + + pagefault_disable(); + ret = __copy_from_user_inatomic(dst, src, size); + pagefault_enable(); + + return ret ? -EFAULT : 0; +} +#endif + +/** + * probe_user_address(): safely attempt to read from a user location + * @addr: address to read from + * @retval: read into this variable + * + * Returns 0 on success, or -EFAULT. + */ +#define probe_user_address(addr, retval) \ + probe_user_read(&(retval), addr, sizeof(retval)) + #ifndef user_access_begin #define user_access_begin() do { } while (0) #define user_access_end() do { } while (0) From patchwork Mon Dec 3 17:06:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10710083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B59D61057 for ; Mon, 3 Dec 2018 17:06:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A02962A6BB for ; Mon, 3 Dec 2018 17:06:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9443C2AD12; Mon, 3 Dec 2018 17:06:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0556D2A6BB for ; Mon, 3 Dec 2018 17:06:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30C996B6A50; Mon, 3 Dec 2018 12:06:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2948B6B6A51; Mon, 3 Dec 2018 12:06:48 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15E9B6B6A52; Mon, 3 Dec 2018 12:06:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by kanga.kvack.org (Postfix) with ESMTP id B0FF06B6A50 for ; Mon, 3 Dec 2018 12:06:47 -0500 (EST) Received: by mail-wm1-f70.google.com with SMTP id g3so4049601wmf.1 for ; Mon, 03 Dec 2018 09:06:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:message-id :in-reply-to:references:from:subject:to:cc:date; bh=LejFDF4nG+/qx9uTE6mowzcEq870wjpYoa4MDBhL1ro=; b=QKhTVlIzHSITQFwzIB0d6kVZxGgQL3jMrkfHqcf3S6FLJSXfntMH18eQ/qbvI8dNjc scuS9SUmdXlHPRs3OKbqHeNpNiWHFAiTs19Cnu4/+kkKszLwk2+jsvAFLE9UDXnjZZV+ XpiqwtkI5YK9jDmZ0lq/gTDTzCUTrr9zGZtkzzXXInVvktPlw61hzifeYpf55SYeJlbf XihHBMxbJ5aDOxTsX1jBCPhktx7RWbP3rlgtco9GaeAN8KXSzyiDmDce+sS2kBSvBJK/ JVaHXeOk2oYMFvsh7gSUT8jFiRQXkecwzMgsBGx/crqJrKxg5S5hG52AVVBnZvwSzp5V dlWQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr X-Gm-Message-State: AA+aEWYkZxEocIqI0gi+zyraA99aXexLHEGJRIWuKDTW8J5AEiKZtBZT 0m6xQpaYiTjRb0WGWak9Nf7/3PXfoEt/3klRN7HdQNn1C9lDAEuIqJ6FV6VaVKdCF7KabJQd73P yo8N1r1L7rJuwo1l99Nvu81LY7JxkDnw3KBwAEVWqdceJJo5KR7TdIhEoODAZBxkFCw== X-Received: by 2002:a1c:650b:: with SMTP id z11mr9201187wmb.23.1543856807181; Mon, 03 Dec 2018 09:06:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/U8HmIHSsiQcOJsV/FgAElEP8TL9/dvpqMB6v6KoSatrn2qDcJsml8E0lrYU1NtBYRqK+a3 X-Received: by 2002:a1c:650b:: with SMTP id z11mr9201115wmb.23.1543856806104; Mon, 03 Dec 2018 09:06:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543856806; cv=none; d=google.com; s=arc-20160816; b=jYIgMMb184BGtujc+TvbaWE48E+A9dMPygjY7E0uIZP6nFJUoUNLBr6w0bsJ4yJFZS EhOmYpqcnyyJ1mqxI9AutvMDAgbC9kka9NlQcGxPeaSVxj2aRtTzCURKl8DUrr3mqt9a tUXXe4fZpBTMN+pcuB2HFbuqEDqsSg+VMaBejl6cVGK9h+miPlYNHpPueqRyGkifBqtX 9Se4uOqNHGtyygF8oCbl8OHI0m1HvGWo4pW5O9Y2fGzPpipvncmN/cAh61bQSlBVp3fh axlB0NZ8w34YXD4qt1ggsuglU8CBBS9tHG4nFlLYdquouYwqv7nBJXtMPPMrJSAI4A5o LYxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:cc:to:subject:from:references:in-reply-to:message-id; bh=LejFDF4nG+/qx9uTE6mowzcEq870wjpYoa4MDBhL1ro=; b=FEVfk3ttBWRJTWC+olUi9gIuabDU1TGOwPhZD3iiqGtWx19J8WeqmfE6+Gkqk6fSy0 wKuNZWV7rJzE9ku2EH9BXZpthGFDW/2JHIYl8KoP7hTHID+EBZkq5x49oodowdoK9n33 q9Z3sbVrQYFBh+LLN9srPUNnNdZM/40mY7d9KJvDc1kLovywfQgGdWLxwWkv0DmIhXU2 cNw7IrjNS1Ndjmm9YLIYADV+H+ONDzb9rift3TUIa6OQRVTlf4QDrPXtHZg3QlMGAAW5 i//s7VEX8/Va9d/KJy54ln4OGVCzFjKOeTXc04vRASbhdqjTnoXo13OQ4rXmLAGvhMhP S2Dw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr. [93.17.236.30]) by mx.google.com with ESMTPS id z124si6309561wmc.102.2018.12.03.09.06.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 09:06:46 -0800 (PST) Received-SPF: pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) client-ip=93.17.236.30; Authentication-Results: mx.google.com; spf=pass (google.com: domain of christophe.leroy@c-s.fr designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@c-s.fr Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 437rxt21XYz9tyyH; Mon, 3 Dec 2018 18:06:42 +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 WsU5Mv8NEi72; Mon, 3 Dec 2018 18:06:42 +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 437rxt1XWHz9tyyF; Mon, 3 Dec 2018 18:06:42 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8EEC18B7B8; Mon, 3 Dec 2018 18:06:45 +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 NZNpV8gFRLuv; Mon, 3 Dec 2018 18:06:45 +0100 (CET) Received: from po14163vm.idsi0.si.c-s.fr (unknown [192.168.232.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 424A28B79E; Mon, 3 Dec 2018 18:06:45 +0100 (CET) Received: by po14163vm.idsi0.si.c-s.fr (Postfix, from userid 0) id F15476BEF5; Mon, 3 Dec 2018 17:06:44 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH 2/2] powerpc: use probe_user_read() and probe_user_address() To: Kees Cook , Andrew Morton , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org Date: Mon, 3 Dec 2018 17:06:44 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Instead of opencoding, use probe_user_read() and probe_user_address() to failessly read a user location. Signed-off-by: Christophe Leroy --- 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 | 9 +++------ 5 files changed, 9 insertions(+), 46 deletions(-) diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 96f34730010f..b77a2b4007e5 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_address((const void *)pc, instr)) { seq_buf_printf(&s, "XXXXXXXX "); continue; } diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 1697e903bbf2..a87a2d2e7a8b 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -274,12 +274,8 @@ static bool bad_stack_expansion(struct pt_regs *regs, unsigned long address, if ((flags & FAULT_FLAG_WRITE) && (flags & FAULT_FLAG_USER) && access_ok(VERIFY_READ, nip, sizeof(*nip))) { unsigned int inst; - int res; - pagefault_disable(); - res = __get_user_inatomic(inst, nip); - pagefault_enable(); - if (!res) + if (!probe_user_address(nip, 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..efe518c4e8c7 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_address(ptr, *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_address(ptr, *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_address(ptr, *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 81f8a0c838ae..25b28aa499b9 100644 --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -407,7 +407,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)) { @@ -418,13 +417,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_address((unsigned int __user *)addr, 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..b8e2349910b7 100644 --- a/arch/powerpc/sysdev/fsl_pci.c +++ b/arch/powerpc/sysdev/fsl_pci.c @@ -1068,13 +1068,10 @@ 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_address((void *)regs->nip, inst); + else ret = probe_kernel_address((void *)regs->nip, inst); - } if (!ret && mcheck_handle_load(regs, inst)) { regs->nip += 4;