Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1978709rwe; Fri, 2 Sep 2022 06:55:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR4dvSXrJemsHZJIbnte7QRGibFOZXIzKCm2j57P08nMtUBE89WVT59/QRkRPLNqydFwmMEB X-Received: by 2002:aa7:8397:0:b0:535:933b:54c with SMTP id u23-20020aa78397000000b00535933b054cmr36022108pfm.38.1662126920614; Fri, 02 Sep 2022 06:55:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662126920; cv=none; d=google.com; s=arc-20160816; b=u5JhFvNzOKR81grhZxaeYVxtibEaHPTh2bYdlTa4Jiyv0H0wXTiw5AIq4+IxZzumvx pAL+rlNXRkjyBYnFtbIlqX6aVYo1YBfxyJ+rL6Y1cQUM2G2qbqqYeK5j0Y9Y2BqVHFyk HIJDh7Jkh0K1BJQOxj7s+t/TA2KJfmFM39wX3sfZc4Wxisf2f/Gkd9lXtGEdp0xYATOd Zqd4G4p61CpRhQDKSSDMqqHqdUTMiAsyQO2hWr+/b3xr9er52tJYQTI51tQmaLf94kcP AqcCiZ3lk/FU2xadfg8WM4jX99McPNuHWLBaKJnRuqv+G4rHvvjmlifrw/m1wUpIM27v BGjQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YH1Z5uFthYPBSfkiV+0fwszFiVoObnqJE1LkBXe7qv0=; b=sqIIeKf+EfZZsAd6F1oFriQNbbUsvctw1934bPxhJHC0tjl89/fCHrhgoIsfk2yyUd teRLyQGhU26ZZ+lgMht/H9wRcm248K994qREvC9s5z0shfPW5YQIlGK1g3z6RG0/35oX Jve8YK7Kzko1WGVSAzy7yDxTk5YkU+78Ajj9H77zIrEmEcH1gKlZifUFwi9+y+VO2ReR jdgE9YWX2esbjS3gd0Nq9cGDnEz0DlyBoflE23EzJHR2O4FYJ8mPxbM66Ps7LJ9Hjh/y c03gtAdS93q2KzMVLkizrQPZd87bdMb42oOTU9aQ8JqzWoiqbnhL5akWh+LVavZTc61R IWxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cfrewgwX; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a17090341d200b00172883f5a2asi2204875ple.624.2022.09.02.06.55.09; Fri, 02 Sep 2022 06:55:20 -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=@linuxfoundation.org header.s=korg header.b=cfrewgwX; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236597AbiIBNdD (ORCPT + 99 others); Fri, 2 Sep 2022 09:33:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236576AbiIBNch (ORCPT ); Fri, 2 Sep 2022 09:32:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDF4111B605; Fri, 2 Sep 2022 06:11:50 -0700 (PDT) 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 98AFBB82AD5; Fri, 2 Sep 2022 12:35:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECC67C433D6; Fri, 2 Sep 2022 12:35:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662122113; bh=aPKFJmxk4ZvRsdW5e6kiQ6asp9b+m3LYnX4sZA3272A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cfrewgwXtMq0o23Wb+i4ypYR+zN40xyrrbSSCjBL7NQsm1BLvtVRj8rshRk9gWnzm wpdwHHcUB+hQqORDPmT3ddQg30nsXYPQMXmuVPx5fzDy+EUPRhU57lS+BKKuFYIXYD 7RyJmObJ7JfuqH5pSkW+vi5eYxD+M91uIdmnTXWw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+7a12909485b94426aceb@syzkaller.appspotmail.com, Zhengchao Shao , Stanislav Fomichev , Alexei Starovoitov Subject: [PATCH 5.19 17/72] bpf: Dont redirect packets with invalid pkt_len Date: Fri, 2 Sep 2022 14:18:53 +0200 Message-Id: <20220902121405.351517438@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121404.772492078@linuxfoundation.org> References: <20220902121404.772492078@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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,T_SCC_BODY_TEXT_LINE 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: Zhengchao Shao commit fd1894224407c484f652ad456e1ce423e89bb3eb upstream. Syzbot found an issue [1]: fq_codel_drop() try to drop a flow whitout any skbs, that is, the flow->head is null. The root cause, as the [2] says, is because that bpf_prog_test_run_skb() run a bpf prog which redirects empty skbs. So we should determine whether the length of the packet modified by bpf prog or others like bpf_prog_test is valid before forwarding it directly. LINK: [1] https://syzkaller.appspot.com/bug?id=0b84da80c2917757915afa89f7738a9d16ec96c5 LINK: [2] https://www.spinics.net/lists/netdev/msg777503.html Reported-by: syzbot+7a12909485b94426aceb@syzkaller.appspotmail.com Signed-off-by: Zhengchao Shao Reviewed-by: Stanislav Fomichev Link: https://lore.kernel.org/r/20220715115559.139691-1-shaozhengchao@huawei.com Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- include/linux/skbuff.h | 8 ++++++++ net/bpf/test_run.c | 3 +++ net/core/dev.c | 1 + 3 files changed, 12 insertions(+) --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2624,6 +2624,14 @@ static inline void skb_set_tail_pointer( #endif /* NET_SKBUFF_DATA_USES_OFFSET */ +static inline void skb_assert_len(struct sk_buff *skb) +{ +#ifdef CONFIG_DEBUG_NET + if (WARN_ONCE(!skb->len, "%s\n", __func__)) + DO_ONCE_LITE(skb_dump, KERN_ERR, skb, false); +#endif /* CONFIG_DEBUG_NET */ +} + /* * Add data to an sk_buff */ --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -955,6 +955,9 @@ static int convert___skb_to_skb(struct s { struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb; + if (!skb->len) + return -EINVAL; + if (!__skb) return 0; --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4168,6 +4168,7 @@ int __dev_queue_xmit(struct sk_buff *skb bool again = false; skb_reset_mac_header(skb); + skb_assert_len(skb); if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_SCHED_TSTAMP)) __skb_tstamp_tx(skb, NULL, NULL, skb->sk, SCM_TSTAMP_SCHED);