Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp559472rdb; Sat, 19 Aug 2023 13:05:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEopYRruBrcMpL17/SzucT3n9t7C8bTpYPJWvLgfIfxlC7uBonvbAL/y1h9vo2CwL6i+2xf X-Received: by 2002:a17:90a:51e3:b0:26d:4a80:b075 with SMTP id u90-20020a17090a51e300b0026d4a80b075mr3964339pjh.11.1692475555715; Sat, 19 Aug 2023 13:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692475555; cv=none; d=google.com; s=arc-20160816; b=PlI/PliKGTHQU4kVKDmigVdpQ72L6Nr4FBiXDxL9FqbMAMrd8SsM/nZnvHfdAo2IKf 6eCLMbCJsVBqqU78LXxCaHpiYymQfOa3FDUGK8f0C8YpcBo9skPu2BIJv0JOXPaFW90G eua1SrDUph6EXaRzTWMNQNcm/1LzhzpvYmT15MUAsX4k7KAPP2HIeDeb2GJ2MGtSMCOF sV67Qcm4r9f3ygj0GzkrIcZogn4zVbf8zzOP0dZ+/GOQfg2tx24eyzBFWTNl0kmL34aJ h9kmh3vShRLQmcEJVyYJ701pEDyCIdySzfilOSVPGu7k7PqYWlspxrDowcqPex5ayxgh /3XQ== 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=PlkFhJjPZ+nVOvUd+Bq8Pm9xKRLhY4/ZIov2TViDPGA=; fh=HO5udTTwDx8oe+ugKc7gb3jXUBLlwRGWTxAztTNKo2s=; b=G2c7ft0etJlrBw/bs2di/lAsEcZtR7hM929c+MJDijxX59TKKe9Ci0b0zDaPieblwk UPq1Cr6ObvabbxgXI2N0cuHg3w8Tvda67EDNDAAq/syGw/NzRlJNxGcIctfY2wG7A8/j D4eQeruja8LJEfeeVREapvvMxyuTelFLSTj7J8jF8w0cozL3pYU56BSPkqqRbQDUgRPV tvX2QbQMlB19utc47U34I37M+hJBPHPp2rOPH83DBKVmSpAD9xEGRYB6xAQnlRwZUlmL SIFmaJ9fAgC3erOP0yRs4dkhUxEYy6fZnyqifUp0KWK1i+KL1dbUUByPKKa8n1Ajdy5/ mLPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=u0crk9vG; 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 p18-20020a17090b011200b0026cab818aa2si5593231pjz.100.2023.08.19.13.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 13:05:55 -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=u0crk9vG; 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 830428E385; Sat, 19 Aug 2023 01:38:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241399AbjHPCzu (ORCPT + 99 others); Tue, 15 Aug 2023 22:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241426AbjHPCzd (ORCPT ); Tue, 15 Aug 2023 22:55:33 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC6722698 for ; Tue, 15 Aug 2023 19:55:25 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id 6a1803df08f44-6424c61c80eso19667136d6.1 for ; Tue, 15 Aug 2023 19:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1692154525; x=1692759325; 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=PlkFhJjPZ+nVOvUd+Bq8Pm9xKRLhY4/ZIov2TViDPGA=; b=u0crk9vGr/nqq4DRoRfsmHXKIisixdAHqHTsS1KMoVwfubQuVk0JmLH7NclBlUCzwP GVP/G00X4Kfqdn6GNdCAunGqtZAtgZ0V0eUK0jkq68HAlYeRZeYac/6KOjVfyyxP/QjU lFKCEbNa2yP5IuAQCD/x011qQerffKA17z1cU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692154525; x=1692759325; 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=PlkFhJjPZ+nVOvUd+Bq8Pm9xKRLhY4/ZIov2TViDPGA=; b=ZHwVE7suF/OycN15v6SVDxImrsJVlm/kcnqT4wd5vaZDRElFQyFNKwhkXA/Q3tdH/d 5xDDfeOQ9iTT9rxJxfoJoe1qqHeMH1GaVTa24z4+/N8pVtPWI8LoQNXuEqlGQJAnbW5W PSbvH8O00AFtwPRglAWBVgjCy87ibusfm8ZcuFaqpBc3y1FmSN1Y7DG+x5X8U0BSyIvT nMNrQjHgvfpRZFMHYdrOoBvBJr5848jFqELGNlNCOmwCn/QIwP95wMKySjJtGhnN89g5 D7WFBygrphqBV/K7k+WXB0u4wGnV6uj/Jj/2GEObi1+DHQHNfNj1ZTIHtnQugkLPF9ym W2uQ== X-Gm-Message-State: AOJu0YzZ8d8mULFiX0XzGLoA6MJNf9M6VOyYAeUvBb/T+135cpy4Eejd pH/iObGx6P7IBlEdkMf2NT29qw== X-Received: by 2002:a05:6214:500b:b0:63d:580:9c68 with SMTP id jo11-20020a056214500b00b0063d05809c68mr5481820qvb.32.1692154524793; Tue, 15 Aug 2023 19:55:24 -0700 (PDT) Received: from debian.debian ([140.141.197.139]) by smtp.gmail.com with ESMTPSA id i4-20020a0cf384000000b006300722883fsm4576015qvk.33.2023.08.15.19.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Aug 2023 19:55:24 -0700 (PDT) Date: Tue, 15 Aug 2023 19:55:21 -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, stable@vger.kernel.org Subject: [PATCH v5 bpf 2/4] lwt: check LWTUNNEL_XMIT_CONTINUE strictly 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,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, particularly if dst_output statuses are directly returned. 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