Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp410833rwb; Tue, 25 Jul 2023 18:24:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlHQjiQ0qVan3S3BVxY8TJItg6/ilUslIZwpNoiawX4Y3b7NmtEQTb1SMzX94ycoTV2ikrOr X-Received: by 2002:a17:906:7795:b0:965:6075:d100 with SMTP id s21-20020a170906779500b009656075d100mr430302ejm.39.1690334648911; Tue, 25 Jul 2023 18:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690334648; cv=none; d=google.com; s=arc-20160816; b=Dzxm4uybTgCEzNtUvVh3c6M8Bel9QicmQudqIyX3RUFnSbc5PgBnDmsTXeBHmT/DSh YtIZYXx78ZOzUrboEzBoBM59oV6N7EiUPDYQa+ATpI0mnXf8VnUfp+fstxl5CFmVrgax sDT1naw71bue8o8NoRixPSl+1Wg1dWL/x0AN1jjdPixepH88imphuKe2rUQN35lGhvKm weEWbJIwgdX2fFsXpnReweO05IU+TQjLY4N3nGLC6eu9pkTDGoknGVOS7z1q4e4QWVZ7 ATTOv1Ym1WtMq8uL9Mh3f4gtTpYMVjaV0DWyBEvZT9EnQjBfX/o603sSwWtDIw1Qte9X A55w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=BdwBWxmoC8jWTGG50vXsFsrbHYhobVYe8zMui4535MQ=; fh=tUEnnqvJ+JVPmX9GZQRvTnGoIyUPZkQwh65YlQvUPUo=; b=Zveg6x9N6h63OJukp/qVwCzN5LZsNkF8lJ31O44hoODJdSCdfgr9//vhtNsThu1qfp Q2d9GtDYEKHgpndMEG2RHuBURdL4j7BHTiBEsfsxoEtjJfRhh12b+M/Ed5HHiMmqz5ho ms1frQdHEBh1uz9PMQ5P2P1LsjQUTHWBoEwcsTsFgyqzVQSS2L4TJsNsAnjM1NYL9nlN 4vvm7u8G18cw7BxEuKnnjpJx1TV//kWWf8OJMecjCx4zxksigNyT0QNvQl+TQEknTsdy yGBLPcjedtCtZpzFTzeUXq31bZ9PN9Q6N38fEqZnLP9Xm1mdX4J+dxpx1iBbOc+3DNKr yj8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=XA63LcB9; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mc13-20020a170906eb4d00b00991ddce682esi8407474ejb.305.2023.07.25.18.23.44; Tue, 25 Jul 2023 18:24:08 -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=@cloudflare.com header.s=google header.b=XA63LcB9; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbjGZBHL (ORCPT + 99 others); Tue, 25 Jul 2023 21:07:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbjGZBHK (ORCPT ); Tue, 25 Jul 2023 21:07:10 -0400 Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC159212D for ; Tue, 25 Jul 2023 18:07:08 -0700 (PDT) Received: by mail-vs1-xe36.google.com with SMTP id ada2fe7eead31-4452fe640fbso1329863137.0 for ; Tue, 25 Jul 2023 18:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1690333628; x=1690938428; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=BdwBWxmoC8jWTGG50vXsFsrbHYhobVYe8zMui4535MQ=; b=XA63LcB9VKrUs3pNggkpMfJamzRch4vGpdmmh6PwlAH3APOY7XGBx0fy8etlhxP1lz Q52+dLUQNIc/9qZ06aIc2H1T3NnY9UtzyAXLAl/zzzu6XeiBtdBEhggxvBYqcUs3hDPe 0oaywFZ21cnoBDtVPm9np78YHPOHUZk+HDBO0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690333628; x=1690938428; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BdwBWxmoC8jWTGG50vXsFsrbHYhobVYe8zMui4535MQ=; b=FUgPSo6ociIE8Fdq1bJjYeSRV8pdeOtofRL7Tf7JZB5HGD7B6DnGdIrBTbh1sG7LgN 7ZXZlOQpbjuyZUU0pilLfVRpVPCuROfO7ZSCCpf3tBxIuVFZO2qlAc64D2EdoWGI2Zxt VQgPTjSfds3ZMYTXjmxvBLBuMftpZijC0EJj9cmfPslU9qX2wMZlL1wTVdJ6J/IC0uNf 3v3YQjHuk1fn3pdl23n9HN9i4txvCDzL3ZEI/+Q2Kc6EZX+pAAkYvFwwzOdFahgdAb2Y f+6gJEZWFMuKEuB//yiLHrkawnjwtac+5xUw5+b2dSBFSH70CmD2zve21JGydOvDqo1X mKAQ== X-Gm-Message-State: ABy/qLZ9nPiXBbhGu3FbKT2Q6FsJ73jQb2S9dHPbxbLI6o8JuC0vMC0G mqX6HI44A9QK9XVmFC8H5GqwBg== X-Received: by 2002:a05:6102:282e:b0:443:7572:598b with SMTP id ba14-20020a056102282e00b004437572598bmr275284vsb.13.1690333627937; Tue, 25 Jul 2023 18:07:07 -0700 (PDT) Received: from debian.debian ([140.141.197.139]) by smtp.gmail.com with ESMTPSA id e7-20020a0ce3c7000000b0063757aea986sm4710610qvl.28.2023.07.25.18.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 18:07:07 -0700 (PDT) Date: Tue, 25 Jul 2023 18:07:04 -0700 From: Yan Zhai To: bpf@vger.kernel.org Cc: 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 , Yan Zhai , 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: [PATCH v4 bpf 0/2] bpf: return proper error codes for lwt redirect Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,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 lwt xmit hook does not expect positive return values in function ip_finish_output2 and ip6_finish_output2. However, BPF redirect programs can return positive values such like NET_XMIT_DROP, NET_RX_DROP, and etc as errors. Such return values can panic the kernel unexpectedly: https://gist.github.com/zhaiyan920/8fbac245b261fe316a7ef04c9b1eba48 This patch fixes the return values from BPF redirect, so the error handling would be consistent at xmit hook. It also adds a few test cases to prevent future regressions. v3: https://lore.kernel.org/bpf/cover.1690255889.git.yan@cloudflare.com/ v2: https://lore.kernel.org/netdev/ZLdY6JkWRccunvu0@debian.debian/ v1: https://lore.kernel.org/bpf/ZLbYdpWC8zt9EJtq@debian.debian/ changes since v3: * minor change in commit message and changelogs * tested by Jakub Sitnicki changes since v2: * subject name changed * also covered redirect to ingress case * added selftests changes since v1: * minor code style changes Yan Zhai (2): bpf: fix skb_do_redirect return values bpf: selftests: add lwt redirect regression test cases include/linux/netdevice.h | 2 + net/core/filter.c | 9 +- tools/testing/selftests/bpf/Makefile | 1 + .../selftests/bpf/progs/test_lwt_redirect.c | 66 +++++++ .../selftests/bpf/test_lwt_redirect.sh | 174 ++++++++++++++++++ 5 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/test_lwt_redirect.c create mode 100755 tools/testing/selftests/bpf/test_lwt_redirect.sh -- 2.30.2