Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp722201rdb; Sat, 19 Aug 2023 23:07:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGAIiVqc/fFZKq0tUkbbjshpNhNZ6+v5LD8xq23i2TmgvWX8KjSIRT3qpYW/k25tHPOzjne X-Received: by 2002:aa7:88c8:0:b0:687:8f50:47c8 with SMTP id k8-20020aa788c8000000b006878f5047c8mr4410806pff.1.1692511632152; Sat, 19 Aug 2023 23:07:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692511632; cv=none; d=google.com; s=arc-20160816; b=Ch8HhhF18PQJOTZXBflvUlmgORk5kjuRUK/ZkCvM5w4Y1o1qHf3IzzxXURwPrVOMIv ngpl6mY63GImCgTiKkdOI4RUmii3jtwwQJ3h1MfKFZIgNli/BShrRYQ6H09SEqxSe9w0 w+JPeg8k/xg7r3+/PZRiIKkmgv6FJZXv26kaDHuYAPOhNvlzfB6fiDWE22qRYvL+sRZ+ v9CaYpETZqEwymalsD4J0zKAPYBfWKLvDgAiFYB1snSV3V8EVmLljDt+kUN9vrLXOFpZ 6Bj4LVQ2VD805ywrJJYH7CbaWUy8iH/QISIKOkEkJJeu99AoQu+ThYwrrplY4AHNsTHW DnRw== 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=t1rveI8qZCR4C4wEbefcxj73KFhEoSnYcRQTDwgiQK4=; fh=yeb3Mmoj9+0E4qiEJEh46aVT+nBpZTUw6rxccJAgZ14=; b=agFsmy4PX0IEfPpE4wrJe5/vPBH58Oin83kHHGXVhsN9SjwXgChWpYzN8KGWKA9R5T MB/p43othnL1lj85roVx4prS7IuJsXeEsVoxyTc6ctog1ogfmeZGWXM7dlMnwU1cKEkK QtPd/2SOhRnCFUNPFAH8xMwsIKD/BG5fWFzcutVGPmA0l8nCxKivmEi82VINtsjKhYy8 TWDlnDx5CAzHGXJDv1GZRK5LhkIu8rZ1qXYU+8DxSkXXGhDFY0c6mP1anQp087MWxYKg nRmnqLycovoYG0LSuE1q2/Hnf2ZOvnEcDxLWUN0AKv48OSEM9x09Ez4VBLcrOgHIEWwl h6aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=WQimjvM9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i197-20020a639dce000000b00565323c82a1si4360926pgd.548.2023.08.19.23.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 23:07:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=WQimjvM9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0DA962A96DC; Sat, 19 Aug 2023 11:46:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357360AbjHRC6a (ORCPT + 99 others); Thu, 17 Aug 2023 22:58:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357345AbjHRC6S (ORCPT ); Thu, 17 Aug 2023 22:58:18 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED8B1210D for ; Thu, 17 Aug 2023 19:58:16 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-64189860374so2415126d6.0 for ; Thu, 17 Aug 2023 19:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1692327496; x=1692932296; 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=t1rveI8qZCR4C4wEbefcxj73KFhEoSnYcRQTDwgiQK4=; b=WQimjvM94ux9B2GBJcDjxNN5CkfPSEt71Ija0YYQ3vdFMYAD9FTBOwEw7+LGPn2WXw /jP2CNqXbUtqXqJ6bDq/sqomHkPUSAde1yqm7ATlWBGqpYwyKtBBhUy0dbwBVKp6erAL Jzn59/doHMy+T6peWT9DJZLX+CC4ogZgBYM9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692327496; x=1692932296; 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=t1rveI8qZCR4C4wEbefcxj73KFhEoSnYcRQTDwgiQK4=; b=OxmKfWOHkrZlzYmMYHmRL8pG3k2SfceBi+EQCdVWq3oNalbxbUlMiapHo2snLetKU7 dkVlLd83vjC6g+c1SJPlq6XA6DQapLFmFX0x+zub2nsUPaXMQ4unaQozO3ecj9xCLKXl d2Z8lcI1HwyujWi1kf7lXNStok5Nja4jL3wkYj5L82xHVnCmnnS+oIIPpqf36R61Nz00 UQQM96c42ntojTJnDhQ5049VLduhvO4rFTQa6sIbYMh3/ZtedOr8IeXc5s1VYnsSrsUk noUoD/HJ8CmpC/78va7q8oFJcAcjB6BVb3ZYMNiamdEQcFnVK+vIXfjlAoce9/S4Ysww +8Fg== X-Gm-Message-State: AOJu0Yx2sBUBnbX/8wVAIzWZ1bebN8ZF5W+QEfpfpRLXfQ4cyfutS7YB SjM2Hj7ZGrubvRbXQvjGlqumwQ== X-Received: by 2002:ad4:4ba4:0:b0:64a:bff7:90e6 with SMTP id i4-20020ad44ba4000000b0064abff790e6mr1258205qvw.65.1692327496080; Thu, 17 Aug 2023 19:58:16 -0700 (PDT) Received: from debian.debian ([140.141.197.139]) by smtp.gmail.com with ESMTPSA id w14-20020a0ce10e000000b006427145590csm347998qvk.48.2023.08.17.19.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 19:58:15 -0700 (PDT) Date: Thu, 17 Aug 2023 19:58:14 -0700 From: Yan Zhai To: bpf@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , Yan Zhai , Thomas Graf , Jordan Griege , Dan Carpenter , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v6 bpf 2/4] lwt: check LWTUNNEL_XMIT_CONTINUE strictly Message-ID: <96b939b85eda00e8df4f7c080f770970a4c5f698.1692326837.git.yan@cloudflare.com> 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,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=unavailable 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 LWTUNNEL_XMIT_CONTINUE is implicitly assumed in ip(6)_finish_output2, such that any positive return value from a xmit hook could cause unexpected continue behavior, despite that related skb may have been freed. This could be error-prone for future xmit hook ops. One of the possible errors is to return statuses of dst_output directly. To make the code safer, redefine LWTUNNEL_XMIT_CONTINUE value to distinguish from dst_output statuses and check the continue condition explicitly. Fixes: 3a0af8fd61f9 ("bpf: BPF for lightweight tunnel infrastructure") Suggested-by: Dan Carpenter Signed-off-by: Yan Zhai --- include/net/lwtunnel.h | 5 ++++- net/ipv4/ip_output.c | 2 +- net/ipv6/ip6_output.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/net/lwtunnel.h b/include/net/lwtunnel.h index 6f15e6fa154e..53bd2d02a4f0 100644 --- a/include/net/lwtunnel.h +++ b/include/net/lwtunnel.h @@ -16,9 +16,12 @@ #define LWTUNNEL_STATE_INPUT_REDIRECT BIT(1) #define LWTUNNEL_STATE_XMIT_REDIRECT BIT(2) +/* LWTUNNEL_XMIT_CONTINUE should be distinguishable from dst_output return + * values (NET_XMIT_xxx and NETDEV_TX_xxx in linux/netdevice.h) for safety. + */ enum { LWTUNNEL_XMIT_DONE, - LWTUNNEL_XMIT_CONTINUE, + LWTUNNEL_XMIT_CONTINUE = 0x100, }; diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 6ba1a0fafbaa..a6e4c82615d7 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; } -- 2.30.2