Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1447801iob; Fri, 29 Apr 2022 05:39:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNED1sMbj01KRLcP6RoRDYTNm6z/0ieKSAgVgkVuCVaGpzlORMEzxh+MqniA2pv8Eo3Rfh X-Received: by 2002:a2e:b0fc:0:b0:24f:1050:ff61 with SMTP id h28-20020a2eb0fc000000b0024f1050ff61mr17150435ljl.290.1651235966200; Fri, 29 Apr 2022 05:39:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651235966; cv=none; d=google.com; s=arc-20160816; b=IF8P0xOf88HgaK4X+udZHVNT0sH5TUFozUAiNMRUBo05Z1plk6Yt1RtEfZwgbFeVBs Jux8eBqGBVrAyUqXt81kjMYrmywYRU3/Z94tiWKOJUyvZb+h2677EaekqeXMLCsfQuC2 JwYf+mtisbWNYzM17JYueAW6dheqMZPVrZn7lHbfAlKG6JFX0/zQaiq+y7FtuV9IHVyw oOHPMniS//R3ZR816jGg9utTnIu3q0Laxbd2rbkSxKav/K06m0oOpZypBxmZSpar+BYU pJL953wtjYeIM5+YiT44BY2y10TQqDSWzet3QQ8rTsfi0aD7LQm/Gvuo2LP5VjjjRo1p ThdA== 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=v/GzplvcO+Dich5VvYqjJe8tDuKvY0qKrv/Zs65/Yd8=; b=MimTu73mmfxylYRXUaSOqqsy9b2WdXJAlSsa0akadxy4GPQ7Xe0WoLoHmCY34Gz4SR jIq1IH57M2/wY4eSeU0PMqU4b7WLDAs1FwzJRWHlplc2A5hIYQkSI6NKef+FnSLupo77 sh2ifJF7OS/oG5cY1RyhLar0a3MFBYeUAEtgmgqKkq9jzrZDjIMtJbODH/KLGXuyOXZG YEC5Fk3wVO1e5Sri6DofES3LapKLqlvvp+i5g8nBADkBHSBmLeo5yquB6gTs18C+Ga5D tGigBTMRYebIHEzmcGytHp9J+mzx4gP51b3CC+NK9n2rv42GYU71v0+MCTNuKn7GlEC6 PAcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ugRo41V0; 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 r23-20020a2e9957000000b0024f06955befsi7130342ljj.509.2022.04.29.05.38.58; Fri, 29 Apr 2022 05:39: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=@linuxfoundation.org header.s=korg header.b=ugRo41V0; 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 S1358097AbiD2KuA (ORCPT + 99 others); Fri, 29 Apr 2022 06:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358186AbiD2Ks4 (ORCPT ); Fri, 29 Apr 2022 06:48:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D017EC8AB1; Fri, 29 Apr 2022 03:44:06 -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 4E1C9B83405; Fri, 29 Apr 2022 10:44:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCC23C385A7; Fri, 29 Apr 2022 10:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651229044; bh=Ssb6HytEiLZ5XlzsnjG4rgI3TrxZRqzekDkLWbmBAcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ugRo41V0QfvyTInDUS5rB6DIkkp56u74wP2sobzArBJGAtyFbT2gNIvRtGP+Y3M81 E6NpyuVZVFuKoQ1e9+6fZ2dvgO9xL32OiGuhrcErzZ3v+O3TVXYi5VchzJ7ExkBzd6 KnuiwP5N3VpvRBuzpwu4noKNzWBA3dkmLeCQXBQo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kumar Kartikeya Dwivedi , Alexei Starovoitov Subject: [PATCH 5.15 33/33] selftests/bpf: Add test for reg2btf_ids out of bounds access Date: Fri, 29 Apr 2022 12:42:20 +0200 Message-Id: <20220429104053.296096344@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220429104052.345760505@linuxfoundation.org> References: <20220429104052.345760505@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: Kumar Kartikeya Dwivedi commit 13c6a37d409db9abc9c0bfc6d0a2f07bf0fff60e upstream. This test tries to pass a PTR_TO_BTF_ID_OR_NULL to the release function, which would trigger a out of bounds access without the fix in commit 45ce4b4f9009 ("bpf: Fix crash due to out of bounds access into reg2btf_ids.") but after the fix, it should only index using base_type(reg->type), which should be less than __BPF_REG_TYPE_MAX, and also not permit any type flags to be set for the reg->type. Signed-off-by: Kumar Kartikeya Dwivedi Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20220220023138.2224652-1-memxor@gmail.com Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/bpf/verifier/calls.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) --- a/tools/testing/selftests/bpf/verifier/calls.c +++ b/tools/testing/selftests/bpf/verifier/calls.c @@ -108,6 +108,25 @@ .errstr = "R0 min value is outside of the allowed memory range", }, { + "calls: trigger reg2btf_ids[reg->type] for reg->type > __BPF_REG_TYPE_MAX", + .insns = { + BPF_MOV64_REG(BPF_REG_1, BPF_REG_10), + BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8), + BPF_ST_MEM(BPF_DW, BPF_REG_1, 0, 0), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0), + BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0), + BPF_EXIT_INSN(), + }, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .result = REJECT, + .errstr = "arg#0 pointer type STRUCT prog_test_ref_kfunc must point", + .fixup_kfunc_btf_id = { + { "bpf_kfunc_call_test_acquire", 3 }, + { "bpf_kfunc_call_test_release", 5 }, + }, +}, +{ "calls: overlapping caller/callee", .insns = { BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 0),