From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE671C4167B for ; Sun, 25 Dec 2022 22:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231282AbiLYWRF (ORCPT ); Sun, 25 Dec 2022 17:17:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbiLYWRE (ORCPT ); Sun, 25 Dec 2022 17:17:04 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 521DA1002 for ; Sun, 25 Dec 2022 14:17:03 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id u9so23287387ejo.0 for ; Sun, 25 Dec 2022 14:17:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=k9VYayWhEojXdedhpz0T3pFz3Qk5NlIUSQcAxKCeies=; b=my66nJcwzmG+P+xBFoH294AVlsUhkpk1U1yPW8gD22A9tApa3nf/Y798u5QqJ2KFdD C2ECvBpIRIUVyJ4ZEZVukE8Bb43+wh7eP9pEJbPlN/2hCNA+ltxznwjgs4B7eHL4riiB 5XigeR7py9R2YXqottUeXzbt4q+kkL6UCpZg+pZc53ktEcI3ZnD5zbEl1fBjT3tl4mjo MeThLKkFBx4nM2rOc4Wad7S/EdzKAqOeeuS25uiOCOlq7DZD5uQV8OliI8GyVNbOlFZb DVeYlsygJymK4VnaZZptxYk+zf1gJFzZmtPIt+opzkAwX9iaCf2vEjaa/pVPIMsYwDaW 3OWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=k9VYayWhEojXdedhpz0T3pFz3Qk5NlIUSQcAxKCeies=; b=uGnJTBVacdk4Klxegha59v/6yuw6xYDbEQUwsp1ioFNv6atswAE/wVpxz5ruWy7rwg HQeYjvqb0DbJCZYzTw3d4/zyj5kFUUBtaiWet1QNGicci+RczkWelxMuFMnCOkqcbA/V OE574fM1+cMd+cd0Vs8nDxQs/usFuYtMLyTxTUhXyCgVqB0aej/djzzcgn/71iJ6wYck 4Da5O0qBJ+CyInJXqmyUbAHKIye8sdhDOhs+1plftLoAM/B390YWsRayya3cPWfJxpTT L40TvHnZHFqoLNFZ7VrnYk9bs/Mmnz2PWjmdWT3cj1FijSa0fQ2cGmJWZ7EfPAmWvPvG mrGQ== X-Gm-Message-State: AFqh2kp6AGSekoLVCI5z2xmtD41ol2MP8+vQxjAn1MrmIoPkXvvt3MHB OnCaGVLyfBE2lNxz2f0V6boStRHtOxZWmPHX4aTQigz2mCw= X-Google-Smtp-Source: AMrXdXvj4TjWhrl6oaLRvnCr8CX/yG0bSRHD9hJLWz1fj14bqPQXTUxwsRS32yD+C1byaROl9bcMArcBcwc32oDuHz8= X-Received: by 2002:a17:906:a18c:b0:7c0:f2cf:3515 with SMTP id s12-20020a170906a18c00b007c0f2cf3515mr1075480ejy.327.1672006621737; Sun, 25 Dec 2022 14:17:01 -0800 (PST) MIME-Version: 1.0 References: <20221223185531.222689-1-paul@paul-moore.com> In-Reply-To: From: Alexei Starovoitov Date: Sun, 25 Dec 2022 14:16:50 -0800 Message-ID: Subject: Re: [PATCH v2] bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD To: Stanislav Fomichev Cc: Paul Moore , linux-audit@redhat.com, bpf , Alexei Starovoitov , Burn Alting , Jiri Olsa , Daniel Borkmann , Andrii Nakryiko Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Fri, Dec 23, 2022 at 5:49 PM Stanislav Fomichev wrote: get_func_ip() */ > > - tstamp_type_access:1; /* Accessed __sk_buff->tstamp_type */ > > + tstamp_type_access:1, /* Accessed __sk_buff->tstamp_type */ > > + valid_id:1; /* Is bpf_prog::aux::__id valid? */ > > enum bpf_prog_type type; /* Type of BPF program */ > > enum bpf_attach_type expected_attach_type; /* For some prog types */ > > u32 len; /* Number of filter blocks */ > > @@ -1688,6 +1689,12 @@ void bpf_prog_inc(struct bpf_prog *prog); > > struct bpf_prog * __must_check bpf_prog_inc_not_zero(struct bpf_prog *prog); > > void bpf_prog_put(struct bpf_prog *prog); > > > > +static inline u32 bpf_prog_get_id(const struct bpf_prog *prog) > > +{ > > + if (WARN(!prog->valid_id, "Attempting to use an invalid eBPF program")) > > + return 0; > > + return prog->aux->__id; > > +} > > I'm still missing why we need to have this WARN and have a check at all. > IIUC, we're actually too eager in resetting the id to 0, and need to > keep that stale id around at least for perf/audit. > Why not have a flag only to protect against double-idr_remove > bpf_prog_free_id and keep the rest as is? > Which places are we concerned about that used to report id=0 but now > would report stale id? What double-idr_remove are you concerned about? bpf_prog_by_id() is doing bpf_prog_inc_not_zero while __bpf_prog_put just dropped it to zero. Maybe just move bpf_prog_free_id() into bpf_prog_put_deferred() after perf_event_bpf_event and bpf_audit_prog ? Probably can remove the obsolete do_idr_lock bool flag as separate patch? Much simpler fix and no code churn. Both valid_id and saved_id approaches have flaws. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9582DC4332F for ; Wed, 28 Dec 2022 18:55:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672253729; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=eJs4uUs7m/wQkjk08pUXrLutEiaWEhfhZ5KSTwyRcJc=; b=CYJxND8JZXk4R2Bje70pbRUl5zGw5zOpJnQsjnB9nYGc7RAtRsCSJanBUygPo4nvoAfVGM /Ool6w1xhiONZFnCYAcmNvx/YaY0C4fuvFN+nrgwbYjAI7W2EpZ2LKZJUveJ1YQFLBN3U0 hT0ECkMkXdNA935PQfiV0eaBYUfu8qU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-351-WGoSxEIBOGyDeIsp2rluUw-1; Wed, 28 Dec 2022 13:55:26 -0500 X-MC-Unique: WGoSxEIBOGyDeIsp2rluUw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A61DB8F6E81; Wed, 28 Dec 2022 18:55:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9817F492B00; Wed, 28 Dec 2022 18:55:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6371A1946587; Wed, 28 Dec 2022 18:55:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9F0491946586 for ; Sun, 25 Dec 2022 22:17:05 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 758322166B34; Sun, 25 Dec 2022 22:17:05 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E8DA2166B33 for ; Sun, 25 Dec 2022 22:17:05 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 517BB85A588 for ; Sun, 25 Dec 2022 22:17:05 +0000 (UTC) Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-426-6KrFcLU1MiihlyCYMOlvLg-1; Sun, 25 Dec 2022 17:17:03 -0500 X-MC-Unique: 6KrFcLU1MiihlyCYMOlvLg-1 Received: by mail-ej1-f52.google.com with SMTP id ud5so23174253ejc.4 for ; Sun, 25 Dec 2022 14:17:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=k9VYayWhEojXdedhpz0T3pFz3Qk5NlIUSQcAxKCeies=; b=xkJ9GURITnN7Xn6d8KQAEfnPD4Y/svXKSY+4skcqGBN6HoFmFXDnDYEYVCRvMyWpaC l19u/IZVpAP3UQeNShI2lCnBaGx+UUSgBbzCRs2S5NSwJjrTNlt6wzV7Ul0UC7A2V+2q 58Qc3tJV8Axaus85vMIuq51Y5+JZe1WhsvAj6MPPQroA+qYpzovA2JLZecdCxIOaWYRF c+QPd3n/D8v/tzU+ggEk+VxeaBlZiUh/pInzFpQU2Okw5jZZx6l7vJU+QPtl+XhBCzZ8 pfo9j+eSijMOnWpKYAT7RNTdLBMSt79EgQHBLPZXWke4Hxm3zQzFsCWb+69nYiOzZzOG +VVw== X-Gm-Message-State: AFqh2kpBWrcUho33wtcJ0OVnXUXcg63/N442G9bIw77SyQCgI0ufXLyc lDTedkcY+pQBwNGJjLkmqt/rAtAEarYqlC0ZS/8= X-Google-Smtp-Source: AMrXdXvj4TjWhrl6oaLRvnCr8CX/yG0bSRHD9hJLWz1fj14bqPQXTUxwsRS32yD+C1byaROl9bcMArcBcwc32oDuHz8= X-Received: by 2002:a17:906:a18c:b0:7c0:f2cf:3515 with SMTP id s12-20020a170906a18c00b007c0f2cf3515mr1075480ejy.327.1672006621737; Sun, 25 Dec 2022 14:17:01 -0800 (PST) MIME-Version: 1.0 References: <20221223185531.222689-1-paul@paul-moore.com> In-Reply-To: From: Alexei Starovoitov Date: Sun, 25 Dec 2022 14:16:50 -0800 Message-ID: Subject: Re: [PATCH v2] bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD To: Stanislav Fomichev X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mailman-Approved-At: Wed, 28 Dec 2022 18:55:06 +0000 X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Burn Alting , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , linux-audit@redhat.com, Jiri Olsa , bpf Errors-To: linux-audit-bounces@redhat.com Sender: "Linux-audit" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Fri, Dec 23, 2022 at 5:49 PM Stanislav Fomichev wrote: get_func_ip() */ > > - tstamp_type_access:1; /* Accessed __sk_buff->tstamp_type */ > > + tstamp_type_access:1, /* Accessed __sk_buff->tstamp_type */ > > + valid_id:1; /* Is bpf_prog::aux::__id valid? */ > > enum bpf_prog_type type; /* Type of BPF program */ > > enum bpf_attach_type expected_attach_type; /* For some prog types */ > > u32 len; /* Number of filter blocks */ > > @@ -1688,6 +1689,12 @@ void bpf_prog_inc(struct bpf_prog *prog); > > struct bpf_prog * __must_check bpf_prog_inc_not_zero(struct bpf_prog *prog); > > void bpf_prog_put(struct bpf_prog *prog); > > > > +static inline u32 bpf_prog_get_id(const struct bpf_prog *prog) > > +{ > > + if (WARN(!prog->valid_id, "Attempting to use an invalid eBPF program")) > > + return 0; > > + return prog->aux->__id; > > +} > > I'm still missing why we need to have this WARN and have a check at all. > IIUC, we're actually too eager in resetting the id to 0, and need to > keep that stale id around at least for perf/audit. > Why not have a flag only to protect against double-idr_remove > bpf_prog_free_id and keep the rest as is? > Which places are we concerned about that used to report id=0 but now > would report stale id? What double-idr_remove are you concerned about? bpf_prog_by_id() is doing bpf_prog_inc_not_zero while __bpf_prog_put just dropped it to zero. Maybe just move bpf_prog_free_id() into bpf_prog_put_deferred() after perf_event_bpf_event and bpf_audit_prog ? Probably can remove the obsolete do_idr_lock bool flag as separate patch? Much simpler fix and no code churn. Both valid_id and saved_id approaches have flaws. -- Linux-audit mailing list Linux-audit@redhat.com https://listman.redhat.com/mailman/listinfo/linux-audit