Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp714326img; Tue, 26 Feb 2019 07:25:49 -0800 (PST) X-Google-Smtp-Source: AHgI3IabHwYl/4Lizhq9l/KEKtyBT2pgB9zG43Ecdh6IjMygBej2cdpyXkDgdIIGpOZ4ASNNAhH9 X-Received: by 2002:a17:902:207:: with SMTP id 7mr26220986plc.142.1551194749437; Tue, 26 Feb 2019 07:25:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551194749; cv=none; d=google.com; s=arc-20160816; b=F3dUWWnvMA2DqpwO6ebcwwFl88GC2J/sjo0l8vrnYIMzc38TKtNFMif+QMpGV4A4bP 9OesOjdXqpZd3EJXT2yij8miYJAtAddSc6NB0ZbKNKN2oWNFfVg2E/q9kMj//sIgyIfp hbALvLs5japU/fwjVmrnifpzrQCh58VMh/+kYEYFAwb+Hqj99TETOKMrLnoPpk2YciGU V5eEDzv4S73VlThjM1ItWlybSN2/nm7GyW2uipHWjRp7qnbzoDTF9jWPxw2gEkAz3pUt hOcQ1KxaA8DkADdOrThbOG2UJPOr7rSBYu2q28iPxu8oGl9oUMQfYv4/XdK9SnIaYzrc /HLg== 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=tIb2I8rZC2PIlMCnZ63uX59cMsFRagPduk4bF+eM78w=; b=ZuBqE1fOrUo34K/rpMmN8hAZHSWYZUhot+Kn+fncICYpa8ELzw/ITiXGDqlrIkxIvM aSI1uRJgrz5pSx9/Z434useLpcIlU5s/ar0zVQDBPV9aNBfdIQGPtqeoRvU6RDCMV2Qx rjo+PV0uSBKVpWx5d+FdzkEB+uaiF4AobbklJcp/hFCLBfDseLLOZQr0/YeHZYdDjmr8 H/jkWxalmoAIQe+VsSX089+uWyrZ7pHz73ssHKWlcIe46+5wZaB547vtPx2r24ThpItv hBlpI28Ne5o2xEGweA/7Nu4D6BRgi9WO22SMsG44udB4LAReKLn+xx6m7sl6S3Vjb2ZK Vf5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=rtzm2sNs; 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 n3si12305539pgv.458.2019.02.26.07.25.33; Tue, 26 Feb 2019 07:25:49 -0800 (PST) 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=rtzm2sNs; 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 S1727054AbfBZPYv (ORCPT + 99 others); Tue, 26 Feb 2019 10:24:51 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:39167 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726542AbfBZPYv (ORCPT ); Tue, 26 Feb 2019 10:24:51 -0500 Received: by mail-qt1-f196.google.com with SMTP id o6so15274384qtk.6 for ; Tue, 26 Feb 2019 07:24:50 -0800 (PST) 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=tIb2I8rZC2PIlMCnZ63uX59cMsFRagPduk4bF+eM78w=; b=rtzm2sNsyrHcZAukv40yLi228bjHkDLGHh1wA5YVErmVMNL0EprOZ9lL6BDVeELonX sXsqJOciw+E9+XDde6J/9QKFbKH0sBJzmS7tBHDmpTFZMnxV1xwN3jgi4BY3LXkcBtXD +abVho8afJCTolOvtXYmIh8B8MKNBGQEudbgw= 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=tIb2I8rZC2PIlMCnZ63uX59cMsFRagPduk4bF+eM78w=; b=sUJ7eCmKiMvyoSZq+K8gvhfEXXgj+4QUESDydd25f45ZOH8kstATjuTkS9MOAViNak RcdkXLDyiPVCHFUdb8TqpjYWmARFDdcW7jhfBo6Rn4oj1/E1td5gM6PKP+Tr8oaXIFF4 l6uDfnszX0uHGKoCzpApL5Cu4cDM877I8XSgeIJV/9i1rLK3RQuJhNsfHv9EiflBL9QM 77MLj5Iz9+jzhXmzuoWggiw6lXi/W+bWmtq06HQyP7FO31ccpXipG9Qvo11wxAOg6vfO gRY7kp57nAy49TDOnRGpguTqLkLGjNdNkE62u4EHbL1hJEb4O0dwYJcA2yFKaqhGg+EJ +9xw== X-Gm-Message-State: AHQUAubUfGmhnv0vycHmTx+6HB5GbSDOWeO+V1NPnQ3EYRDD+cV34UMv MtxQ+8//HD3rLA5CDzH6UMC2WA== X-Received: by 2002:a0c:9508:: with SMTP id l8mr9231910qvl.88.1551194690147; Tue, 26 Feb 2019 07:24:50 -0800 (PST) Received: from localhost ([2620:0:1004:1100:cca9:fccc:8667:9bdc]) by smtp.gmail.com with ESMTPSA id 132sm6926844qke.0.2019.02.26.07.24.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Feb 2019 07:24:47 -0800 (PST) Date: Tue, 26 Feb 2019 10:24:47 -0500 From: Joel Fernandes To: Alexei Starovoitov Cc: Linus Torvalds , Masami Hiramatsu , Steven Rostedt , Andy Lutomirski , will.deacon@arm.com, Linux List Kernel Mailing , Ingo Molnar , Andrew Morton , stable , Changbin Du , Jann Horn , Kees Cook , Andy Lutomirski , daniel@iogearbox.net, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH 1/2 v2] kprobe: Do not use uaccess functions to access kernel memory that can fault Message-ID: <20190226152447.GA99670@google.com> References: <20190219111802.1d6dbaa3@gandalf.local.home> <20190219140330.5dd9e876@gandalf.local.home> <20190220171019.5e81a4946b56982f324f7c45@kernel.org> <20190220094926.0ab575b3@gandalf.local.home> <20190222172745.2c7205d62003c0a858e33278@kernel.org> <20190222173509.88489b7c5d1bf0e2ec2382ee@kernel.org> <20190222192703.epvgxghwybte7gxs@ast-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190222192703.epvgxghwybte7gxs@ast-mbp.dhcp.thefacebook.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 22, 2019 at 11:27:05AM -0800, Alexei Starovoitov wrote: > On Fri, Feb 22, 2019 at 09:43:14AM -0800, Linus Torvalds wrote: > > > > Then we should still probably fix up "__probe_kernel_read()" to not > > allow user accesses. The easiest way to do that is actually likely to > > use the "unsafe_get_user()" functions *without* doing a > > uaccess_begin(), which will mean that modern CPU's will simply fault > > on a kernel access to user space. > > On bpf side the bpf_probe_read() helper just calls probe_kernel_read() > and users pass both user and kernel addresses into it and expect > that the helper will actually try to read from that address. Slightly related and FWIW, BCC's eBPF-based opensnoop tool [1] installs a kprobe on do_sys_open to monitor calls to the open syscall globally. do_sys_open() has prototype: long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode); This causes a "blank" filename to be displayed by opensnoop when I run it on my Pixel 3 (arm64), possibly because this is a user pointer. However, it works fine on x86-64. So it seems to me that on arm64, reading user pointers directly still doesn't work even if there is a distinction between user/kernel addresses. In that case reading the user pointer using user accessors (possibly using bpf_probe_user_read helper) should be needed to fix this issue (as Yonghong also privately discussed with me). [1] https://github.com/iovisor/bcc/blob/master/tools/opensnoop.py#L140 thanks! - Joel > > If __probe_kernel_read will suddenly start failing on all user addresses > it will break the expectations. > How do we solve it in bpf_probe_read? > Call probe_kernel_read and if that fails call unsafe_get_user byte-by-byte > in the loop? > That's doable, but people already complain that bpf_probe_read() is slow > and shows up in their perf report. >