Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1062039rwb; Wed, 26 Jul 2023 07:06:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlFAPVkFfZihInIrttl/4snSmlMb7jT22zJm1CcLMrsFKDFlf8p0XfXiKFKnaGQgHNOuHF7v X-Received: by 2002:a17:902:cecd:b0:1b0:3d03:4179 with SMTP id d13-20020a170902cecd00b001b03d034179mr2884420plg.6.1690380411236; Wed, 26 Jul 2023 07:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690380411; cv=none; d=google.com; s=arc-20160816; b=pJs/ibLUPI9WVFiZeuLC88vCv7m2njNeKsy0SFtLO+9V2W3a21DT8u+FAgE1n1U4kO XblwtEQhGR/NyhFdOs6ztUBcfDSiVsT06+qhqQKoWsK6Rl72HdU9N3n2XGRwl3IafnHM Xc2R4UtVDK5kIrppDwkM8DhyOWxbcWjvC2mienIQbaKKhJV3O5HumMIYMhv3l3mzZCMG DTDxWOUYXxvsJ0Kmd4hxIUVfhYMlJToXKMPoOwgUDXZlY5W3t68HANs+EUOibcDvp+vc pz2tJA7ye3lIyTYPclMvnvdzEKw8NzcpnL0ozsCc5PkynkIeTdkZPT7BYpP02ly4Z98D r0+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sHorn2FTxwc0GDGivshkp6+VTJEJlE83QxVA+vKmjNE=; fh=H6UQKSAqGHjb54pZqph1tH1MP6c6rOoC25f6obiXGjY=; b=WKkVnaUSnoFrwyDe/EtpLAQtnvyEWhYWVkoOeS3ni4x76XumQf1UunOJO3H8ibLgqa eAllUzlryR9NF8GFX10h+3pi2JbIBo4rvSV3v8l6xDxC5DmKt9r145lkZZz3Z7QoEQQD pZcVJU7a4UjED5bVabyPU/1NNsMnX3brEBO5BVFC/Akppa8t9Lp1HlCt5KdSW2DoHdqQ TopWl9dokciN6v8ivIsH+5NsNOSuhkW8aOL5VESkvQ8F6fKGTen24Z8UQzU0W2q0P/SV bjw9nv/yvQiOdWjW8WjzlQrivGa6NHDl3H5KXYreHLahRbJ87JSvRG+pshde8KFE1DAR W+AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QtqNqfpE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a170902db0200b001bbb5f82fecsi4342529plx.182.2023.07.26.07.06.37; Wed, 26 Jul 2023 07:06:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QtqNqfpE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234170AbjGZNjT (ORCPT + 99 others); Wed, 26 Jul 2023 09:39:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233009AbjGZNjR (ORCPT ); Wed, 26 Jul 2023 09:39:17 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 919BB213F for ; Wed, 26 Jul 2023 06:39:14 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2b9bb097c1bso6397971fa.0 for ; Wed, 26 Jul 2023 06:39:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690378753; x=1690983553; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=sHorn2FTxwc0GDGivshkp6+VTJEJlE83QxVA+vKmjNE=; b=QtqNqfpE1x1/0/UDSxEqRIfyyVp5wMDHWM4K+MqdPWDXaWnPNZ23aDH1w4ey7rt3fq koE1R4PoykZZ3WtvdpH0gebC9FGFI9CXVLTgrq0zRjQwNHeQjzB6sGSnUA6pSZLgdGvi ndrD70cwEd3c+e1nYlS73PNkpzS0qpTV5ymUqdqDkKTK0QNTgZF3SdRrffaJ0z8t7pdc k9jryvlx+EusM3TCaspE7FiJ7Z8v1y/03sg1uiguZMdRO1tbyNP/HcHIOzmF+I9a9Uf2 p6fluw7tX1PoZnlRruOJWB0AdgDobaaHWUb8uKlih3Iz823NB0HZJXAPVUZQqfSvqA0x mSTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690378753; x=1690983553; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sHorn2FTxwc0GDGivshkp6+VTJEJlE83QxVA+vKmjNE=; b=e8fLvC8/SQwt6C+PcFuCDQ/gDpNsly4V+TgfGzfK2HnFQvkZPOEylmrg6u0xqA64DM Yq2mWTZ+vW4nGReMt2iHsLUzbF4aIdjHolENZkfYimyK9wryihLlueo3OhmHvhhl4X0w dcNh+myjr39PYU4aAU4EVdgr85DRlawHFBo48bc72GNvOetKLH/mOTFi06cOTCjJtxNa Ozl74YWs/+vr+X/blyY0g0/QCRiDnQQS9y/zSVKxjoiK56KdeGOLiXZT155geyQZB87v gATzU0pRX41E7POkN/NhNZAlOLxM04gopF4oGTbnvKIjBFQzGk1RgnHkmQjJ6JMpgQXK x6mg== X-Gm-Message-State: ABy/qLbiHYMbML8ZKQZuw5vO3APGaVoJFrek6l7PsWT+KUgtqlA6r4pE ETchGmYVpskDLMJjLjAXlkX0SQ== X-Received: by 2002:a2e:2e16:0:b0:2b6:c818:a9bc with SMTP id u22-20020a2e2e16000000b002b6c818a9bcmr1560633lju.23.1690378752781; Wed, 26 Jul 2023 06:39:12 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id n12-20020a7bcbcc000000b003fbb346279dsm1986398wmi.38.2023.07.26.06.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 06:39:12 -0700 (PDT) Date: Wed, 26 Jul 2023 16:39:08 +0300 From: Dan Carpenter To: Yan Zhai Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Mykola Lysenko , Shuah Khan , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@cloudflare.com, Jordan Griege , Markus Elfring , Jakub Sitnicki Subject: Re: [PATCH v4 bpf 1/2] bpf: fix skb_do_redirect return values Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I'm not positive I understand the code in ip_finish_output2(). I think instead of looking for LWTUNNEL_XMIT_DONE it should instead look for != LWTUNNEL_XMIT_CONTINUE. It's unfortunate that NET_XMIT_DROP and LWTUNNEL_XMIT_CONTINUE are the both 0x1. Why don't we just change that instead? Also there seems to be a leak in lwtunnel_xmit(). Should that return LWTUNNEL_XMIT_CONTINUE or should it call kfree_skb() before returning? Something like the following? diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 11652e464f5d..375790b672bc 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -112,6 +112,9 @@ void netdev_sw_irq_coalesce_default_on(struct net_device *dev); #define NET_XMIT_CN 0x02 /* congestion notification */ #define NET_XMIT_MASK 0x0f /* qdisc flags in net/sch_generic.h */ +#define LWTUNNEL_XMIT_DONE NET_XMIT_SUCCESS +#define LWTUNNEL_XMIT_CONTINUE 0x3 + /* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It * indicates that the device will soon be dropping packets, or already drops * some packets of the same priority; prompting us to send less aggressively. */ diff --git a/include/net/lwtunnel.h b/include/net/lwtunnel.h index 6f15e6fa154e..8ab032ee04d0 100644 --- a/include/net/lwtunnel.h +++ b/include/net/lwtunnel.h @@ -16,12 +16,6 @@ #define LWTUNNEL_STATE_INPUT_REDIRECT BIT(1) #define LWTUNNEL_STATE_XMIT_REDIRECT BIT(2) -enum { - LWTUNNEL_XMIT_DONE, - LWTUNNEL_XMIT_CONTINUE, -}; - - struct lwtunnel_state { __u16 type; __u16 flags; diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c index 711cd3b4347a..732415d1287d 100644 --- a/net/core/lwtunnel.c +++ b/net/core/lwtunnel.c @@ -371,7 +371,7 @@ int lwtunnel_xmit(struct sk_buff *skb) if (lwtstate->type == LWTUNNEL_ENCAP_NONE || lwtstate->type > LWTUNNEL_ENCAP_MAX) - return 0; + return LWTUNNEL_XMIT_CONTINUE; ret = -EOPNOTSUPP; rcu_read_lock(); diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 6e70839257f7..4be50a211b14 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -216,7 +216,7 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s if (lwtunnel_xmit_redirect(dst->lwtstate)) { int res = lwtunnel_xmit(skb); - if (res < 0 || res == LWTUNNEL_XMIT_DONE) + if (res != LWTUNNEL_XMIT_CONTINUE) return res; } diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 1e8c90e97608..016b0a513259 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -113,7 +113,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff * if (lwtunnel_xmit_redirect(dst->lwtstate)) { int res = lwtunnel_xmit(skb); - if (res < 0 || res == LWTUNNEL_XMIT_DONE) + if (res != LWTUNNEL_XMIT_CONTINUE) return res; }