From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 260F03859FE; Wed, 8 Apr 2026 18:15:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775672124; cv=none; b=JDdT4nWPPAgEl95hrRu4sxaFOpS7pGGixc0V+hC/hf30q8Un9nh7/PU1FAutjuaV5XHDqQxZicXPNLc1ue/1TwJGayZPAAs6XPproEPdmp49VWEmjjmTMHqcVQTOeWLG4xAosi1iT/RymnoAxvh7dqorWrMXe6sz0RUm5yjc5+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775672124; c=relaxed/simple; bh=meFRYR2+VC1acStms4HtC2ygfonnbfkwpB57YBj6YxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZHRNr5+FfCSXrB6l63siWvSqquxJwUvzaXhmd6v1fmigJjuLOO7VhEKv+3Oqkt2wxEA0isliogWchKFwy65N/I3j7DKQbtuVTYkVTyU4jY6ym0WM/AdLPTTjNY6MWjLTWaI3DBzyip4nBHwjsqCzAGbM/WCH1l9bsUCAvJb2/zc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CF6hh628; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CF6hh628" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59CE2C19425; Wed, 8 Apr 2026 18:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1775672123; bh=meFRYR2+VC1acStms4HtC2ygfonnbfkwpB57YBj6YxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CF6hh628Jro4kNWri5b+ipvn1ukOx1gFaYoDaFDuMVuE8wThTTnoVz/xZyPkGKKBe /4rSVCL2t1J6RJaqCZqeXifPhSvAK7EUsK4Dwn8l/kAGJeKu16zq3IDN7XSx6TOXV/ tg/fORWHytFZy8rcyUpti97N99KDeT0EAEdkhFEQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qi Tang , Kumar Kartikeya Dwivedi , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 191/312] bpf: reject direct access to nullable PTR_TO_BUF pointers Date: Wed, 8 Apr 2026 20:01:48 +0200 Message-ID: <20260408175940.894037965@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408175933.715315542@linuxfoundation.org> References: <20260408175933.715315542@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qi Tang [ Upstream commit b0db1accbc7395657c2b79db59fa9fae0d6656f3 ] check_mem_access() matches PTR_TO_BUF via base_type() which strips PTR_MAYBE_NULL, allowing direct dereference without a null check. Map iterator ctx->key and ctx->value are PTR_TO_BUF | PTR_MAYBE_NULL. On stop callbacks these are NULL, causing a kernel NULL dereference. Add a type_may_be_null() guard to the PTR_TO_BUF branch, matching the existing PTR_TO_BTF_ID pattern. Fixes: 20b2aff4bc15 ("bpf: Introduce MEM_RDONLY flag") Signed-off-by: Qi Tang Acked-by: Kumar Kartikeya Dwivedi Link: https://lore.kernel.org/r/20260402092923.38357-2-tpluszz77@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 59f53fea9e3c6..d8d3616abceb6 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5139,7 +5139,8 @@ static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, u32 regn } else if (reg->type == CONST_PTR_TO_MAP) { err = check_ptr_to_map_access(env, regs, regno, off, size, t, value_regno); - } else if (base_type(reg->type) == PTR_TO_BUF) { + } else if (base_type(reg->type) == PTR_TO_BUF && + !type_may_be_null(reg->type)) { bool rdonly_mem = type_is_rdonly_mem(reg->type); u32 *max_access; -- 2.53.0