Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1720269ybt; Mon, 15 Jun 2020 07:46:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDnQBaYeBSD3cZovFkLkHUxcGRVDWSLiRvTKPRyZOx+RGFOUt63cUexL9GqO9OKJayguqF X-Received: by 2002:a50:fe0d:: with SMTP id f13mr24542385edt.204.1592232365684; Mon, 15 Jun 2020 07:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592232365; cv=none; d=google.com; s=arc-20160816; b=q4emuq1e/0jsbwfqLkcmO7RafjbjWvLHvim/+jENFv5aemu7x8xU5kVVsiR9CVnL/R 3tjtCDEjHMzeBgSLqMwPWJgirmRjJ2T+gaJb9nQOA9wbWamekCX6NUo+0313T1r6hooT HJXS49B0vTBlltHnsN3us7ainLgRWypDm9vIkhty1qplNUdpfVOrYMztyRLfzZNYX76/ Goa+zR7jyv3f1pA1vY+KKXwL+IOWd2aK3TWLZ/OvYiEPuqMsbHd3FD+KzNZKJyBaWUaH bMLOhfwKiD1Ic6WY8JGNAXq2GU3IYwpMoeBdJFH4xt1FseFeDRehBYIfdlAFQpb7OjJC /8TA== 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=r8im4dJtuxkkAaqZZS6bmcni2naI0KL21K/0KZhRnTg=; b=qw1JxtLvChsDJEaxTsNEhr0wyvUyuP2w7zryN1dv/siV6HMrIBxJnyillXs4UgstG4 5mX7zGGCHbuxe14Cda7aueln5fp2c/d+xpYrOGMnftRs/zFgdfqBiiKZovXmR9MnpJzk tmKs05hv60SpaDqR1rNo6T+0maE8D09vE2xEV6/qTYBfzZNLbzcnFYvo7MtEJwFaudZ/ /dELrDDppm+X5FyV9++7qNo5vYPqYL4YD8TYwqVjyyNJNQYgUP4+AuaVW6BfTRO4XrS6 zx+vRYlcksykkUbHz25M7sKBVf2mCh+Sqt82uGRDP1NIvVPDhZ5zU5pKUdhad4ICHH3X e/uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=Kvpm8lif; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si8240558edr.463.2020.06.15.07.45.43; Mon, 15 Jun 2020 07:46:05 -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=@cloudflare.com header.s=google header.b=Kvpm8lif; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730735AbgFOOn7 (ORCPT + 99 others); Mon, 15 Jun 2020 10:43:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730213AbgFOOn6 (ORCPT ); Mon, 15 Jun 2020 10:43:58 -0400 Received: from mail-oo1-xc42.google.com (mail-oo1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E73C0C061A0E for ; Mon, 15 Jun 2020 07:43:57 -0700 (PDT) Received: by mail-oo1-xc42.google.com with SMTP id 127so1105358ooc.9 for ; Mon, 15 Jun 2020 07:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=r8im4dJtuxkkAaqZZS6bmcni2naI0KL21K/0KZhRnTg=; b=Kvpm8lif52moFLeMmaNKGAHoyXK5aBJWB+oAUhzGn06yJXqIvn/PnfObLHY9dxrmon 3LBcru7CGHTqvQ2q9h7SG/2RHOsw3K4VKzqDapSU6QXnYY72ZBKse0+FifGxXpmZGSa2 WqECeuk02tQWmywJxEP3fjo9i0CJIQPSkhfB4= 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=r8im4dJtuxkkAaqZZS6bmcni2naI0KL21K/0KZhRnTg=; b=H0KGKUKI9Lb8jEAUrvfUe159Zoy0oMOCQ9QbfZ3hT7z14ErXbEJ4kdAbowD9695jvU akVfr1dtHN3IOZrONYeYzJnVwi8Al4IZKdRKLu2KOfALpcT14rPisw5l1grajI/pgex1 Gh+frCc3jwObMWrTIBzArs2oN4MwubZsJPNDgqCEymQlQsPzya+fIPLRgAHWeHlyxxsY pIcmTLRX2aVD5sj7xNjmTUy8dqXfwmWvAgGc0YBnS91qDwh42RtZ0O2hWznJqiIJgjY8 Qq9Hq2sA8jjWs+xWR2AtCqNmDr9PI4XCkwGaVQW4VGNDVVWqDGx1niki9UWrRgTxzWIn AmEw== X-Gm-Message-State: AOAM530wekeMsXXI3COA4Gz3pDJz762e3GWSerkMwewU1WHYIAVhOt1m P5LSHgNsDIIY0bNgPmB/iWJHSYQTqzLYMzXoXSBS3Q== X-Received: by 2002:a4a:3559:: with SMTP id w25mr21208459oog.6.1592232236922; Mon, 15 Jun 2020 07:43:56 -0700 (PDT) MIME-Version: 1.0 References: <20200612160141.188370-1-lmb@cloudflare.com> In-Reply-To: From: Lorenz Bauer Date: Mon, 15 Jun 2020 15:43:45 +0100 Message-ID: Subject: Re: [PATCH bpf 1/2] flow_dissector: reject invalid attach_flags To: Alexei Starovoitov Cc: Alexei Starovoitov , Daniel Borkmann , Jakub Sitnicki , kernel-team , Network Development , bpf , LKML 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 Fri, 12 Jun 2020 at 23:36, Alexei Starovoitov wrote: > > On Fri, Jun 12, 2020 at 9:02 AM Lorenz Bauer wrote: > > > > Using BPF_PROG_ATTACH on a flow dissector program supports neither flags > > nor target_fd but accepts any value. Return EINVAL if either are non-zero. > > > > Signed-off-by: Lorenz Bauer > > Fixes: b27f7bb590ba ("flow_dissector: Move out netns_bpf prog callbacks") > > --- > > kernel/bpf/net_namespace.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/kernel/bpf/net_namespace.c b/kernel/bpf/net_namespace.c > > index 78cf061f8179..56133e78ae4f 100644 > > --- a/kernel/bpf/net_namespace.c > > +++ b/kernel/bpf/net_namespace.c > > @@ -192,6 +192,9 @@ int netns_bpf_prog_attach(const union bpf_attr *attr, struct bpf_prog *prog) > > struct net *net; > > int ret; > > > > + if (attr->attach_flags || attr->target_fd) > > + return -EINVAL; > > + > > In theory it makes sense, but how did you test it? Not properly it seems, sorry! > test_progs -t flow > fails 5 tests. I spent today digging through this, and the issue is actually more annoying than I thought. BPF_PROG_DETACH for sockmap and flow_dissector ignores attach_bpf_fd. The cgroup and lirc2 attach point use this to make sure that the program being detached is actually what user space expects. We actually have tests that set attach_bpf_fd for these to attach points, which tells me that this is an easy mistake to make. Unfortunately I can't come up with a good fix that seems backportable: - Making sockmap and flow_dissector have the same semantics as cgroup and lirc2 requires a bunch of changes (probably a new function for sockmap) - Returning EINVAL from BPF_PROG_DETACH if attach_bpf_fd is specified leads to a lot of churn in selftests Is it worth just landing these fixes on bpf or bpf-next without backporting them? -- Lorenz Bauer | Systems Engineer 6th Floor, County Hall/The Riverside Building, SE1 7PB, UK www.cloudflare.com