Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3753845pxb; Mon, 1 Nov 2021 20:22:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfCgKErWN2laMbMSEGroL0wMVWGZzWINpQ3mN1QYotp010nPzam/rrpAkUEr4wMH7dLjat X-Received: by 2002:a92:c245:: with SMTP id k5mr9458928ilo.280.1635823372064; Mon, 01 Nov 2021 20:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635823372; cv=none; d=google.com; s=arc-20160816; b=f3GmqlmvXUYIrKeogv6xDVYpF1jkT+B5jWM7XVDgPFqpTUMIBgeeayYltTIhTHJgHo dIJIiA287qmYAg7DURlTjiqn/dum3+ZzaZaxqEyG8pnBpV9q1Wf4HMZwXj8cEE9IXymt +eOGlI/qqQYT45gI3aZ8zznlm8vNQB/+OTDRxYA3Il5Ypb9XpWo0PvzoQSDh1Lo4HTcS z5bvmUEER3fUW5VGhKJDVBQRwdoRpRa5RHr+23oUmJAnPJZMD7Lp1EcSNPKIJ3GXqRlF HEQeAQHSwo6rnU6k6aq8hcOPvz8OAr837ZvYhp/TsU79KbqEfuy2ZMWVWHLzSMUMrs0f 04tg== 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=lzmqKQY04x0Mf4v12yhiT4vRZMoRSKZyJDowpEUZgLM=; b=jSmwXYi0nrEC67N0vUJcO0V6qpnIte7Bqj66jUCtFf1rTNiACNKfA5n9MjPnSUKHY7 WqoA3PBYeI1UxVMjFKysx1sJv1lGse8ET4mfBKtCmpyQ01JvNkU4xrjPeOqSHQ8dTH4I pUGvV6Wey7dSpMy3KSePj++i9hX1l7GFdIqPegfo3D/h/57TuQyYBSRB4rjRoMGn66g9 h6grcUqjBH26Ee0tJ9P7t+36InTlO/nn3wjMZP5EHTeHEMQNF0mvmjhvth0hLKhDLWKM ZiK2qqpuF17SphIh61Z38wYR2lngqDTtpMwbB6zVZHuVhYJHoT+VbLHk1mfMwHLeozxy 4vKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jFB1CeXu; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w11si951568iov.94.2021.11.01.20.22.39; Mon, 01 Nov 2021 20:22:52 -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=@gmail.com header.s=20210112 header.b=jFB1CeXu; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231889AbhKBDXD (ORCPT + 99 others); Mon, 1 Nov 2021 23:23:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbhKBDXD (ORCPT ); Mon, 1 Nov 2021 23:23:03 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6608C061714; Mon, 1 Nov 2021 20:20:28 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id r28so18993827pga.0; Mon, 01 Nov 2021 20:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lzmqKQY04x0Mf4v12yhiT4vRZMoRSKZyJDowpEUZgLM=; b=jFB1CeXudan1gpt+WYXrPANf21KVYr7eNwWcSdTX7/NP0/0z2t8Scz3zfU7h+h8Bh8 TGzXwFsUK3hUfQoekamLiflZqX2w3Xhw9imauD6d9Qj5E561bl8jhXRZV+O0AUOpnPUC 9Avp4G8ZygQon7Cm5akD2V91qbhHRLBl0EPxZbVkSkTy4G6Xi5MT1MpddEUJ5pqgtBd5 YrDg7Ya1R4ZxMoHZWdBnHuPGn1Ea/bvZTt1pcLk1i5Ee70gsS4yPMHJ28XdKb+8dV3QZ AgyMKcV9AxZQcoREHiVqdXF8hEOimkj3rXUF1+/M+gZmY6APdOVKNWX3eIQTZ59SoEgw f3mw== 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=lzmqKQY04x0Mf4v12yhiT4vRZMoRSKZyJDowpEUZgLM=; b=jWLuq5pGjhRwKv6arbBuFKgk0aridU7Mim3BCOBUiBNH8hrBWU3Ane76O7+Eg7sBMd /gZJUlh+UnI+O/YmCL0huN+9AX+c481B6oYcZSOuFriX/jhe8DaL/19NgNQ9qFgHRZQB cmnW5eh77ItamvqVkMthsVRt2ryAPkz+Uc+/+CNMMFfCkzYruYd+CGwQZB8bQXw/nhgr N4jt6YcOk7QIUnnDCH1Jf2ZEhoAgPMEVmJOCNSKhQq2Zkx7Ek655wdPKfaiPQHL/knM1 gDDclZGym0mA6kFaAu0zdL+sbfmMnftTxsamU7Vsx7FzPZjLrlWvzW23w28qm3eMrufz wHhQ== X-Gm-Message-State: AOAM531TfISx6t1k5ewtppqkxFP0mpU7BxqpDMRRs1Ovdn0FaHkFW8AN 8Uyky2PsPb5IU1tUPnMdDR1qtGyLZB2TBY22yhE= X-Received: by 2002:a63:8642:: with SMTP id x63mr8609418pgd.376.1635823228318; Mon, 01 Nov 2021 20:20:28 -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: Alexei Starovoitov Date: Mon, 1 Nov 2021 20:20:17 -0700 Message-ID: Subject: Re: [PATCH bpf-next] bpf: Allow bpf_d_path in perf_event_mmap To: Andrii Nakryiko Cc: Yonghong Song , Florent Revest , 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 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. > > Can we just require all helpers to check NULL if they accept > PTR_TO_BTF_ID? It's always been a case that PTR_TO_BTF_ID can be null. > We should audit all the helpers with ARG_PTR_TO_BTF_ID and ensure they > do proper validation, of course. > > Or am I missing the essence of the issue? It's not a pointer dereference. It's math on the pointer. The &vm_file->f_path part. The helper can check that it's [0, few_pages] and declare it's bad. 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.