From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.173 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== 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== 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 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 ; Sat, 5 Dec 2026 09:10:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1A4C0606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ubuntu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-386c71feeeaso2222064eec.0 for ; 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) 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) From: Pragyansh Chaturvedi To: bpf@vger.kernel.org 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 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 Message-ID: <20261205090934.3813585-1-r41k0u@ubuntu.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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