🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27306

[PATCH bpf 1/2] bpf: Give a raw_tp test_run program the largest context when it does tail calls

#27306
From: Pragyansh Chaturvedi
Date: Sat, 05 Dec 2026 09:09
79 lines
12247 bytes
BPF_PROG_RUN for RAW_TRACEPOINT compares ctx_size_in with the
max_ctx_offset of the program that it runs. The target of a tail call
gets the same context:

  first:   bpf_tail_call(ctx, ...)      max_ctx_offset 0, ctx_size_in 8
  target:  r0 = *(u64 *)(ctx + 96)      out of bounds

The target is not known before the run. Pad the copy of the context
with zeros up to U16_MAX, no program can use more.

This is the raw_tp instance of commit 08c987904970 ("bpf: Give a
syscall program the largest context when it does tail calls"), which
applied the same fix to the syscall test_run path only. With KASAN
and BPF_JIT_KASAN the raw_tp path reports:

  BUG: KASAN: slab-out-of-bounds in bpf_prog_..._target+0x2a/0x259
  Read of size 8 at addr ffff88810486a818 by task rawtp_chain_leak/285
   bpf_prog_..._target+0x2a/0x259
   __bpf_prog_test_run_raw_tp+0x5b8/0x900
   bpf_prog_test_run_raw_tp+0x42f/0x7e0
  The buggy address belongs to the cache memdup_user-8 of size 8

The copy is accounted now. It comes from kmalloc-cg or vmalloc, not
from the caches of memdup_user().

Fixes: 04fd61ab36ec ("bpf: allow bpf programs to tail-call other bpf programs")
Signed-off-by: Pragyansh Chaturvedi <r41k0u@ubuntu.com>
---
 net/bpf/test_run.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 8b8c4e9ded9..31c4c656d39 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -782,6 +782,7 @@ int bpf_prog_test_run_raw_tp(struct bpf_prog *prog,
 	__u32 ctx_size_in = kattr->test.ctx_size_in;
 	struct bpf_raw_tp_test_run_info info;
 	int cpu = kattr->test.cpu, err = 0;
+	u32 size = ctx_size_in;
 	int current_cpu;
 
 	/* doesn't support data_in/out, ctx_out, duration, or repeat */
@@ -804,10 +805,18 @@ int bpf_prog_test_run_raw_tp(struct bpf_prog *prog,
 	if (prog->sleepable && (kattr->test.flags & BPF_F_TEST_RUN_ON_CPU))
 		return -EINVAL;
 
-	if (ctx_size_in) {
-		info.ctx = memdup_user(ctx_in, ctx_size_in);
-		if (IS_ERR(info.ctx))
-			return PTR_ERR(info.ctx);
+	/* the target of a tail call can use that much */
+	if (prog->aux->tail_call_reachable)
+		size = max_t(u32, size, U16_MAX);
+
+	if (size) {
+		info.ctx = kvzalloc(size, GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
+		if (!info.ctx)
+			return -ENOMEM;
+		if (copy_from_user(info.ctx, ctx_in, ctx_size_in)) {
+			err = -EFAULT;
+			goto out;
+		}
 	} else {
 		info.ctx = NULL;
 	}
@@ -842,7 +851,8 @@ int bpf_prog_test_run_raw_tp(struct bpf_prog *prog,
 	    copy_to_user(&uattr->test.retval, &info.retval, sizeof(u32)))
 		err = -EFAULT;
 
-	kfree(info.ctx);
+out:
+	kvfree(info.ctx);
 	return err;
 }
 
-- 
2.53.0
Technical Details
Message-ID: <20261205090934.3813585-1-r41k0u@ubuntu.com>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377906-linux-kernel-netdev=dewy.ru
References: <axPUDKyHAFXUXdp_@x1c>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377906-linux-kernel-netdev=dewy.ru
From: r41k0u@ubuntu.com (Pragyansh Chaturvedi)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf 1/2] bpf: Give a raw_tp test_run program the largest context when it does tail calls
Date: Sat,  5 Dec 2026 14:39:33 +0530
Organization: Usenet Network
Message-ID: <20261205090934.3813585-1-r41k0u@ubuntu.com>
References: <axPUDKyHAFXUXdp_@x1c>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2994403"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:d+FILjZTKF24nDCOqzlZLOnoeNo= sha256:cEND/6qEKO45+xwlmv/ucFWh3qIpzaIA043zP6rm284=
	sha1:a87mLInchSr7yqdTm0FL9VYKeq4= sha256:jNwzxvmcrCFiS9WeA10wJ3Fs0juGAJH48Wkp617AUg8=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 898CA117DA3; Sat,  5 Dec 2026 12:10:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.299
X-Spam-Status: No, score=-3.299 tagged_above=-9999 required=6.31
	tests=[HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id JeO9WDtzdNa3;
	Sat,  5 Dec 2026 12:10:24 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377906-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=ubuntu.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 87EDB117DB9; Sat,  5 Dec 2026 12:10:20 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 5E75C29332; Sat,  5 Dec 2026 09:10:14 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796461811;
	b=qDUIDkl815VWmEqk512KrUdd8ItIJgvDi9W7z5qAngPKbqDkOYIvHgYzb3Q+dgwplgap
	 2++LT8/gWA4zVxB+3i+6+WCLSAGEuBKwqXngi9wVF9SSqlQ8V8G56FxhooB5/qht4pTKd
	 xKyOaWp3k2oAp4bFWKdO1Hp/JVkWHmd4U54iLvRvJKnm4BLX4YurbBq+DAD341yQ6WS6x
	 VAWL31s0EOZefBj43qS4DMeFrrUS4oYLd/Mqx3Gxh/MBQgr9QeP+tvratogiFqDjYBZbd
	 XYaPwL4eIDWtYo6ALkngpBEMtSj2fUtYAbsnq2mX19R9fm5EG+0hFl3l5xcvybjRl6A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796461811;
	h=X-Original-To:Received:DMARC-Filter:Received:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=rk9zwRlTttBksi4lOeqqtwUyRt/yXdNlWvFDcE93ho0=;
	b=D5YiKtq/CwRziRXP42z6l+81NxW65LPtQOmsl3DUn/p/ErJtCx5V7tSoZMfw7ICDGPOQ
	 CJ4J/FgqPqhVIiFOIBVHT75zlFpXi9qWQ1FHYVc5my/ETNuWT/v9q5sBt1Iu4Nq8DnTEY
	 SjUMzKUD3tDN5TaC24zOjgU9S1QuePTCDw/N5GL2+EpS7MwRDUDWXaKUsjvRlSZRQluFR
	 8H0zP60LypVtqBlGAzAN75Y7g4Om28Q3UkqwK+GRs3GOFWA3nTOsAUbFToump56ddaZFV
	 hb5ZmQk7b/IFrqwjuE7FeeMv405KKnABgHx5dtjp+cSKKmXUJGC+aA14Bkkw47SabVw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=fail header.from=ubuntu.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B56AF606A33B;
	Sat,  5 Dec 2026 09:10:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796461811;
	b=uKHWD8r5dpOqQOp6K3fb4UwN8nenN6pmCbrXM7YVRZ64JIj3SWowkBiIxwNMifhoUg4t
	 6XbxHjL0CkyTyMykRG7j+POl6B0yQ4Xcd+sd1csmqoqMtgSFl1ej8pIB1xki407w8Jbi8
	 /R10M35iRmD/8BDNtdtPpWoBAzPQvJ5bnXdNt4sXjEguLWnvs722nGmXpHVJWexkAW7R3
	 P4FggTzanXlNcOSUqRF6X3vW54HbWOPXcsCyQxNwkmhaUUe5OXYJTaDiDsWvUetcGVesh
	 esvC+iDQO7TnCKXkwVzxjfEtlwSPRfn5doHJ2q3hCthXKB4t+fSKlhBl/o5cJvG+p3Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796461811;
	h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Forwarded-Encrypted:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=rk9zwRlTttBksi4lOeqqtwUyRt/yXdNlWvFDcE93ho0=;
	b=TAIbQ0pKypa5tbhD77zD1vb0zZGn4Ie9GpKeBv7iQIHv6ks2FhLIDu0P+jlSdwICrSKh
	 9vvueQ7YDEuJsjd3ijinWoPnv3NIgZUyYKTR//SJle8/Pxl8ch4d+1RhVXaIZcS9hTzB9
	 qL70vW7Znl0MXEWA8UZv5TVqPxqsmFL3LuMgvjTDB9hpjQou6LUgZbh2zUZoqmU5nvdCs
	 N1Dw9999Dyf8gQ4uBbm/e0RU9pCBOntjwKNtj9/8RS9YkxPrzoTNgMLsD+DrUIERQ0NHw
	 UbjXqcaCcRDbvTZEpJpg4UEXJPbzgrlb2Fia4R2e32kOISdO6Lp0COoB7Pa2aa3XZOA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=fail header.from=ubuntu.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=none smtp.remote-ip=74.125.82.173
X-Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.173])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A4C0606A32F
	for <netdev@vger.kernel.org>; Sat,  5 Dec 2026 09:10:09 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1A4C0606A32F
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ubuntu.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-386c71feeeaso2222064eec.0
        for <netdev@vger.kernel.org>; Sat, 05 Dec 2026 01:10:09 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796461809; x=1797066609;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=rk9zwRlTttBksi4lOeqqtwUyRt/yXdNlWvFDcE93ho0=;
        b=JybCLA2D8jIQgJV04PUD9/29sbTQfEBQAW9AcbgJ6rZlCT3kO3eorpDJX0xtOEjV5n
         tvD4ALFkvfOmXUlTOPOihMAy5AD6ujrk7CtBMDyf9UnP+eJLbbrijiEGdBBtCTpO/Ppk
         2MfLkbq1C/X4L0RgfJae5XmfsRrwjrdVRQaGaNHizXGxBaq9z7eIxv0BDR4oo7BPdt9R
         jhyUqqY4b2O0v1hC3+1pr/ntAVd2R0fJlZpuehx9zpo5mMCou6ZiIcpm6QctZu9AFgIs
         l9GakqRDJvox4ofHagqlCK/fR8PtsJ2y1x+NhQooOa4gX2IMCZPFHBBQ6FdqnUar2PWx
         84YA==
X-Forwarded-Encrypted: i=1; AL+hErEdqzWVS+l6GhQhER0FmHHTEd6T/Mficz5YQCn3g+Kbg76zMufZxKEEPbZYFg4LYsG9hWMeZB4=@vger.kernel.org
X-Gm-Message-State: AB4q+uFP2KEMbKNfDnCA1iPVsvAf/ahiWHKaEuraQLzXzL6XWl13GOBZ
	8FXi5iUA0sIQkYtv7K776DUK+CgO5d5Jyfmn7mI18qYilWvsA7ievsylSDQgJA==
X-Gm-Gg: AZFdTZd+XYZ84eZJ4irkgpDmnRCxVxClD67JeHf2Jbqoa3qHM3M8JDqxcHCdmzGJBMm
	IrbgYI65t7Dmn9HHVOUKy3MeRHhGT8jRjGNC06lJf5X1NSolwp7JXzjF1i5nkoVr+YCEuVN/2pM
	A2BUXZG2AvAdUQwFVezRVc8Eeu+sMaPg8UZiXHni+It0BbcWeKFe48/afwuxzaLUJSs7OC6aXls
	qQBLG/tGAl3auLHKgsxQ2xFj5VRpJ8gjZ/dUokEDCayFH5gAqBoHn4ewsrO3PHXv6RoWdWEFJ9D
	U8Bdhhm6/ipNF7YiszafLnHfuGoXqguFhQhLmB1E4LTBL1YT9u3jLMoSayTdm+rzVWHMF8fx7dt
	GapC/abf7kuYOYFCxw2fA2bRRxSnul8wUzwV2RRDLg5jCJ2f34WlqCgHqatwSNpuKfjH+EAkAJg
	9qvi+J20jCa3xg3Fl6+7mkmzA0oejnnGKywLtTiI+jqk9tGLIfRSysYchswgcN5hXCN8ECOIslu
	0kcGJyes5R/jW3mmDuD9X7v/e6hKvmz7rXJDjNA6uL8wKmknGazTuhF+it+We7AO0twBwTykyF3
	FffcI1C+aQPhxGUkl4ZHJyUtdqH7z+Q+njuj6126
X-Received: by 2002:a05:7300:d10a:b0:386:b896:319c with SMTP id 5a478bee46e88-387522101a7mr4421290eec.35.1796461809229;
        Sat, 05 Dec 2026 01:10:09 -0800 (PST)
X-Received: from x1c.tail178f29.ts.net ([2406:7400:bb:fb44:feef:834d:2032:98d5])
        by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875207adecsm18481629eec.3.2026.12.05.01.10.04
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sat, 05 Dec 2026 01:10:08 -0800 (PST)
X-Cc: ast@kernel.org,
	daniel@iogearbox.net,
	andrii@kernel.org,
	eddyz87@gmail.com,
	varunrmallya@gmail.com,
	kc@kcsrk.info,
	yonghong.song@linux.dev,
	memxor@gmail.com,
	ngs@cse.iitm.ac.in,
	netdev@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Pragyansh Chaturvedi <r41k0u@ubuntu.com>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <axPUDKyHAFXUXdp_@x1c>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list