Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1558735yba; Sun, 5 May 2019 08:53:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXQwuoyEPK0ReXYO9cfx6YIbsHFXbOnVepUATAsnd2jHoGfX+04p3HGlaZl4q2aevIf3KG X-Received: by 2002:a62:4115:: with SMTP id o21mr26611057pfa.153.1557071611193; Sun, 05 May 2019 08:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557071611; cv=none; d=google.com; s=arc-20160816; b=wLEmBZbHUudTILB5TrVniHfqcuHQUmk8oXQ5zSeI9EB/h/CSq57YzhsdhyMb2p9+iE Rz2aXyLiYcFOZvlio/Blo9Kf1sr9mKaEGp3uaEkzM79MtR0GByadF1IqavO7ja1yqGR8 wVF3WwjQOziV2ZdxeJDmFOhVYB67OWfoX6p5x5mTcu+vAHAamvUaTTewtms/sFf7Kt7s 5gHXIO93eKwAFhxLxpib/e7J2GbqdpQUcuKO35uBtszl5o5wnTX2/2kpJpTEYG8uCJOH cIAF28XU6ZQJ+WMVJ++abhzo9NxgG8Wlzrrg4D9C8MgAE7VZPDT0iG+HAY/TuO2tUF2u Yn0w== 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:dkim-signature; bh=ekhL+urX0SV3pO/WanUIad49ZFzCKRVsusysCBLgkOE=; b=aW7TXdSfcLjs7DsccRZaJedbtFePunvSir2ztM/4NOfVowkcvejKKA1NQ+/MhWLL7g Ht/2UEew3RoGqxgkNrZfl/EXtkxT3jtsR0893f7bDeOx/Rh/ahSq+jH0GKSsUMDleLwG gGQelB3s/yKVD2FLjjczAMX9+/+9QQcKiexyKunMmx4X9KccT1NeurQ0QseiJ4mFFxXo E7RZ1sSCedJ6oFDg65urq8uLOYKo/In+4XHgyNc6wNNOjy/6V3sJeyfNgr+uXkD6UmoU tjJDl/rod7WzgPW5kUyiw2NTav2Wf0NxFioPyhcNV82j5HNs3vdAThaSg76Ky9owucrS YDkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=xWWosPQH; 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 g64si11477084pfd.281.2019.05.05.08.53.16; Sun, 05 May 2019 08:53:31 -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=pass header.i=@joelfernandes.org header.s=google header.b=xWWosPQH; 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 S1727295AbfEEPw2 (ORCPT + 99 others); Sun, 5 May 2019 11:52:28 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:39683 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726965AbfEEPw1 (ORCPT ); Sun, 5 May 2019 11:52:27 -0400 Received: by mail-qt1-f195.google.com with SMTP id y42so12096363qtk.6 for ; Sun, 05 May 2019 08:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ekhL+urX0SV3pO/WanUIad49ZFzCKRVsusysCBLgkOE=; b=xWWosPQHmUFheOe1Au0aHAuk81jiD4yI3tFMkCufMgZkpHgtxb9cCqBttPlxKzRAHV CrEPqOxXsAQiyW13TTg5vOY8UoMtKpL6DcTZe4PbEAXOnj8q+ze8NZrrvD041oNuuk4H iw8RMna6hLhRus1sL/wdsLDLpFCZQ/CWWSRm0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ekhL+urX0SV3pO/WanUIad49ZFzCKRVsusysCBLgkOE=; b=UccUQqf1RjXSn9BRDeAqrEUdImu33vrErX+DdSX+m9r2vC6J68VPBl1NDiODxby5K0 VEQveOKvzNoJGN26WxPrlBehkyOnKMCSAFGngtIpzvc1E0ntC1HSePEQsKvH0v1Z7vAy EnmH0WU1YcjFgRAnMCiZ/f8TkQX5s2bQzcgD9T/FoDt28sg+lDcWZYg62cTwu21f/sv+ +qXMuiIG9Q6tden48vASXZbxfGFUz0mieOv2Eo0pYEBtZft+pBgRdPHIh5we8sSff088 mK7GWRByuq8zHdz/sOEiI5cMCcI2xeFIHvle+E6ce2K0C12TMCc5JjyZUJKG5DsqRYeq 1AUg== X-Gm-Message-State: APjAAAV4TaSS/t7wjclwo/8n/VrvVamFTV34aKGlUr8RE6qdEeYpq2S5 mzxJgGkL5VKiPPdUaqA+DvZ4Og== X-Received: by 2002:a0c:8b6f:: with SMTP id d47mr17288737qvc.135.1557071546090; Sun, 05 May 2019 08:52:26 -0700 (PDT) Received: from localhost ([2600:1003:b451:8ec8:55bc:61ad:9aa2:244e]) by smtp.gmail.com with ESMTPSA id v141sm5000241qka.35.2019.05.05.08.52.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 May 2019 08:52:25 -0700 (PDT) Date: Sun, 5 May 2019 15:52:23 +0000 From: Joel Fernandes To: Qais Yousef Cc: 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 Subject: Re: [PATCH RFC] bpf: Add support for reading user pointers Message-ID: <20190505155223.GA4976@localhost> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190505144608.u3vsxyz5huveuskx@e107158-lin.cambridge.arm.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 On Sun, May 05, 2019 at 03:46:08PM +0100, Qais Yousef wrote: > On 05/05/19 13:29, Joel Fernandes wrote: > > On Sun, May 05, 2019 at 12:04:24PM +0100, Qais Yousef wrote: > > > On 05/03/19 09:49, Joel Fernandes wrote: > > > > On Fri, May 03, 2019 at 01:12:34PM +0100, Qais Yousef wrote: > > > > > Hi Joel > > > > > > > > > > On 05/02/19 16:49, Joel Fernandes (Google) wrote: > > > > > > The eBPF based opensnoop tool fails to read the file path string passed > > > > > > to the do_sys_open function. This is because it is a pointer to > > > > > > userspace address and causes an -EFAULT when read with > > > > > > probe_kernel_read. This is not an issue when running the tool on x86 but > > > > > > is an issue on arm64. This patch adds a new bpf function call based > > > > > > > > > > I just did an experiment and if I use Android 4.9 kernel I indeed fail to see > > > > > PATH info when running opensnoop. But if I run on 5.1-rc7 opensnoop behaves > > > > > correctly on arm64. > > > > > > > > > > My guess either a limitation that was fixed on later kernel versions or Android > > > > > kernel has some strict option/modifications that make this fail? > > > > > > > > Thanks a lot for checking, yes I was testing 4.9 kernel with this patch (pixel 3). > > > > > > > > I am not sure what has changed since then, but I still think it is a good > > > > idea to make the code more robust against such future issues anyway. In > > > > particular, we learnt with extensive discussions that user/kernel pointers > > > > are not necessarily distinguishable purely based on their address. > > > > > > Yes I wasn't arguing against that. But the commit message is misleading or > > > needs more explanation at least. I tried 4.9.y stable and arm64 worked on that > > > too. Why do you think it's an arm64 problem? > > > > Well it is broken on at least on at least one arm64 device and the patch I > > sent fixes it. We know that the bpf is using wrong kernel API so why not fix > > it? Are you saying we should not fix it like in this patch? Or do you have > > another fix in mind? > > Again I have no issue with the new API. But the claim that it's a fix for > a broken arm64 is a big stretch. AFAICT you don't understand the root cause of > why copy_to_user_inatomic() fails in your case. Given that Android 4.9 has > its own patches on top of 4.9 stable, it might be something that was introduced > in one of these patches that breaks opensnoop, and by making it use the new API > you might be simply working around the problem. All I can see is that vanilla > 4.9 stable works on arm64. Agreed that commit message could be improved. I believe issue is something to do with differences in 4.9 PAN emulation backports. AIUI PAN was introduced in upstream only in 4.10 so 4.9 needed backports. I did not root cause this completely because "doing the right thing" fixed the issue. I will look more closely once I am home. Thank you. > So I am happy about introducing the new API but not happy with the commit > message or the explanation given in it. Unless you can investigate the root > cause and relate how this fixes it (and not workaround a problem you're > specifically having) I think it's better to introduce this patch as a generic > new API that is more robust to handle reading __user data in BPF and drop > reference to opensnoop failures. They raise more questions and the real > intention of this patch anyway is to provide the new correct way for BPF > programs to read __user data regardless opensnoop fails or not AFAIU. > > Cheers > > -- > Qais Yousef