Received: by 10.192.165.148 with SMTP id m20csp4745933imm; Tue, 24 Apr 2018 07:47:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/jn3IrWRI6/rMf5yYkdcCgu51juVGqLh5XDf+VUEZMCXxzaFYrQouB/pUC4+/nSPVy7v8H X-Received: by 10.99.116.74 with SMTP id e10mr20391888pgn.169.1524581259002; Tue, 24 Apr 2018 07:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524581258; cv=none; d=google.com; s=arc-20160816; b=OcqDsckKuFFEXNjjJ+NCRVZHZcnkgkJAHpDjUods0RJ2WDXYT5FkN79cwln3AcklEG UWRoQ7xEtyruQNVhnKa2QlvjSZ2KKA6dI5zZM08cL1Pgf970uVtaTaGF8sxQWkaZCrXx 9lIxt998yylo2RI1q5SeSx3BVIoYTiyZfM4T53HXMZmt1OeNgoFOY6eYAizVNo+fwbrj kwvBGNYwRY/D7MNR1IDVlH3nUj9aiVnNVKWeUfwfr6rpjYukjNw5RXikquuvU4wq1a0+ oMx5V3o+Zio8mp1wWfPqOWYHCWNXBkeDtJ6wJoJMQvC3fTMbwrBAwFoLivjY/KUPz425 fzQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=CnNrPi0PRxvuskkyxnoWq69868YaFdnUxYS5rswuHKI=; b=K5PThsOOyYLe8rlpe7rj43D77tV//q0DRYJvhxQM2y9FUBhGpubDpdHgHfpZlCBGif u77B3x24rK0U+7ZSJrurOUaU6CKKc24UKC8PSO37zmKTDvkBvNTUCaVFqkPcPN2PfmnD CPb5yzzHPBIusp4dXxmYJ2FlyYwCgqvl9nORw3SDjUK55xeWb6xoUOrxXSgwLn1Hb1Fl OPbdV1H3/blbjJXldBriBIr6PSVVp/YAd+mT8lzvctEaBMPPsu0U8HCDhPDMPP2rUBfs f6GZrvA6MTstDeBSI8+SrW+78Hehqv+MMvUMHz0ghqXzQW4Wg8j79OxUxVGJtLY3HxA0 HClQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=LgJ6z5dG; 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 y6si11290719pgv.520.2018.04.24.07.47.24; Tue, 24 Apr 2018 07:47:38 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=LgJ6z5dG; 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 S1751346AbeDXOqP (ORCPT + 99 others); Tue, 24 Apr 2018 10:46:15 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:44502 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750739AbeDXOqM (ORCPT ); Tue, 24 Apr 2018 10:46:12 -0400 Received: by mail-oi0-f67.google.com with SMTP id e80-v6so10458448oig.11 for ; Tue, 24 Apr 2018 07:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=CnNrPi0PRxvuskkyxnoWq69868YaFdnUxYS5rswuHKI=; b=LgJ6z5dGIIbGgwyomfS1hg2ncjxypM1VSp0W+HM9bgeyrKGuAvZbxAkPtEziGR+zsr OI/LiUPSp3bWK7y4u/6eCRpVo119XDUs2YhK/V2UKHyuVac9g9JHdpGgGhG+nYJGQM3c qulRO7rYcQIgsoJWMRc7RyxV57PJC99rd+Uuty4kQzZmyy4xk/4BRGq0yqHw+vnIXkH1 bjT53Sd97azAaKvTW9RXrG2oQM7NRbJgDrufh5SbHeJA+a7M/pUpU6uJ44YBkqUyuoHS Ohq2L+7t14/XKzuYsZ5hWIv3wFqAE+f7+1tmgkXVHuO7nLlhwSsG6tjLiOWo2oNCv7Lm 1jgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=CnNrPi0PRxvuskkyxnoWq69868YaFdnUxYS5rswuHKI=; b=OomPrCpFE9aYPgExinQ5XKingwaTzEh5zrrAOAr9QJh245UFX1MhLETtz2CfUtZQ+m D+Bu8MtCoHlWHX3dM+IoD6im6VpxkoQ+CvBN+JwIeuFeFyE69gSQYaeEPjzkkV42Bn2O 3BLlGPvyf9YlYJ2Xwz+izo6S4NTTZf1WMny0tjWnZrLxl36uHjAcY1eZoTKsJHZ79WwZ DaMThw69WG8lqeofyEB+B/quME5aSftnR5UzBR0KpeJ7wj2jcNKSJ6HflsGEObbJPTGa /raA6FuN3/aKqRykiYjKapIHYLnalzGSlSoxt6Eoes0PagUG628IQmoOxFSe3Guoez4P InhA== X-Gm-Message-State: ALQs6tB674i1sbbUCqA4hu+j7rAqbvmu+LsWKYFOqStwbam2tzcRDsfx bPI9ny5kJMLSYnRg2piN3mVuXDpXYewNsCRZoCk= X-Received: by 2002:aca:bf02:: with SMTP id p2-v6mr782918oif.306.1524581172287; Tue, 24 Apr 2018 07:46:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.138.3.5 with HTTP; Tue, 24 Apr 2018 07:45:51 -0700 (PDT) In-Reply-To: <20180424141759.F02AF6C59D@po15720vm.idsi0.si.c-s.fr> References: <20180424141759.F02AF6C59D@po15720vm.idsi0.si.c-s.fr> From: Mathieu Malaterre Date: Tue, 24 Apr 2018 16:45:51 +0200 X-Google-Sender-Auth: SBkZKlLnyPO6aJXJHEJdkQWKfJ4 Message-ID: Subject: Re: [PATCH] powerpc/signal32: Use fault_in_pages_readable() to prefault user context To: Christophe Leroy Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , LKML , linuxppc-dev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 24, 2018 at 4:17 PM, Christophe Leroy wrote: > Use fault_in_pages_readable() to prefault user context > instead of open coding > > Signed-off-by: Christophe Leroy > --- > arch/powerpc/kernel/signal_32.c | 13 +++++-------- > 1 file changed, 5 insertions(+), 8 deletions(-) > > diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c > index 492f03451877..cfacb2726152 100644 > --- a/arch/powerpc/kernel/signal_32.c > +++ b/arch/powerpc/kernel/signal_32.c > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > #include > #ifdef CONFIG_PPC64 > #include > @@ -1045,7 +1046,6 @@ long sys_swapcontext(struct ucontext __user *old_ctx, > struct ucontext __user *new_ctx, > int ctx_size, int r6, int r7, int r8, struct pt_regs *regs) > { > - unsigned char tmp __maybe_unused; > int ctx_has_vsx_region = 0; > > #ifdef CONFIG_PPC64 > @@ -1109,9 +1109,8 @@ long sys_swapcontext(struct ucontext __user *old_ctx, > } > if (new_ctx == NULL) > return 0; > - if (!access_ok(VERIFY_READ, new_ctx, ctx_size) > - || __get_user(tmp, (u8 __user *) new_ctx) > - || __get_user(tmp, (u8 __user *) new_ctx + ctx_size - 1)) > + if (!access_ok(VERIFY_READ, new_ctx, ctx_size) || > + fault_in_pages_readable((u8 __user *)new_ctx, ctx_size)) > return -EFAULT; > > /* > @@ -1231,7 +1230,6 @@ int sys_debug_setcontext(struct ucontext __user *ctx, > { > struct sig_dbg_op op; > int i; > - unsigned char tmp __maybe_unused; > unsigned long new_msr = regs->msr; > #ifdef CONFIG_PPC_ADV_DEBUG_REGS > unsigned long new_dbcr0 = current->thread.debug.dbcr0; > @@ -1287,9 +1285,8 @@ int sys_debug_setcontext(struct ucontext __user *ctx, > current->thread.debug.dbcr0 = new_dbcr0; > #endif > > - if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx)) > - || __get_user(tmp, (u8 __user *) ctx) > - || __get_user(tmp, (u8 __user *) (ctx + 1) - 1)) > + if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx)) || > + fault_in_pages_readable((u8 __user *)ctx, 1)) I believe you meant: fault_in_pages_readable((u8 __user *)new_ctx, ctx_size) Since (u8 __user *) (ctx + 1) - 1 really is (u8 __user *) new_ctx + ctx_size - 1 > return -EFAULT; > > /* > -- > 2.13.3 >