Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2276468ybt; Tue, 16 Jun 2020 01:34:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0K0xPrQm1r8Lx8g4l0bPos78h7fNI8Wcw8Yq9ocBFin7sYwPTO/aiAU2TX/R4w0upuuqF X-Received: by 2002:a17:907:209b:: with SMTP id pv27mr1676330ejb.146.1592296471062; Tue, 16 Jun 2020 01:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592296471; cv=none; d=google.com; s=arc-20160816; b=dDrO/fhAAXZ20wfM4wkAYbYFN1yORzqVTotlZUJFtBF8xAq0ZMmTzinmfNCsGEZ09W MPEINbtEhZdSnhSOF5AXRv53Ngcwncf49indnnPIn5JkPHPwtNtHPlrWCcd1O7fN90JX UeyylekTsYVj0JT6toq9f/kY0z8+zDNqZwUZIzWF5ui7N7lfLer4J5rfGMXRYJgmy/Ez mMhj3sreRADysmfqRI/+wYTa7B/AQ5ogComwakHeNgh10rkoyCFb4+OfJn0EDd+7LOx+ NQzNlMQcXXbgGSL2fGluIKj5RFKL4b6vqWP1UuTYOeXsnoMgBdYE+L4V8e9XhWZOLUpI SM8A== 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=iFZu21anIecqeWnmtHDcKq9io7f3G/fD/2SgVahSB5o=; b=O4fKoaQgtGH+TwkXtXLFcAPImS6EEWGJ1j0hoRByEmT0Nf1XcuKjAs5YJuNL+zKGcs 98DvuIi7dRWWxmZQBVQVL1HqpmU46rJQOB6P8HMrtWsoQPpmoSCrKPzjOGFJCN3L1r+p TFLraSCguqnlHG5O35WRLFXB6umlwyJ8YGEkUXTJEZfPLON4lV3ye55b01s5zkzHL6GD jsU04LNBIDEbVLUYdcKGiRPezLlq8erR6Pbt/SfnBNlolfydOUfevDlK9MgZ20zSGlxc YTo8/U2VDaKysKoNpF5yIysTRfy3uto3p26cRgF05sokSbJdx7up0hwvZ3iwfIDosI49 dlXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=xNw2XJ3W; 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 a9si11156605ejk.553.2020.06.16.01.34.08; Tue, 16 Jun 2020 01:34:31 -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=xNw2XJ3W; 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 S1727932AbgFPIaY (ORCPT + 99 others); Tue, 16 Jun 2020 04:30:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbgFPIaU (ORCPT ); Tue, 16 Jun 2020 04:30:20 -0400 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 980DCC05BD43 for ; Tue, 16 Jun 2020 01:30:18 -0700 (PDT) Received: by mail-ot1-x343.google.com with SMTP id m2so15299653otr.12 for ; Tue, 16 Jun 2020 01:30:18 -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=iFZu21anIecqeWnmtHDcKq9io7f3G/fD/2SgVahSB5o=; b=xNw2XJ3W6+QRI42l+XFlKIs2oUp3ZMllemOdGovEuifvIF3kEWzDFTdYX+xBKVJZe0 XZ+aHBfFXcExTyTXZx2pwIo6GF3KWtHNfN0wD8alb7/4mqnwZMoxYoZfDZcDY6mRwH7X 1OI8kbUZYWXgNEdjExp8YSuk1HrapdVEoQ5v4= 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=iFZu21anIecqeWnmtHDcKq9io7f3G/fD/2SgVahSB5o=; b=eMsmfLGCpEE7+NduH8dSJ48ScKggHpc7+uq7sDgi79Xs8souyYRdF9vZ1XOx1DndQe sSjQtLqbGcgjuQPe7SjIfHYIsQPxjjIA/MI7jd5ckMS+9tSMQTc2e4PtLbUy2jLKtSdw iz127bTJEoWJLZL1r0JGyvQPPwaXZk9Mqgfj1wXYrMHWVMqZOeyUAIimD0T5MooY8vP0 xlG7XY+SfpOp9Gr2WkJyO0YwrYCcKH79SPp6MBFEupvqnfzbog8PnrAyYJNudgWHIOsx BxhTmGAeMKLhZT6VNNPwpOX852pxOjjefg7SNtZI9SpWzB8ogeBx2yxH8g6G7AesfvqF XkOQ== X-Gm-Message-State: AOAM5323ygsDpEE0xN2ClSgejkf0ua1opJ6kSu0vyQyiNKsIn1H1utdv R8+BMuWadVGxFcOZ/3Z2ATXHfrJplA88HLeowkY02g== X-Received: by 2002:a9d:5cc1:: with SMTP id r1mr1384294oti.147.1592296217878; Tue, 16 Jun 2020 01:30:17 -0700 (PDT) MIME-Version: 1.0 References: <20200612160141.188370-1-lmb@cloudflare.com> In-Reply-To: From: Lorenz Bauer Date: Tue, 16 Jun 2020 09:30:06 +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 Tue, 16 Jun 2020 at 04:55, Alexei Starovoitov wrote: > > On Mon, Jun 15, 2020 at 7:43 AM Lorenz Bauer wrote: > > > > 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) > > making flow dissector pass prog_fd as cg and lirc is certainly my preference. > Especially since tests are passing fd user code is likely doing the same, > so breakage is unlikely. Also it wasn't done that long ago, so > we can backport far enough. > It will remove cap_net_admin ugly check in bpf_prog_detach() > which is the only exception now in cap model. SGTM. What about sockmap though? The code for that has been around for ages. -- Lorenz Bauer | Systems Engineer 6th Floor, County Hall/The Riverside Building, SE1 7PB, UK www.cloudflare.com