Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1190082yba; Sun, 5 May 2019 00:25:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyebikueYEmGCmAcQIPFoiLz8tUGtEaVQiryZIRsDv8oXlwwascxLYuUmM5QG2HC/oD65ct X-Received: by 2002:a63:5907:: with SMTP id n7mr23399293pgb.416.1557041153369; Sun, 05 May 2019 00:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557041153; cv=none; d=google.com; s=arc-20160816; b=UORhvPwDZGrP6Nw0t7XBklehtQsKVZBXN5THWRdscyyAK7yirY0daO7LV3devIhQ4B MfxDtQ9bB8GR5mAwqHQdn9vG8g/VmEKyE4YEupplCcQS59MmzBBmONbCL0Ws5cd4CKwW 6dvzjm6HqT8thUF1FBXq+OXdFrIIgyvlGg0SW54m/UwnN0/yzdq8ZHkeVC/Zy8m7vhUM G+lEbgDhAp3jEMhLNeg/RnU4LaU6SxiBS6ZiKjapM8pdT7f71mmFWD4E+En6zAYoDiBI 42XucMfx43gEzGwn3L3ROXiuzlJYaovW4h5j0858fHASmA+DgaJ4IWSyaYkb71mJNMdQ TN6w== 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 :in-reply-to:references:mime-version:dkim-signature; bh=rqjkexR6cKEvg4nJFIESH0EoiMBEnFjwHJlnCdqLAog=; b=beoM7WOpFhvQCJYbUbYbH2kNeW7GBmTJ+YvQPA1S7JhfFw3pSnftF6oD9rn47qyzY/ GguKsqpegQHHtoTMfVpcSm9ezEecTRs4DePepq9aU319uEy1dra6bEQIXecV530mAKr5 7dVTiDsbPDhhBaHoEC7XEbjDDBs9VrdJnpepgnGq9ZOemVAc/7aHDj9NXjuGxeYkjEem iLR5JGup6rWYwM1MQRE3Jj+mL236CVok4n9TCV9xJHzh4u6r21KP1WKDRhFB3SMoqV0j KVPRrszjIgmRqpxaqQHd5x7MyUOASy392xEOZ607k9Ng8QGmEGVH2lhlNOakTVTdbaNa 4A+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="C0/rbRj2"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id go14si9905101plb.221.2019.05.05.00.25.38; Sun, 05 May 2019 00:25:53 -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=@gmail.com header.s=20161025 header.b="C0/rbRj2"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727434AbfEEHT4 (ORCPT + 99 others); Sun, 5 May 2019 03:19:56 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:36668 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbfEEHT4 (ORCPT ); Sun, 5 May 2019 03:19:56 -0400 Received: by mail-lf1-f66.google.com with SMTP id y10so346451lfl.3; Sun, 05 May 2019 00:19:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rqjkexR6cKEvg4nJFIESH0EoiMBEnFjwHJlnCdqLAog=; b=C0/rbRj2NttQ1SxFzRYc2iCq6fDLNe999e6o44mbbCY61LNopJn1Uks2DrNzxmiDYE RoGeTjUqv6EcO72idFZjXfAzI0GdILyp0Cj9iFzcEPJ/ASDmuACN0/sjEgZU0g/3i2ez pUDwg30foReGTiIuc/z7gn5KOaI4zpZ31Op+06FOy921Q1EF/mGIYbJapPEhGdzgdDMz bI9HqvJZtaIZvPjavu/NP+tUjU0n49bQe2q3KHNeLTdm/qleTTMSbpBmDcztW5mVLvcG /lqkym7EhG/UnPpNs+kH2Z6YKID8ynKf7uB2PTiIRklrUQj4kfKl5YsdlmeyxyrSDLRQ 5mQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rqjkexR6cKEvg4nJFIESH0EoiMBEnFjwHJlnCdqLAog=; b=S/EWMflfkAG3JwUY3L/tCii+PnMf5BDMto4+YfTUcVRupPJzqWONIbIJx3A35MlzwW TLPollOLTuVXbR5GBOzz1kGZOJ/7ZjbALLdFzvzcn7CdQ5VziRzKv7Cny/XBkmbGQv3/ Ie3txsix/ynQ3l6vrn+bLPIU5w0Mj3kj9mwGYmMXTFfvokbcW9zNYB6D5r5NDGcL6duX 0iPf7neyr2gUfdhku7atoJmDzNFa20VX1fhZNPskizcrhTerSwARmm6ykjK9IJKUDXW7 CUncXKYXqfX8Nq1QsRCrZHX9cRuAvV0JhleuukTb9/sOC6Vc00iwZIIVUu2CL4eC+T5M 3PsQ== X-Gm-Message-State: APjAAAWUHbOufWwwbvTsbMNGWTDzubGSpvERPnPnRLqF50uQ+KLNmbo7 EDOHWjNm+LISBUEyGsHnMziQSQ++a/D0k7ZyKWw= X-Received: by 2002:a19:c216:: with SMTP id l22mr9436689lfc.112.1557040794052; Sun, 05 May 2019 00:19:54 -0700 (PDT) MIME-Version: 1.0 References: <20190502204958.7868-1-joel@joelfernandes.org> In-Reply-To: <20190502204958.7868-1-joel@joelfernandes.org> From: Alexei Starovoitov Date: Sun, 5 May 2019 00:19:42 -0700 Message-ID: Subject: Re: [PATCH RFC] bpf: Add support for reading user pointers To: "Joel Fernandes (Google)" Cc: LKML , Michal Gregorczyk , Adrian Ratiu , Mohammad Husain , Qais Yousef , Srinivas Ramana , duyuchao , Manjo Raja Rao , Karim Yaghmour , Tamir Carmeli , Yonghong Song , Alexei Starovoitov , Brendan Gregg , Masami Hiramatsu , Peter Ziljstra , Steven Rostedt , Kees Cook , Android Kernel Team , Daniel Borkmann , Ingo Molnar , Network Development 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 Thu, May 2, 2019 at 1:50 PM 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 > which calls the recently proposed probe_user_read function [1]. > Using this function call from opensnoop fixes the issue on arm64. > > [1] https://lore.kernel.org/patchwork/patch/1051588/ ... > +BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size, const void *, unsafe_ptr) > +{ > + int ret; > + > + ret = probe_user_read(dst, unsafe_ptr, size); > + if (unlikely(ret < 0)) > + memset(dst, 0, size); > + > + return ret; > +} probe_user_read() doesn't exist in bpf-next therefore this patch has to wait for the next merge window. At the same time we would need to introduce bpf_probe_read_kernel() and introduce a load time warning for existing bpf_probe_read(), so we can deprecate it eventually.