Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7692001rwp; Tue, 18 Jul 2023 21:25:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlEK+biEq9w42VsK/VsukTQFEJBtZW4v+HDJycVCVQKxjwA5yVHQJRXo46yjjiWok/AfZ3K8 X-Received: by 2002:a17:906:3109:b0:993:e2ba:a7b0 with SMTP id 9-20020a170906310900b00993e2baa7b0mr1184872ejx.24.1689740714438; Tue, 18 Jul 2023 21:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689740714; cv=none; d=google.com; s=arc-20160816; b=y3GpkVTAIl7YgJfkO27cFhzjjjXJQwKbxLFLtAWSvAwpNU/daki2toC5Ujq3PKRYb/ IGxJW+K5ovA2fyKC9DhEgpqgR+eb7UvY6M5x0YhTPHyUIGpKgA9zg4L8EsTJQmeCJmsn ACjNgS8wCgxOrhAi0Ps8eH/IFjaCMieamDtF183/uoVeMhjmT3Hnzeze8Uc1f6h91mh5 REYlUbiaw2W7TM8erJKSozIuynzUxlAviVNwZGa8GvmkPJGv4IBjccktVLWmRhspKXoN wKfaXTF4xcLgL8L254R79ChyLGgKAVAhGx8wwxG2YyHiDKaZ6/VWSdq5JlF/fr9/GmU1 b/iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=N6nGe3/14lsIlAFKvEfl97Na5N58gbsjqham6f34LTI=; fh=tHXo7DB5bH0HZBbN/EF2MLOVmEDR3EX60IbSdM+LKZY=; b=zg9bJIpPvlGjeO9SgM1sqjgzJqwVa2URKumBYXFCqYSshh6gj06MIFkp9VIQC0PjvF oDuFKTkc6Ux9JxbU51Qds/hKgLyXK09z8ZnN3CcyNL1TFJbQTfrJN7i/xIMSk94W+8Ew h2m20lZrGBxpayBYl+rZsVZpgEWNHd0w1Klc1PiZoMj/rPDJES252FT3ZKP3ozWmvRvk uNxkOdBnVZGj++C2gYg+1AoAtJUlYZTrR3EDOhKGRMmUGb/Co2WIaArHzc895Lwnli+l TUnXPyt6YSRVZjL6SCuwmEa105EPkZHXBJjCAIhT9PBzd7ojVMdxBbqpbe0GkOzRcQwG o2Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=Wv+4+oXQ; 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 kb7-20020a1709070f8700b009944e912852si2177734ejc.429.2023.07.18.21.24.50; Tue, 18 Jul 2023 21:25:14 -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=Wv+4+oXQ; 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 S230393AbjGSDV5 (ORCPT + 99 others); Tue, 18 Jul 2023 23:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjGSDVz (ORCPT ); Tue, 18 Jul 2023 23:21:55 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16FE01BF7 for ; Tue, 18 Jul 2023 20:21:54 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-51e5d9e20ecso9087992a12.1 for ; Tue, 18 Jul 2023 20:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1689736912; x=1692328912; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=N6nGe3/14lsIlAFKvEfl97Na5N58gbsjqham6f34LTI=; b=Wv+4+oXQl7HjDsiJtgHXbRji7FkiAndbYjBdgI+lOTSTnCWTHSki+QPrxMg/vtOvSh r0iVYBxIjy3Wga8epsor/VmNiFFJfTXP91/upI7QJ6eJAQP/0Hw1HIJ0gpgAlpCrutQS sDkFj3Jo4/KxP8goc1v6ulCxpyCWDxYCc/Do0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689736912; x=1692328912; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N6nGe3/14lsIlAFKvEfl97Na5N58gbsjqham6f34LTI=; b=KcZK0UQQD4pYBVktZ5oTGOXPe6GDCMirj2qtgsphRkz+So0lM446c2gUno4Y3HRYMV lNFoR3YdmiLg0eV7HoyVaAucHxIten8jTFr+G6hmG0+HUvbv9nIuCkdR8MnROHKqAYkT lyVX5gIplULBlVbbBYOTWh5psSeTHraYKPIrInz9rmRAy6fXZ6gwp7OS85JMuovWugrm JQkIDv1M8XFW1yoACS29BC7/Lia9ord1qWfTODdmyrsQEA27OavXM0RX5liecbLpYmOM 6x82YNS/neHQzthTVOFSRg/yqjBD6wPhqg7jEttWna7iBQY4ws1wk4CFmrxVMQsMvMR2 /MoA== X-Gm-Message-State: ABy/qLa8quXyzZ18avXqneZkFBLVoZDEncZHyYVOUncKrcNP6kkr4YJG 85sWZgmPFH43msE/uWP3IOQ6pk59j4IcrhL4rihNoA== X-Received: by 2002:aa7:d384:0:b0:51e:309:2e11 with SMTP id x4-20020aa7d384000000b0051e03092e11mr1453872edq.36.1689736912402; Tue, 18 Jul 2023 20:21:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Yan Zhai Date: Tue, 18 Jul 2023 22:21:41 -0500 Message-ID: Subject: Re: [PATCH] bpf: lwt: do not return NET_XMIT_xxx values on bpf_redirect To: Stanislav Fomichev Cc: "open list:BPF [NETWORKING] (tc BPF, sock_addr)" , kernel-team@cloudflare.com, Martin KaFai Lau , Daniel Borkmann , John Fastabend , Alexei Starovoitov , Andrii Nakryiko , Song Liu , Yonghong Song , KP Singh , Hao Luo , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "open list:BPF [NETWORKING] (tc BPF, sock_addr)" , open list , Jordan Griege Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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,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 On Tue, Jul 18, 2023 at 3:29=E2=80=AFPM Stanislav Fomichev = wrote: > > On Tue, Jul 18, 2023 at 11:22=E2=80=AFAM Yan Zhai wr= ote: > > > > skb_do_redirect handles returns error code from both rx and tx path. > > The tx path codes are special, e.g. NET_XMIT_CN: they are > > non-negative, and can conflict with LWTUNNEL_XMIT_xxx values. Directly > > returning such code can cause unexpected behavior. We found at least > > one bug that will panic the kernel through KASAN report when we > > accidentally redirect packets to a down or carrier-down device at lwt > > xmit hook: > > > > https://gist.github.com/zhaiyan920/8fbac245b261fe316a7ef04c9b1eba48 > > > > Above bug is hit because NET_XMIT_CN is returned by noop_qdisc of the > > down device, and it propagates from dev_queue_xmit all way to the lwt > > logic. Although skb has been freed by the qdisc, it still continues to > > neighbor subsystem and triggers the bug. > > > > This change converts the tx code to proper errors that lwt can consume. > > > > Reported-by: Jordan Griege > > Signed-off-by: Yan Zhai > > --- > > net/core/filter.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/net/core/filter.c b/net/core/filter.c > > index 06ba0e56e369..c9cc501ecdc0 100644 > > --- a/net/core/filter.c > > +++ b/net/core/filter.c > > @@ -2129,6 +2129,11 @@ static inline int __bpf_tx_skb(struct net_device= *dev, struct sk_buff *skb) > > ret =3D dev_queue_xmit(skb); > > dev_xmit_recursion_dec(); > > > > + // We should not return NET_XMIT_xxx here since it will conflic= t with > > + // LWTUNNEL_XMIT_xxx values. Convert the return value to errno = instead. > > C++ comments; should be /* */. But, also, maybe they are not really neede= d? > *facepalm* yes I think we can remove them since the commit message already covers it... > ret =3D dev_queue_xmit(skb); > if (ret) > ret =3D net_xmit_errno(ret); > > We have a bunch of places with the pattern like this, so probably can > do the same here? > Personally I like an explicit name better, since not all the return codes use 0 to signal success, e.g. XDP_PASS, TC_ACT_PIPE. But I'd leave that for future improvements now that all other places use 0 on this. thanks Yan > > + if (unlikely(ret !=3D NET_XMIT_SUCCESS)) > > + ret =3D net_xmit_errno(ret); > > + > > return ret; > > } > > > > -- > > 2.30.2 > > --=20 Yan