Received: by 10.192.165.148 with SMTP id m20csp4750613imm; Tue, 24 Apr 2018 07:52:44 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/rwjeJCmccDOO8gfG/vhshOISu+3ASk/IKVVd0Ln4EzranGu4yFGJmVq7gBlN1DlIw+gpx X-Received: by 10.167.131.217 with SMTP id j25mr23953170pfn.5.1524581564176; Tue, 24 Apr 2018 07:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524581564; cv=none; d=google.com; s=arc-20160816; b=zjk7yM4qTSdP/jVw1uKUPkF0B2uwZ7c8wz5RPtgeZ5l1pUTliXzLiXw3eBY30gJsyN O13A7RvjO53ip9ACjJnE4aN2YpC1LzjiEsi6WeXlUkrlSTWOrCl4f9cxw20n+OxKiyJr CRsO7ofFV3s6mKZb7ywD0Y3YW7q/ZKxgXVMlf8frCWZmcxOzqDxF+kMXlFSBRHuv/r6v /H4vDAszlnKSaBcfc460t21tRwO6boR/CTVXJ6UWpB7NrhZZcpnX4/tJCL9psjhMxt/6 Zaaxi8nSE7HEKi69UR4zCEN1BKo6eEh6kvj+e/G348L/GcT1nYL5fncdtFMwmq20j4mz XJ5g== 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=aZQyTqNmD4zC5ClsuOWv0wbYTss2sdUj2s86gbWkt7w=; b=EkucCk36+xP5tsvV8KwsPJn2qJ02rAyUXqHiWFilKoD70gyeuP01GVXF9ObJl/OL71 LH6erHlRmbm3sT3c5/nXJFoXfBESMXSNfUkQpWU7l8t6blMkfZjomwrFZ1tWKCel3CpY z3wFwAIUtlHJwdC03nMDlpaoqGrDTSVN/mmsDZSswlr9yiv/NEfqSI5oE3mbfbJfcUbn ULlQI2eA2PB5Rv3V1ovOxB26F+xz7sflFPgJPbIKy2lorFBnf5mlkz35+/iB3yada+f/ h/HkBlt/2FEOSFXEIyi0CeTZ0sM/o8xCF17a0fcqDDeCxy+itlAjlagSZXOHXOGXoh3W 7WeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fnsMC/vN; 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 w12si11839774pge.165.2018.04.24.07.52.29; Tue, 24 Apr 2018 07:52:44 -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=fnsMC/vN; 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 S1751437AbeDXOvQ (ORCPT + 99 others); Tue, 24 Apr 2018 10:51:16 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:35538 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751097AbeDXOvJ (ORCPT ); Tue, 24 Apr 2018 10:51:09 -0400 Received: by mail-oi0-f65.google.com with SMTP id a6-v6so8878459oia.2 for ; Tue, 24 Apr 2018 07:51:08 -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=aZQyTqNmD4zC5ClsuOWv0wbYTss2sdUj2s86gbWkt7w=; b=fnsMC/vNPLXJvbdx5iY8d6WEmo/IXOdr8FiKnUj1y1R0yGdVjm32/Opaqppf6kcmtf 1rnXrLAptjwm7gTRZ10jrZSldy9F8Ij0IPdbRV1e9em3PRoRRY2m67L5+pbtAN4GqmUg gB2SR8CIACNfT6U8lF8kfLAMa4MKwv5TC8R1KNqPwnasJW86/ohAbNiyw+jFKSxCOuiZ ohFnnJmzFk7gvnMqc7ElOmemLTHi4hWL7RHxRAHVdD/0Qq/EAzXBpyvbC8X2nYm/eTAt llWJ1+hh7N2tck5zCHofynfK6YD2NcuBtExtNYV2Tn7QILZzAEcmTzRbcTg3T74C1M1C rHcw== 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=aZQyTqNmD4zC5ClsuOWv0wbYTss2sdUj2s86gbWkt7w=; b=Sf4g2Fgw/RmOSqI4vyZpBte6rhINx1jaj3EofFbjZI2m+1k8VH9klwcaKADMooG6Ga WTFVsfBsXEcz9hu7Xc7NfziLr3gKkOjJsTU8O+xUDmeME3FLoqK0iFY5PwD6nm7cTzSY TvRD+ulJWyWzzWumdQR8vJIGOPJYmPsx87szb1fErdj16tsbIar20og38FBGAqczLe1y sMLx2QSkd0rT4mq5H4srtcr4hqy58yGqS954mPiUxmaDmnjct58mf70Pqwj64t3TfeWr Tx9x5+uK79SFoLlO1osg0vLDlgZwZLp8icgwuK0UZ6PDg/E1UWfthWE2crjPxGhq9mAs xlCQ== X-Gm-Message-State: ALQs6tDPfbcahVNXAJTDS59G/5ie3RKAA48wDFk1HXnO94AWdVKPaCFd DMc6zfHCzXrgqXCXn+bv/vnYV+cRhNbVKXctBgM= X-Received: by 2002:aca:328a:: with SMTP id y132-v6mr15975436oiy.199.1524581468385; Tue, 24 Apr 2018 07:51:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.138.3.5 with HTTP; Tue, 24 Apr 2018 07:50:47 -0700 (PDT) In-Reply-To: References: <20180424141759.F02AF6C59D@po15720vm.idsi0.si.c-s.fr> From: Mathieu Malaterre Date: Tue, 24 Apr 2018 16:50:47 +0200 X-Google-Sender-Auth: Z1ven8z2rbGe5R3_j7yLt8u9MMQ 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:45 PM, Mathieu Malaterre wrote: > 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 Without the copy/paste errors: [...] fault_in_pages_readable((u8 __user *)ctx, sizeof(*ctx)) Since (u8 __user *) (ctx + 1) - 1 really is (u8 __user *) ctx + sizeof(*ctx) - 1 [...] >> return -EFAULT; >> >> /* >> -- >> 2.13.3 >>