Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4787279pxb; Tue, 2 Nov 2021 16:05:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwd0QD+ClUlLSx4jHcy7SKMVg43eu1MEGeZKXkF2cBwb4a70lMa610etvpDZv5E+3zSNw+R X-Received: by 2002:a05:6602:2d43:: with SMTP id d3mr14403077iow.6.1635894314799; Tue, 02 Nov 2021 16:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635894314; cv=none; d=google.com; s=arc-20160816; b=G9nahgWm29v+ww+mM/9pk+tMIr2z+P69KNJ6nh+7TCf0T6KEniLA7EtRLe8EZHU031 eAaSbV+ZWcWHVsta63gg3IsiOiP0MVOrFh4d3RfZol7usNt6TE6sGN1B8f27VcRIK07B WvHDC+Lt9xWgm+ae0IVQbx3INxAQcZvzEj48NsoI20b8zV70S8x7uaF5dG3/bxGC2sK5 Hfd/h0Y7wL32H5XijDYopo6KFqnO1VMpq0UHY64Scb/PN3RyAXFd0ZvfuwX5H3KVntqD KlRMUS4z2HYvCkrkFwq2wq32VIiPrXQBNoTDXqr0G8h0XHxGnHclZ+wTSX8H2wZkUDN+ m0uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5ymKBrF1lHUXhO11qLF1Obbq9g7saDwiiQnV7ykje44=; b=pTZwi1888qyYEb4zvhop8yzhjDk0Fnq3nIGFgBvCFnJbZC1h1O6V3RZkIsEWLRjgWA Bq5vW4/MPR9vdaU3maPJaBIo/yLQmy9AWsxACPG4q0mNOLbi06znimc2avL0F7dQJwgW 6AyWlbFOKUm7N08VDBXTCnOfmi0spfVL5b3GEVzHUmlMO6QdVsMuFreIvOq8zgiAjm+m UxBMbx57N4Sz+TxL6ndYo9axx3vlQP6yE125tUk4BD7KC2lMs/lV6eAUx79ujHZTj78J 5gnyEfWgoykKVj17Km2g88MRsZ2A8EAB4DA79QZfQmpc22bnuZJWRxUFpOcdV0Hk6oD2 fMAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YFGSHXOn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay2si897375iob.27.2021.11.02.16.05.03; Tue, 02 Nov 2021 16:05:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YFGSHXOn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229900AbhKBXGd (ORCPT + 99 others); Tue, 2 Nov 2021 19:06:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbhKBXGc (ORCPT ); Tue, 2 Nov 2021 19:06:32 -0400 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15CFBC061203 for ; Tue, 2 Nov 2021 16:03:57 -0700 (PDT) Received: by mail-il1-x12a.google.com with SMTP id l8so691348ilv.3 for ; Tue, 02 Nov 2021 16:03:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5ymKBrF1lHUXhO11qLF1Obbq9g7saDwiiQnV7ykje44=; b=YFGSHXOnzm3Nf6cQVlx1DrAesM0CL0yllAeadoyVP9ENEoi283lOqB4RtkwGGO442f BKtE7QHbG4YnEOqX97+q4xEnk8DI92aNflHXnuz95nzTy4NNSBqD82OCGswWldycNAVo zyGRIN7mUNUNa/kFrCKBAVOxcg11X9TopVtUY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5ymKBrF1lHUXhO11qLF1Obbq9g7saDwiiQnV7ykje44=; b=XQQN+B4MwusibDr2HV/cuaHEOqpYSJD1YboTCyY3J1/Qrq9GZ1KzqYiWcopE+96Bbe xiXOEkvXjzyLGepM8vsz2bg+pDpqWdwoIIu4kjOtORvvKo9FzSbw6vh1t/7SfaoxV80l jFiOhwrQp5EPU4L1JV0vYBRbpBV4Tha31MCNcw/3xrL6xRbXbvIjlg1qDUJd1TLlgBJr v5nYl6HzWr9LMRicrgsNrEzj3BVTqU+rhpKQJHkN6VlZ1wkd2fjezFedgl58qKJvy/lv /n6vxA+321s5PnBaqQBaz8ZNPuAnnFIxapasHsbWRiETJ7URCm5Kp/t06rf251l1qexw kgMQ== X-Gm-Message-State: AOAM533pRgdBgvXeHgVjD2d0FcCQYHl8cXoeomfHauMzbDG6ODa5fMNe 9GsBcTq6SDUS5/H9cljbDZe66aFPBYVjzERu/knTeg== X-Received: by 2002:a92:c547:: with SMTP id a7mr15498371ilj.189.1635894236494; Tue, 02 Nov 2021 16:03:56 -0700 (PDT) MIME-Version: 1.0 References: <20211028164357.1439102-1-revest@chromium.org> <20211028224653.qhuwkp75fridkzpw@kafai-mbp.dhcp.thefacebook.com> <204584e8-7817-f445-1e73-b23552f54c2f@gmail.com> In-Reply-To: From: Florent Revest Date: Wed, 3 Nov 2021 00:03:45 +0100 Message-ID: Subject: Re: [PATCH bpf-next] bpf: Allow bpf_d_path in perf_event_mmap To: Andrii Nakryiko Cc: Alexei Starovoitov , Yonghong Song , Hengqi Chen , Martin KaFai Lau , bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , KP Singh , Brendan Jackman , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 2, 2021 at 5:06 AM Andrii Nakryiko wrote: > > On Mon, Nov 1, 2021 at 8:20 PM Alexei Starovoitov > wrote: > > > > On Mon, Nov 1, 2021 at 8:16 PM Andrii Nakryiko > > wrote: > > > > > > > > > > FILE *vm_file = vma->vm_file; /* no checking is needed, vma from > > > > > parameter which is not NULL */ > > > > > if (vm_file) > > > > > bpf_d_path(&vm_file->f_path, path, sizeof(path)); > > > > > > > > That should work. > > > > The verifier can achieve that by marking certain fields as PTR_TO_BTF_ID_OR_NULL > > > > instead of PTR_TO_BTF_ID while walking such pointers. > > > > And then disallow pointer arithmetic on PTR_TO_BTF_ID_OR_NULL until it > > > > goes through 'if (Rx == NULL)' check inside the program and gets converted to > > > > PTR_TO_BTF_ID. > > > > Initially we can hard code such fields via BTF_ID(struct, file) macro.' > > > > So any pointer that results into a 'struct file' pointer will be > > > > PTR_TO_BTF_ID_OR_NULL. Right, this is what I had in mind originally. But I was afraid this could maybe prevent some existing programs from loading on newer kernels ? Not sure if that's an issue. > > The helper can check that it's [0, few_pages] and declare it's bad. > > That's basically what happens with direct memory reads, so I guess it > would be fine. > > > I guess we can do that and only do what I proposed for "more than a page" > > math on the pointer. Or even disallow "add more than a page offset to > > PTR_TO_BTF_ID" > > for now, since it will cover 99% of the cases. Otherwise this sounds like a straightforward solution, yes :) Especially if this is how direct memory accesses already work. I'd be happy to look into this when I get some slack time. ;)