Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp485486imn; Wed, 27 Jul 2022 11:31:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sr6SFXppArukF1DC/mA8L+6n4tTaQIJ/Sr7Cb33l4+v67/KyPUyN8kSZ8ODQlBCs97UwIv X-Received: by 2002:a05:6a00:228e:b0:52b:13d2:2627 with SMTP id f14-20020a056a00228e00b0052b13d22627mr22871854pfe.42.1658946676405; Wed, 27 Jul 2022 11:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946676; cv=none; d=google.com; s=arc-20160816; b=nrvBtUo4lVRFEpgspOMrmyCL/tGMXnohMJXFl/3mnVJG6SIcppfoCcbibHNDEeTFLr 8XWxBbcPR35k1WbsDX1C5ucaxjZ5XHhz4DYG9DMwy9Xl27SIe5QTTsViPKhcOzdxRCn0 xDnWVbXiEx3L969KUFHpghish0mGBLko2sDGHUrrnGoOXJvB3Xwq6OdvVJzLzvDA0n25 U1JbwUofxbBT9uQt1zFACOSaBYaQjsisaDYN3gAfDI2rSwe7DsHwtxxpbTq+0FBHq3XR PfuXFP+OiUTc1uDEs/oG8O2d8cRGuKPmrzdScckL6CaU6SfwSsxBrdxk7W1qrM0JYhCU 9+oA== 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=Skxrp2BWRz8jx4AoNxkN/9hdrhJng9D7IoIymNV1XQw=; b=TChyTC+TeulEqV0zV0ooob7dwqF1+EVA2P/CtQ2RoCMpqqUo+AviTf+0jFRbujz/ot IRgDT48o4AHvhA67UGW1vlh6espFsq2/6Sx08HMU2j6t8MysgwJiqHi+tLraSv4ruOlY Laph+C87EVLDkpc4KclPIlLnB+0JL1gdVaZ5k8qqRQUojHxpB962JfEudm2i0DQjDx1W XYptSgTnPeVrjJj5efKSY7zbEuRmZszg++ydTuNvSIqxsXF/geAHYfxb2H+wHn0obNLh 15VHZ/kbaH7okDWvdyc6w2ogh9DCx8UquvtiZBu+gTL7Ip9BFda/PdlnpVvJiBPPVrkN A+MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IPcxzl2Z; 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 t73-20020a63784c000000b0040d9515987asi21316084pgc.62.2022.07.27.11.31.00; Wed, 27 Jul 2022 11:31:16 -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=IPcxzl2Z; 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 S241059AbiG0Qzh (ORCPT + 99 others); Wed, 27 Jul 2022 12:55:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241031AbiG0QyO (ORCPT ); Wed, 27 Jul 2022 12:54:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 778524F661; Wed, 27 Jul 2022 09:35:22 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A6D2A61A8E; Wed, 27 Jul 2022 16:35:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0E0BC433D6; Wed, 27 Jul 2022 16:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939721; bh=njurI18qD1t1r66D78QE8tvSsJDqwpTLVeo3OeAw6N4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IPcxzl2ZUnwsBtl6WCdUD1kjARoAqSdoSYulT8ACwahbks4mHOqRgUwGKC3sT1ePE jz53SGfUo3VT8BNXh+7aJZzecPOheLzLk0/tK4oiUBvKWr75JKZCE3b26KFJWcFLoH t3SgEoQ9Q5PD7jAhg59xR6yoV6Aju+RTwV1+dfj0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Eric Dumazet , Daniel Borkmann Subject: [PATCH 5.10 080/105] bpf: Make sure mac_header was set before using it Date: Wed, 27 Jul 2022 18:11:06 +0200 Message-Id: <20220727161015.300001150@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161012.056867467@linuxfoundation.org> References: <20220727161012.056867467@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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: Eric Dumazet commit 0326195f523a549e0a9d7fd44c70b26fd7265090 upstream. Classic BPF has a way to load bytes starting from the mac header. Some skbs do not have a mac header, and skb_mac_header() in this case is returning a pointer that 65535 bytes after skb->head. Existing range check in bpf_internal_load_pointer_neg_helper() was properly kicking and no illegal access was happening. New sanity check in skb_mac_header() is firing, so we need to avoid it. WARNING: CPU: 1 PID: 28990 at include/linux/skbuff.h:2785 skb_mac_header include/linux/skbuff.h:2785 [inline] WARNING: CPU: 1 PID: 28990 at include/linux/skbuff.h:2785 bpf_internal_load_pointer_neg_helper+0x1b1/0x1c0 kernel/bpf/core.c:74 Modules linked in: CPU: 1 PID: 28990 Comm: syz-executor.0 Not tainted 5.19.0-rc4-syzkaller-00865-g4874fb9484be #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/29/2022 RIP: 0010:skb_mac_header include/linux/skbuff.h:2785 [inline] RIP: 0010:bpf_internal_load_pointer_neg_helper+0x1b1/0x1c0 kernel/bpf/core.c:74 Code: ff ff 45 31 f6 e9 5a ff ff ff e8 aa 27 40 00 e9 3b ff ff ff e8 90 27 40 00 e9 df fe ff ff e8 86 27 40 00 eb 9e e8 2f 2c f3 ff <0f> 0b eb b1 e8 96 27 40 00 e9 79 fe ff ff 90 41 57 41 56 41 55 41 RSP: 0018:ffffc9000309f668 EFLAGS: 00010216 RAX: 0000000000000118 RBX: ffffffffffeff00c RCX: ffffc9000e417000 RDX: 0000000000040000 RSI: ffffffff81873f21 RDI: 0000000000000003 RBP: ffff8880842878c0 R08: 0000000000000003 R09: 000000000000ffff R10: 000000000000ffff R11: 0000000000000001 R12: 0000000000000004 R13: ffff88803ac56c00 R14: 000000000000ffff R15: dffffc0000000000 FS: 00007f5c88a16700(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fdaa9f6c058 CR3: 000000003a82c000 CR4: 00000000003506e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: ____bpf_skb_load_helper_32 net/core/filter.c:276 [inline] bpf_skb_load_helper_32+0x191/0x220 net/core/filter.c:264 Fixes: f9aefd6b2aa3 ("net: warn if mac header was not set") Reported-by: syzbot Signed-off-by: Eric Dumazet Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20220707123900.945305-1-edumazet@google.com Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -66,11 +66,13 @@ void *bpf_internal_load_pointer_neg_help { u8 *ptr = NULL; - if (k >= SKF_NET_OFF) + if (k >= SKF_NET_OFF) { ptr = skb_network_header(skb) + k - SKF_NET_OFF; - else if (k >= SKF_LL_OFF) + } else if (k >= SKF_LL_OFF) { + if (unlikely(!skb_mac_header_was_set(skb))) + return NULL; ptr = skb_mac_header(skb) + k - SKF_LL_OFF; - + } if (ptr >= skb->head && ptr + size <= skb_tail_pointer(skb)) return ptr;