From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1674731F9BE; Wed, 20 May 2026 16:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779295956; cv=none; b=B6TKjk2uG+6BXaEG0roCWe4f7s4MIiKiXgekbjiylelJeEayg7Ar3USKRl68XqqEida/jLjhiD0OckICizMsW1UOMipqC4h49Go1QCPfykt8aKcLmLowBgJkfUU6446HtmQHEy+kwPqtV/FesXQ9HfyKlNi5q6+7LOkkv8mld3g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779295956; c=relaxed/simple; bh=feboqpoIQtROagPAhshHGBn4sQN5SPoiK3Xk5BnwSQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IXjpby6a0IeYwPQJVK9zKUTSAIPpus7fX9OQzEJMLb+6b7/YUQ9o4v8tt9PGoQ4aD4v+1Zd4XVw8Bayhm7h2UeJVN4vtf5ADKsGyL3EkP5jyY6dSUXoy3TT+apo5/GXQBkLTHlCOVWwsa7rSoqyQHrQ6mnR+zh5Xc04NPOH4+9o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Xycj0RvH; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Xycj0RvH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B4DB1F000E9; Wed, 20 May 2026 16:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779295955; bh=GrgBk0VyTfN9LyVmYoKSo4aeqn+coXBbNMjRht5koug=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Xycj0RvHQGrj0GrDjhePr2HjiETSsgcKdF1Iqmfq7p3Vt0QCKZ6ZfrBFezoRb9L21 jFHaMWC1LjwokI/cjbMH2gEWNMMaabHoIuLzF+YO8JVILewQknBrrTVQpuSxkwN7Um r5/RGmHUd2ktx8kZHAjO0qWlMXNscs7u6Ql+y/AQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hiker Cl , Mykyta Yatsenko , Paul Chaignon , Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.0 0617/1146] bpf: Fix NULL deref in map_kptr_match_type for scalar regs Date: Wed, 20 May 2026 18:14:27 +0200 Message-ID: <20260520162202.146228672@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520162148.390695140@linuxfoundation.org> References: <20260520162148.390695140@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mykyta Yatsenko [ Upstream commit 4d0a375887ab4d49e4da1ff10f9606cab8f7c3ad ] Commit ab6c637ad027 ("bpf: Fix a bpf_kptr_xchg() issue with local kptr") refactored map_kptr_match_type() to branch on btf_is_kernel() before checking base_type(). A scalar register stored into a kptr slot has no btf, so the btf_is_kernel(reg->btf) call dereferences NULL. Move the base_type() != PTR_TO_BTF_ID guard before any reg->btf access. Fixes: ab6c637ad027 ("bpf: Fix a bpf_kptr_xchg() issue with local kptr") Reported-by: Hiker Cl Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221372 Signed-off-by: Mykyta Yatsenko Acked-by: Paul Chaignon Link: https://lore.kernel.org/r/20260416-kptr_crash-v1-1-5589356584b4@meta.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index b26a599be947f..77ddd452b8035 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -6000,6 +6000,9 @@ static int map_kptr_match_type(struct bpf_verifier_env *env, int perm_flags; const char *reg_name = ""; + if (base_type(reg->type) != PTR_TO_BTF_ID) + goto bad_type; + if (btf_is_kernel(reg->btf)) { perm_flags = PTR_MAYBE_NULL | PTR_TRUSTED | MEM_RCU; @@ -6012,7 +6015,7 @@ static int map_kptr_match_type(struct bpf_verifier_env *env, perm_flags |= MEM_PERCPU; } - if (base_type(reg->type) != PTR_TO_BTF_ID || (type_flag(reg->type) & ~perm_flags)) + if (type_flag(reg->type) & ~perm_flags) goto bad_type; /* We need to verify reg->type and reg->btf, before accessing reg->btf */ -- 2.53.0