Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp970512rwb; Wed, 26 Jul 2023 05:55:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlEdoYgzRDKB827M1vJTha+NqXIjGHp4nDYuWqrexD4wNqDg+8ryuNbnKLMOHk2Rp8LYJYvZ X-Received: by 2002:a05:6512:201c:b0:4fb:8435:3efc with SMTP id a28-20020a056512201c00b004fb84353efcmr1141181lfb.16.1690376126254; Wed, 26 Jul 2023 05:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690376126; cv=none; d=google.com; s=arc-20160816; b=MSixp4oVC6kp3uYp8EzAQULj3ZWrG8zFNQBPPR+uieRDzimLY1Ox0kOhp85o+KmXb+ ip8YSBRjGtBsMHlueg8uKsbVmYEgm1nnl5toY0pOSmxmHk8Jo7JpbkE7dqzWTjuiB3qD OTzRIIGWlm4LiD14sGCpyoMdDnT9DTVgat7Kj+P4XLTkmQzjtvxotElCve/1n6iyopcA 0LC+CA0DCKDCZ0gV6Mf39BeycWnGdwmZKal69Ypx5dq+uD7E9vzZoQY7QFTOOWUzeLVf 8BkXa6qRldisrRLDJW4sQX4VqcDsOZVl5tt1iEk/OqNgPIisuI0VrHW96hwMNpbL2KQD cAOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=Zw4DRcroK7b/Ks1g/UthzcdQpwOmLzE3yDyhD4mJ/48=; fh=F7ZeU1s0BvoaGdPyZnpe39+nKnuPuRffhHU2Zy5zmhU=; b=GNawnd3POE7LzuIHuVaDtq8subVY/45pZ0S4Ax8jqnCapUmgZrPB+gmFG+KsDz75Or ie3jjXj++0VhB8zcr2shd+AiR8T6gUQyYFClYkCBYTSLMLR7O7xamao3wzybfmCPSR// jz1EPHADAXcKrFAJlhKABWwTEVmZS7SV9NWbimWm+qYXnyer6kli2j5O7yTrWwVj2AnD 9WQr1FuZyup9o+gtw8jnXXs5MPoHRhQVuUb5i4Xk2JxYEfOAdegWp6AzLTUR0tgsis/A IEcgQ/21SbbFTM50ndkSXLs5nvBfD1oBvr5Zjb+TUU0R6al2YzEA9svDvi9QTignovbO Ky3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=NRctkvSK; 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 g6-20020aa7d1c6000000b0051e226c4e6dsi9455545edp.278.2023.07.26.05.55.01; Wed, 26 Jul 2023 05:55:26 -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=NRctkvSK; 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 S233655AbjGZM0S (ORCPT + 99 others); Wed, 26 Jul 2023 08:26:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233722AbjGZM0Q (ORCPT ); Wed, 26 Jul 2023 08:26:16 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93B362698 for ; Wed, 26 Jul 2023 05:26:09 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-99bcc0adab4so62445266b.2 for ; Wed, 26 Jul 2023 05:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1690374368; x=1690979168; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=Zw4DRcroK7b/Ks1g/UthzcdQpwOmLzE3yDyhD4mJ/48=; b=NRctkvSKs+iRsVWTOZqB7gngDEnfK/LWaunoUHDqBmsl8zHpvn2iWS36/Od0sBmlP5 bgEFSxuRPtraPIqqbylltCq6p74DT34dqQ8CENZ7S2I/+5XFdRzWfZmSjBqVQSKZctZk Pzv6HO/hLOX962lGP2VFYRYV5W4djxSgMgugU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690374368; x=1690979168; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Zw4DRcroK7b/Ks1g/UthzcdQpwOmLzE3yDyhD4mJ/48=; b=Eqo5xJ7G/2wDDzSV15kSO0UNEe0fkvciFry7lcoVOfrPGe1uyp1ecFbTIBf9tPquVm eSckCdyPeIfN1YxObG03Whywevb36dTAf5x8hQb6iunTOYCNcW5yGmeIFkUtP6lry6hu tdauVlyLvw4MwgF9YBHnPuw/BqH6bmDzgF79lq/CMtMDPwqRo9KpgUOPOm2lep6dFspP FVjzJqREzYE6FOOPISiR1Qc7punRWa+R4PcLkiFwPcN56CSTt+4BGE4u+O+kbUDsuyo8 MFw3iqMFPUXbzZf0bzKRwkt3C3E/+oYmw+5F2VN8912/iASSaZK0PTYwvOot7LJuznhE rTig== X-Gm-Message-State: ABy/qLZdzF910i/0jPnRtfkT0ats9mKTDw3Sqn9ErtmsNZIL1tKfsAoV GMYvgNbUtH/XMSs0BExvXMgJQw== X-Received: by 2002:a17:907:a049:b0:994:54e7:1287 with SMTP id gz9-20020a170907a04900b0099454e71287mr1478975ejc.73.1690374367751; Wed, 26 Jul 2023 05:26:07 -0700 (PDT) Received: from cloudflare.com (79.184.136.135.ipv4.supernova.orange.pl. [79.184.136.135]) by smtp.gmail.com with ESMTPSA id n13-20020a170906378d00b0099b4ec39a19sm9621112ejc.6.2023.07.26.05.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 05:26:07 -0700 (PDT) References: User-agent: mu4e 1.6.10; emacs 28.2 From: Jakub Sitnicki 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 Subject: Re: [PATCH v4 bpf 1/2] bpf: fix skb_do_redirect return values Date: Wed, 26 Jul 2023 14:25:38 +0200 In-reply-to: Message-ID: <87ila6yi3l.fsf@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain 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=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 On Tue, Jul 25, 2023 at 06:08 PM -07, Yan Zhai wrote: > skb_do_redirect returns various of values: error code (negative), > 0 (success), and some positive status code, e.g. NET_XMIT_CN, > NET_RX_DROP. Commit 3a0af8fd61f9 ("bpf: BPF for lightweight tunnel > infrastructure") didn't check the return code correctly, so positive > values are propagated back along call chain: > > ip_finish_output2 > -> bpf_xmit > -> run_lwt_bpf > -> skb_do_redirect > > Inside ip_finish_output2, redirected skb will continue to neighbor > subsystem as if LWTUNNEL_XMIT_CONTINUE is returned, despite that this > skb could have been freed. The bug can trigger use-after-free warning > and crashes kernel afterwards: > > https://gist.github.com/zhaiyan920/8fbac245b261fe316a7ef04c9b1eba48 > > Convert positive statuses from skb_do_redirect eliminates this issue. > > Fixes: 3a0af8fd61f9 ("bpf: BPF for lightweight tunnel infrastructure") > Tested-by: Jakub Sitnicki > Suggested-by: Markus Elfring > Suggested-by: Stanislav Fomichev > Reported-by: Jordan Griege > Signed-off-by: Yan Zhai > --- Reviewed-by: Jakub Sitnicki