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 6046A4F93B3; Thu, 17 Sep 2026 17:20:41 +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=1789665642; cv=none; b=jY+onr/F2QjzqflTpcchCAYXIXmecaqtbS3Slgajwp8mdbW1flH0gQCJEJMgkBwRvZAXtv8UXo9IC2FYmUK7aL9DviiltbvrRnvsZ94bh9ZfRMLwX+dz0yQpSpZXyopn0JNyWbZ33c4q1zvctKwD5fLIFMRAAnd7GjlgDUcpu5U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789665642; c=relaxed/simple; bh=pD7wInguFWrYRaeNI0780GqNSNOOhYUfRLR4Jz+60eA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qRVMb9SzTcSobOZjHewRg37+m23Oyv83sUu/aK57i1ZJ3tti8WCp8mbZFaiOH3WMBu8YtkVdCga9s2JfKcxxMJdpNUxoPOeR/lhwKekDZ8RCZ60FnETmpFboltxrUjz/xMldQz3fpDpf9S/SS2rC1fIFI5jT8WUmueXhg2saGLI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dNAXSbs8; 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="dNAXSbs8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2F031F000FF; Thu, 17 Sep 2026 17:20:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789665641; bh=POmJhFVLQ9WSq3Mjj5p7S8elm7ufQ9zoCtkx2W4u/Q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dNAXSbs83MSvMOOMnHC/36Kns6ITLBJ+aEAsR4bGGlyKFHw/MxtUH85rArC/wayqQ 9ohXvbQp2k8+9gSY5NNUjVOvZSgQfwhUzaFGZhOk13QHgjo8dTHbwUq/exFzAjHsww R6sv3k+tzj+qL1MDeMp7vVhtO8XU6PgbAHrD5ME8= 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 6.18 0735/1250] bpf: reject BPF_PSEUDO_FUNC reference to the main program Date: Thu, 17 Sep 2026 16:08:50 +0100 Message-ID: <20260917151611.813012740@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151551.901433442@linuxfoundation.org> References: <20260917151551.901433442@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 6.18-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 0a4198335c9b9..c0564cbb9154a 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -17346,6 +17346,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