From patchwork Wed Jan 16 16:59:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10766429 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 6253F746 for ; Wed, 16 Jan 2019 16:59:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EA892F0F1 for ; Wed, 16 Jan 2019 16:59:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 426EA2F1AE; Wed, 16 Jan 2019 16:59:32 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 C178E2F0F1 for ; Wed, 16 Jan 2019 16:59:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE6D48E0004; Wed, 16 Jan 2019 11:59:30 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C979B8E0002; Wed, 16 Jan 2019 11:59:30 -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 BAE158E0004; Wed, 16 Jan 2019 11:59:30 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id 657EC8E0002 for ; Wed, 16 Jan 2019 11:59:30 -0500 (EST) Received: by mail-wm1-f72.google.com with SMTP id y85so1474181wmc.7 for ; Wed, 16 Jan 2019 08:59:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:from:subject:to:cc :date; bh=VClA1koYN/8UB1kz/FeELweQ5cMzF1pBl+1hJ48rHrs=; b=uW/0ZUj015FXDiqIbZ70DOB1082JidwZNXBAub3cus2rwXOCGgogyftNgHeLtN3/jg 4Mo8fsie+8vtABaVS1CsC8W/x561vqPQABrSusifwkydXalL0rmIN0Dzhd806PZDvtbI 84zLJ/9H+6FEqUa8cjwXG+ZCcbnTJWINWcuCbZzLpmpwLKZYpIfjXAUiG5m5ILCGPriU 7wL8oAnsdavWOqvUbdprALcSLAvkZqL8RZdeTX39NLLIhEtSgglh+VgM9fcx28mvLrbc L2C4078FJARrW1vmIB9DcLe9u7W3aTmZkHDiP2MtrI3rnbpARdYkVK6cn2A/xMUwvt0o 7L0Q== X-Gm-Message-State: AJcUukdPqGw8phBXXNeEKNHApf1j/nkTfKj9OkE1wYoTcPNSJhBbH4Lw QI5gcSw/T6+irmr+uDfk9DmZgPVwdj70WvqjcA78NaK8ILJgrh5txU6wPXhXTvKIaDCQFRNVyZI 4tgxQvcqcE9HpWB2cWauvX6iv8W2WYCY7FzNy8Zx3NCTP4No81GfMKgFXA4zF3wCZIQ== X-Received: by 2002:a1c:aad2:: with SMTP id t201mr8120975wme.148.1547657969790; Wed, 16 Jan 2019 08:59:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN61eSM2bACF2VXKSq2QOd/yPgic6bKrLQTQb/ILCnwPd4MCSzqCUp5Zqlkw80/nsCzfIoF+ X-Received: by 2002:a1c:aad2:: with SMTP id t201mr8120917wme.148.1547657968728; Wed, 16 Jan 2019 08:59:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547657968; cv=none; d=google.com; s=arc-20160816; b=dDriO016KWn7skPaKd+qOhKZAHZe8jUFLPtm7AndCqscGdOLBwh595RG4mFdq2YXaM IylA2dOjMeNsOMKIDmiDor/Z1o2zMz2MepIhzPcZmhnUfzA3wdJOfHchvLCvG2rA/peo PsIefMvU3Ft2r7gPShhZLdGfklXqjv+qyc9TJMkSOF6boK69MjMbqvHgyITgQ5t/Rt4l 0ScyqjRp+ouojFFpoMloi7IV+QKi9qsnQ4ISWKJUNMyCSgOTFLXEBAN+Duw2/s/Tx3rz uov5EOJ3DtgO9we02PY5eQGE15dUDTRLu8cduaPwWnpH+FU/wtzHBH530Lwo0D7KNbyf S7Aw== 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:dkim-signature; bh=VClA1koYN/8UB1kz/FeELweQ5cMzF1pBl+1hJ48rHrs=; b=HejQRGHgwngnpFeLMZbOzqIx45Z4A5FKGkLWtofjBVyRR+2FdvozazRI953wxvZsIt ZUmSSzUGbcNsi092gRppkx8r8VY1B4jyVMPcS4UvX/ZSfnNQNMsEwAkltec4BKGyOw4+ kCuhPMe4BWrMuBMAuWCVPw/HiG99S7HSprpySeotKi/UvDBRPr1AjTlCM67v8w/bMkSk d7FxOrHKx5Ll9eD1LgwVUNXTukIuyUAtunVkjSqaDgVq0OorTWKjop6kk+wc9BNwG46q FSaHdpule1ib92LctH4BC0qo/zdhru8Acc0Uv0URUhbBKfB9zEESPjaDPNapWt9XeIEE noig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=eLvAt7Bq; 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 g1si55416782wrv.204.2019.01.16.08.59.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 08:59:28 -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; dkim=pass header.i=@c-s.fr header.s=mail header.b=eLvAt7Bq; 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 43ftjB4Kcjz9vBmN; Wed, 16 Jan 2019 17:59:26 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=eLvAt7Bq; dkim-adsp=pass; dkim-atps=neutral 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 1y33t7ubUemJ; Wed, 16 Jan 2019 17:59:26 +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 43ftjB3GBBz9vBmJ; Wed, 16 Jan 2019 17:59:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1547657966; bh=VClA1koYN/8UB1kz/FeELweQ5cMzF1pBl+1hJ48rHrs=; h=From:Subject:To:Cc:Date:From; b=eLvAt7BqtYsxN7kNzsTn3yCzQeJgXW/pvrjCRLWQQ+Rx6by4eR4OaEJxaMf4xrbET FQPUhr3MjsHuIZLRxf2Pz0xRhQ1V3U3082He6sRkmK9YzwfMpNOArgKFNnb2OSCtzl KimuUtlrI8GCG37yM7y6uPutILgDbNlGXG28AO5Q= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0E9D68B84C; Wed, 16 Jan 2019 17:59:28 +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 2W1rUcGyGM6V; Wed, 16 Jan 2019 17:59:27 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C98BD8B848; Wed, 16 Jan 2019 17:59:27 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 6A6F37187C; Wed, 16 Jan 2019 16:59:27 +0000 (UTC) Message-Id: <39fb6c5a191025378676492e140dc012915ecaeb.1547652372.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v3 1/2] mm: add probe_user_read() To: Kees Cook , Andrew Morton , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Mike Rapoport Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org Date: Wed, 16 Jan 2019 16:59:27 +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 powerpc code, 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(), this patch adds probe_user_read(). probe_user_read() does the same as probe_kernel_read() but first checks that it is really a user address. The patch defines this function as a static inline so the "size" variable can be examined for const-ness by the check_object_size() in __copy_from_user_inatomic() Signed-off-by: Christophe Leroy Acked-by: Murilo Opsfelder Araujo --- v3: Moved 'Returns:" comment after description. Explained in the commit log why the function is defined static inline v2: Added "Returns:" comment and removed probe_user_address() include/linux/uaccess.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 37b226e8df13..ef99edd63da3 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -263,6 +263,40 @@ 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. + * + * Returns: 0 on success, -EFAULT on error. + */ + +#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(src, size)) + return -EFAULT; + + pagefault_disable(); + ret = __copy_from_user_inatomic(dst, src, size); + pagefault_enable(); + + return ret ? -EFAULT : 0; +} +#endif + #ifndef user_access_begin #define user_access_begin(ptr,len) access_ok(ptr, len) #define user_access_end() do { } while (0) From patchwork Wed Jan 16 16:59:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 10766431 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 A269E746 for ; Wed, 16 Jan 2019 16:59:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EDCF2F199 for ; Wed, 16 Jan 2019 16:59:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82A7B2F1AE; Wed, 16 Jan 2019 16:59:35 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 514E22F199 for ; Wed, 16 Jan 2019 16:59:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B16038E0005; Wed, 16 Jan 2019 11:59:32 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A9ECD8E0002; Wed, 16 Jan 2019 11:59:32 -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 963968E0005; Wed, 16 Jan 2019 11:59:32 -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 3F3168E0002 for ; Wed, 16 Jan 2019 11:59:32 -0500 (EST) Received: by mail-wm1-f70.google.com with SMTP id b186so1511130wmc.8 for ; Wed, 16 Jan 2019 08:59:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:message-id:in-reply-to:references :from:subject:to:cc:date; bh=VS0H/GV7FY7nPJrZuJkENuwqd89d98HCiR9a0gQHbK0=; b=BRcYHqOiSL4cpucKmNvBWDBsgwsfXL6OhidltuYYpo+Jn3Ww+6AV7Ckd0aRiMobn8z 4RE41Mn+fXu77DmBXGRl5MwndLK+qw1D6ihduTQsDtcZoBIF141Thdft4KS2oNfQ41dU NRKa2UfqMF80jZReRPF6gNUJKwTK8aupRTs5pYKPASkYI3T4ouvXIKFJvm5hbCHJUism kNm9UcwJg3jfLltAmwDKUneCgavL0N6/FpWHFnyecbjT1bq7Ts/GdyRNGqwreBDKL54K bj8p82QEM74Rw5XXQecD8vyzLcqqIt+EKQ9JDUvNIfH8+5ACh/InCYXAOYHhZS/A+Gf3 PKcQ== X-Gm-Message-State: AJcUukefl6z3aTLSmCv3Q68MaBteZKWuXAAl5fIriwcBXd9gTG0Ximce gOIHoU/WGgzF+Dz+hU8T0nNM1wZo0rQOviESuU3fXLtXdsWyVXEC6fuzcPi2jJw5+Iw/shWi7OO vt/489v4rPXVmKt5eQe4nZ1lUwzRxAwaBVxo4VRaWGGrPUJLwwQ0liBEcYdVqRGzw1Q== X-Received: by 2002:a5d:67cf:: with SMTP id n15mr8106030wrw.211.1547657971684; Wed, 16 Jan 2019 08:59:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN6XLhm9Bd1j3XVYxn5j7Ppu9i3c0F9smakLKJSaVUPc+3bQKD/+ToxvKSgnMAoyl2b4P1Lf X-Received: by 2002:a5d:67cf:: with SMTP id n15mr8105969wrw.211.1547657970681; Wed, 16 Jan 2019 08:59:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547657970; cv=none; d=google.com; s=arc-20160816; b=oIIq5PKMTimT5xGnJ571G47WqNMJ6l2yUVsCenwY7qWmwX/U7kvgm2qE07/WwDiDgf bDiwgXnVoAMwl4ZdN3W/zA++g4Onqr+R4LT9WT16YP51UdRSQ3NFJ/v9xN1ccp5PAzd4 +Z566Q+oODgx/HaRbe3XjbjS+bOp3n5iQC8KBuOz8MAnIuhp7B4OHdrPqXExAnnaWVRi FLxTHE0K7TUsvD1QMp6ZFaGFM6JKY0ffmfq0Sv3oRt6tgfx+7ZH777MUQYXvub7L16NK yY0GynWGM3S0YNGSmGNqxWFRRsDkQ8giQst1k85gIbi7fPEfexwHbzBAXJbn156GlyLK +5Rw== 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 :dkim-signature; bh=VS0H/GV7FY7nPJrZuJkENuwqd89d98HCiR9a0gQHbK0=; b=hrieMsvYSYXUeGXgoj1kr5IaHuOxglogm/s/35mCvBLXpOdBsIqcra1orjI9ARC203 74mw8w3aioAauMkiJLjtAzpnQlA0nWvEW2kSRtMqQ3Ltw/P8XjlRnrjMSGpsWGdkJ6Rn a3kpXpRVIrTMDoZiRV7EiHuspitLrZcvQv8XrulL7/7BV3mmZHiUyjNAQsQSh7JMV+ga GvUnIzrBorIA21K0+RLw29CaaRZ6NsvS8iat6KGtIT1KyiHcRXwuJxLR3xKxlSgOQaRy G3ws9wGeJStMYcCsGJG4VNrkz0GRoK4kiuzNdryLncFE3nXBFi2wkozvmzr6xrr8k5R8 /tjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=Khwl8Sdf; 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 x16si54136603wrn.206.2019.01.16.08.59.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 08:59:30 -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; dkim=pass header.i=@c-s.fr header.s=mail header.b=Khwl8Sdf; 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 43ftjD3zfTz9vBmT; Wed, 16 Jan 2019 17:59:28 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=Khwl8Sdf; dkim-adsp=pass; dkim-atps=neutral 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 wQTomXkCom_3; Wed, 16 Jan 2019 17:59:28 +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 43ftjD2XzQz9vBmJ; Wed, 16 Jan 2019 17:59:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1547657968; bh=VS0H/GV7FY7nPJrZuJkENuwqd89d98HCiR9a0gQHbK0=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=Khwl8SdfOqxJHr3TpI4Ab+XN4eSlHofcgIrMBmybK/gWc5pwMocRAVp83IpnJPZq3 znvEFmndmjTzi87TTQhg7VgK93YoP8wDLDM4QWLw/eSeC7Gu/IgnaHDlp7sXyrWc2G ttiL9QqBkoagXDpe0x05dR233sXigz7frh3vgV+I= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CD6738B84F; Wed, 16 Jan 2019 17:59:29 +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 vMtuhXty79AC; Wed, 16 Jan 2019 17:59:29 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8300D8B84C; Wed, 16 Jan 2019 17:59:29 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 4C18A7187C; Wed, 16 Jan 2019 16:59:29 +0000 (UTC) Message-Id: In-Reply-To: <39fb6c5a191025378676492e140dc012915ecaeb.1547652372.git.christophe.leroy@c-s.fr> References: <39fb6c5a191025378676492e140dc012915ecaeb.1547652372.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v3 2/2] powerpc: use probe_user_read() To: Kees Cook , Andrew Morton , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Mike Rapoport Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org Date: Wed, 16 Jan 2019 16:59:29 +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() to failessly read a user location. Signed-off-by: Christophe Leroy Acked-by: Michael Ellerman --- v3: No change 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;