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 869315172F5; Wed, 30 Sep 2026 18:03:20 +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=1790791401; cv=none; b=DDsH9c8K+FFjaw1ADlGC40L5iaNzw/SI+nhnUXzSywpmEczcD5sQlZFgkGktUhvLGNOh4vjFavEeYU6xBDBsjicja9UZ1c89ARQzluastfL68emgoHkEyI+bcrbZNZ78SuKM4U4o3PnuOh4YoEsMbS8O5NJZxFzT7VaRo49qOEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790791401; c=relaxed/simple; bh=e1Fg8rFySMbEMrLQpxkZhpxJJWxRLAwEu0piTXzwNaQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i6Prd+tADPaXbInRV3Ig1m4Me8Gp/EiTxLHBBFd3OEIRZCZXlZvlwK5CBwgrYzPUpjqYCs4ocWLQLPfukr3AslZoqwZim9WRiogKRYbetUlZy1wGVOCn3+cBsJBgmAmr4ykfbMxRMdROePExZ/vAmgcxNulWxG6+GNUA/puOQLQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JqpdK4oH; 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="JqpdK4oH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF7C61F000FF; Wed, 30 Sep 2026 18:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790791400; bh=ib6CzggH6L4U2toTnOzf94jQXeLH+/dSt2j6NGTRHFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JqpdK4oHDy/ATFv3E40OPoaXV2p6cWuf46UngYN+iy0A8P4GNwUJO6pEwebwDhFLx 8PuTQ5yaxOwzj6jik+gBS4DGBCDGy6IjvXJenxFdutRZeFegSKSRFp8aYBwlvOA0uQ 59Wa5qAs/9O1Cc42tB8hidV9uBPGhmde3fbjlv9g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nicholas Carlini , Eduard Zingerman , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.15 289/752] bpf: reject BPF_PSEUDO_FUNC reference to the main program Date: Wed, 30 Sep 2026 17:22:39 +0200 Message-ID: <20260930152404.544442540@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152358.131179731@linuxfoundation.org> References: <20260930152358.131179731@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eduard Zingerman [ Upstream commit 374b2c5561db80fcdd7cdce44af37a49416f61c7 ] fixups.c:jit_subprogs() rewrites BPF_PSEUDO_FUNC loads to contain real function addresses. This function is invoked from bpf_jit_subprogs() only when env->subprog_cnt > 1. Meaning that for any program like below: int main(void *ctx) { void *ptr = main; ... bpf_timer_set_callback(..., ptr); ... } The 'ptr' won't be ever converted to contain an address. In combination with e.g. bpf_timer_set_callback() this would lead to a function call at a bogus address. Instead of complicating the implementation, just assume that no useful program needs main to be a sync or async callback and reject BPF_PSEUDO_FUNC loads for the main subprogram. Fixes: 69c087ba6225 ("bpf: Add bpf_for_each_map_elem() helper") Reported-by: Nicholas Carlini Suggested-by: Nicholas Carlini Signed-off-by: Eduard Zingerman Link: https://lore.kernel.org/r/20260902233658.1186477-1-eddyz87@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 4e2d49b0d1f1c..786d641c9cd94 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9518,6 +9518,15 @@ static int check_ld_imm(struct bpf_verifier_env *env, struct bpf_insn *insn) verbose(env, "callback function not static\n"); return -EINVAL; } + /* + * When env->subprog_cnt == 1 this instruction won't be rewritten + * to hold a real function address. Assume that no usable program + * combines e.g. main and timer callback and just reject here. + */ + if (subprogno == 0) { + verbose(env, "callback function cannot be the main program\n"); + return -EINVAL; + } dst_reg->type = PTR_TO_FUNC; dst_reg->subprogno = subprogno; -- 2.53.0