Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2793084yba; Mon, 6 May 2019 11:36:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTRoyqDPpMPwavwb3lG5nZmwGIajo6BbOibM9DPsBqCtvmF46QQKwpPq/cDWM3GMbEIo/q X-Received: by 2002:a63:3746:: with SMTP id g6mr34022558pgn.422.1557167785779; Mon, 06 May 2019 11:36:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557167785; cv=none; d=google.com; s=arc-20160816; b=j1sIoHtA37VXuNn4IvcPjOOLPuIQNtE4/fLUBbsQlpa2nAwv3khU9HvD8SL5TLUuFl BwTvlQ+PMbe50m2d/ooyADoBvufcD+OmYLuDl5wvmusleF0yzQaFA7BkRB0jYzhlilzO 1PKOG4WNXf01P3mK/lBvFJHSZLo+NKjsUZ0p8dlApF5mug4moX2Yyuy50iE2TA+akp9i vdDHuUpOhwxx4pgXOlsNCqxr3IdOAOw8/0ZYYWHTJe5JlywJau+ukAOhoazVrk5tNUl+ MgzImwQoSLcBvzNV+6huaLrGCamC57yaDesy0kZXZc71cVaBIJjeHMZGXCfQ3T6jn696 fiPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=rd4we1sTW5rUDKedurecUOa8j4t9Z+0UOSLkHu6U8gM=; b=CM3qNLyq55smnFD87dH35NrGlnub16bI/jMCV6kXPbobwb5yIBlK314/28QiQiQa7j BXCMhhdcpg0uwbLZptYLXgOH7v7XFZDUslMqwdNkX6l20xqWRzUYFSIqWrgBswBLsO60 41e5SbZtsCgNpZA3hymsnEtHMH/Y7S+OYskLLaSSft2ROZ4nXZzCPgj6wKbNZOB39p6m 2N7BoV3rNW1ACidrQcIUQI3i1Cm7DLFTwThneQHRbt4O5shJTfezIl+Ek9dI0uowPXTB Eq8UpYnNMLYA1mcNpnNJUGEJp4MlN9bvAU15hPtyEvPWS25f64zOuvKemL6ghsrtOvYz 5zFw== 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 bh3si15656812plb.284.2019.05.06.11.36.09; Mon, 06 May 2019 11:36:25 -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; 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 S1726567AbfEFSfQ (ORCPT + 99 others); Mon, 6 May 2019 14:35:16 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59244 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbfEFSfP (ORCPT ); Mon, 6 May 2019 14:35:15 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EC17CA78; Mon, 6 May 2019 11:35:14 -0700 (PDT) Received: from brain-police (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C0C843F5AF; Mon, 6 May 2019 11:35:09 -0700 (PDT) Date: Mon, 6 May 2019 19:35:06 +0100 From: Will Deacon To: Joel Fernandes Cc: Qais Yousef , linux-kernel@vger.kernel.org, Michal Gregorczyk , Adrian Ratiu , Mohammad Husain , Srinivas Ramana , duyuchao , Manjo Raja Rao , Karim Yaghmour , Tamir Carmeli , Yonghong Song , Alexei Starovoitov , Brendan Gregg , Masami Hiramatsu , Peter Ziljstra , Steven Rostedt , Kees Cook , kernel-team@android.com, Daniel Borkmann , Ingo Molnar , netdev@vger.kernel.org, Mark Rutland Subject: Re: [PATCH RFC] bpf: Add support for reading user pointers Message-ID: <20190506183506.GD2875@brain-police> References: <20190502204958.7868-1-joel@joelfernandes.org> <20190503121234.6don256zuvfjtdg6@e107158-lin.cambridge.arm.com> <20190503134935.GA253329@google.com> <20190505110423.u7g3f2viovvgzbtn@e107158-lin.cambridge.arm.com> <20190505132949.GB3076@localhost> <20190505144608.u3vsxyz5huveuskx@e107158-lin.cambridge.arm.com> <20190505155223.GA4976@localhost> <20190505180313.GA80924@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190505180313.GA80924@google.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Joel, On Sun, May 05, 2019 at 02:03:13PM -0400, Joel Fernandes wrote: > +Mark, Will since discussion is about arm64 arch code. > > The difference between observing the bug and everything just working seems to > be the set_fs(USER_DS) as done by Masami's patch that this patch is based on. > The following diff shows 'ret' as 255 when set_fs(KERN_DS) is used, and then > after we retry with set_fs(USER_DS), the read succeeds. > > diff --git a/mm/maccess.c b/mm/maccess.c > index 78f9274dd49d..d3e01a33c712 100644 > --- a/mm/maccess.c > +++ b/mm/maccess.c > @@ -32,9 +32,20 @@ long __probe_kernel_read(void *dst, const void *src, size_t size) > pagefault_disable(); > ret = __copy_from_user_inatomic(dst, > (__force const void __user *)src, size); > + trace_printk("KERNEL_DS: __copy_from_user_inatomic: ret=%d\n", ret); > pagefault_enable(); > set_fs(old_fs); > > + if (ret) { > + set_fs(USER_DS); > + pagefault_disable(); > + ret = __copy_from_user_inatomic(dst, > + (__force const void __user *)src, size); > + trace_printk("RETRY WITH USER_DS: __copy_from_user_inatomic: ret=%d\n", ret); > + pagefault_enable(); > + set_fs(old_fs); > + } > + > return ret ? -EFAULT : 0; > } > EXPORT_SYMBOL_GPL(probe_kernel_read); > > In initially thought this was because of the addr_limit pointer masking done > by this patch from Mark Rutland "arm64: Use pointer masking to limit uaccess > speculation" > > However removing this masking still makes it fail with KERNEL_DS. > > Fwiw, I am still curious which other paths in arm64 check the addr_limit > which might make the __copy_from_user_inatomic fail if the set_fs is not > setup correctly. > > Either way, I will resubmit the patch with the commit message fixed correctly > as we agreed and also address Alexei's comments. I'm coming at this with no background, so it's tricky to understand exactly what's going on here. Some questions: * Are you seeing a failure with mainline and/or an official stable kernel? * What is the failing CPU? (so we can figure out which architectural extensions are implemented) * Do you have a .config anywhere? Particular, how are ARM64_PAN, ARM64_TTBR0_PAN and ARM64_UAO set? * Is the address being accessed a user or a kernel address? If you're trying to dereference a pointer to userspace using probe_kernel_read(), that clearly isn't going to work. Will