Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1472014rwj; Sun, 18 Dec 2022 08:50:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf5+LsLHdeykUDpZ5s/3kdp5TDd5fPSdkNQDByOFslpTj30FqiclEpvMnoweWdkjSd2hlCUs X-Received: by 2002:a17:906:4d8f:b0:7c0:e535:13fc with SMTP id s15-20020a1709064d8f00b007c0e53513fcmr46485411eju.37.1671382254362; Sun, 18 Dec 2022 08:50:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671382254; cv=none; d=google.com; s=arc-20160816; b=CJDs5isPJLvSfODYreg8t2yhxFAxLjQxvQylCI1PTFOAPEeYtqpPRla2vO8Z8GBE8/ JI//uvT29vKTCK2pQ1zDWcI5BMe8i/wM4q043O/5zmITeulUh1gje6hozsW39OZ6FDMa WDwOWy605UZeSZMh5ZyGoOatA/mzJ4LE/bDFJLiGC704rRutodzV+EPy282fROJ2X/Gk hX7Qpzs5m0GB2R/fTxR+poX5/+NPw0DXZ82ZtW88p/QY2HrPgXSzAJLDy0z8s8sBa1fX 8eePLRWftV/WW4b9I4EY6TsI4/6WcT9CrOhsb6Eeyd6DgEt4BovnKNWMdR164U7kznAa LRjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UwAcusXAotznH4fTgF+9GteybhnynjjCN/DERDc8G7g=; b=U6Ybs1TAAW9p9/tY02qnI+kAxOjIUkN1OterXkWNpMupFWYUtmywfr0krbvLQpvbzU Vw3dV6CvA1F8Va+aue2+5yIXz9cu5VhxVbjCPNyWoAl5Btr64X6RIBYSxf+5gtOBwu4W 7CIaBltE0J1BNTR4GtnOGQ+5QcYP8P0rtxgP3dNFNLat/YsgXT5DWQ4ta3B99kFiGIUt Eok+buhXc5zy8x+1W7Nhl2+0FuT8rJNu8iz3gB5GZJigEjb9Ffk0+IwvP/2/xDe3s7bI J6bfhJ5Ndp4zgPuLkoQrpmpsQaCU/rvE4HS7oPOhExLlocwtG/jaisG4zVg8uNIpRq+O 86yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jgCp1TJQ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g20-20020a1709065d1400b007adb868f102si8012563ejt.476.2022.12.18.08.50.37; Sun, 18 Dec 2022 08:50:54 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=jgCp1TJQ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232504AbiLRQif (ORCPT + 70 others); Sun, 18 Dec 2022 11:38:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232561AbiLRQhb (ORCPT ); Sun, 18 Dec 2022 11:37:31 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E33D017E15; Sun, 18 Dec 2022 08:13:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 89F7BB80BD9; Sun, 18 Dec 2022 16:13:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4820C433D2; Sun, 18 Dec 2022 16:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671380009; bh=UgKZGYaJ9pVdstIwTRvpLJHcpaogbLc+Uo9at4fFaJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jgCp1TJQ1GhF2ihp30k6e7IbppCFYksmdHsEqRb+fDZqUT/dYdoLBrTqcaphBxUcz lRSr1lzIHysfQf6HkrX4Br0SD+vMEHMxVdJ/ElgpXCpsdc0U+pLPQqtOT8i4HSaqL1 cHNX5YuRygFjLmtxKeD24QCfdqDMza9o+wy6sTDW7jdX6SxZcW82kBXs6CuELs26h6 mBuaJJBz49lzVOjtkG+M4Oa7srylwamm7BILeJyKR6ZyvWNqra8cxVmNbB954Hx8iF EmW8/+03obxhYOXZEk6pWEataI1TEQLGyBtaMyLeilIHDR8Kln5mWEbB6dXzktFFAk /DlnJi9gzzNFg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Stanislav Fomichev , Eric Dumazet , syzbot+f635e86ec3fa0a37e019@syzkaller.appspotmail.com, Martin KaFai Lau , Alexei Starovoitov , Sasha Levin , martin.lau@linux.dev, daniel@iogearbox.net, andrii@kernel.org, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, bpf@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 11/46] bpf: make sure skb->len != 0 when redirecting to a tunneling device Date: Sun, 18 Dec 2022 11:12:09 -0500 Message-Id: <20221218161244.930785-11-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218161244.930785-1-sashal@kernel.org> References: <20221218161244.930785-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Stanislav Fomichev [ Upstream commit 07ec7b502800ba9f7b8b15cb01dd6556bb41aaca ] syzkaller managed to trigger another case where skb->len == 0 when we enter __dev_queue_xmit: WARNING: CPU: 0 PID: 2470 at include/linux/skbuff.h:2576 skb_assert_len include/linux/skbuff.h:2576 [inline] WARNING: CPU: 0 PID: 2470 at include/linux/skbuff.h:2576 __dev_queue_xmit+0x2069/0x35e0 net/core/dev.c:4295 Call Trace: dev_queue_xmit+0x17/0x20 net/core/dev.c:4406 __bpf_tx_skb net/core/filter.c:2115 [inline] __bpf_redirect_no_mac net/core/filter.c:2140 [inline] __bpf_redirect+0x5fb/0xda0 net/core/filter.c:2163 ____bpf_clone_redirect net/core/filter.c:2447 [inline] bpf_clone_redirect+0x247/0x390 net/core/filter.c:2419 bpf_prog_48159a89cb4a9a16+0x59/0x5e bpf_dispatcher_nop_func include/linux/bpf.h:897 [inline] __bpf_prog_run include/linux/filter.h:596 [inline] bpf_prog_run include/linux/filter.h:603 [inline] bpf_test_run+0x46c/0x890 net/bpf/test_run.c:402 bpf_prog_test_run_skb+0xbdc/0x14c0 net/bpf/test_run.c:1170 bpf_prog_test_run+0x345/0x3c0 kernel/bpf/syscall.c:3648 __sys_bpf+0x43a/0x6c0 kernel/bpf/syscall.c:5005 __do_sys_bpf kernel/bpf/syscall.c:5091 [inline] __se_sys_bpf kernel/bpf/syscall.c:5089 [inline] __x64_sys_bpf+0x7c/0x90 kernel/bpf/syscall.c:5089 do_syscall_64+0x54/0x70 arch/x86/entry/common.c:48 entry_SYSCALL_64_after_hwframe+0x61/0xc6 The reproducer doesn't really reproduce outside of syzkaller environment, so I'm taking a guess here. It looks like we do generate correct ETH_HLEN-sized packet, but we redirect the packet to the tunneling device. Before we do so, we __skb_pull l2 header and arrive again at skb->len == 0. Doesn't seem like we can do anything better than having an explicit check after __skb_pull? Cc: Eric Dumazet Reported-by: syzbot+f635e86ec3fa0a37e019@syzkaller.appspotmail.com Signed-off-by: Stanislav Fomichev Link: https://lore.kernel.org/r/20221027225537.353077-1-sdf@google.com Signed-off-by: Martin KaFai Lau Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- net/core/filter.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/core/filter.c b/net/core/filter.c index fb5b9dbf3bc0..1a7903812a22 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2125,6 +2125,10 @@ static int __bpf_redirect_no_mac(struct sk_buff *skb, struct net_device *dev, if (mlen) { __skb_pull(skb, mlen); + if (unlikely(!skb->len)) { + kfree_skb(skb); + return -ERANGE; + } /* At ingress, the mac header has already been pulled once. * At egress, skb_pospull_rcsum has to be done in case that -- 2.35.1