From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796462814; b=G9qfUuO0pet0BC9DoLjmHPlXASUxqSAsr51BHlZZX6CGGurlS4zoHOB8RA2a+MtEQp2L XbBdfI8ZZNX1dos3N9i3DvEQxFf5wJ62o/snuW/E3L+zOB9lx6f2BxT6VvnrJPbYYvZcE 7F26D6zirIT7eCGiZvPKlfmMDNI/+qeu09PCVltGrPkxRQC8mOGFYPQuh+4KyYTTsf1De fq+RaHeA9nxKoZ+cqfQDPEWblOs4Br4ychXQhT268JnoYgK9r/cVteEfu1J5UnRJGRdx2 lpUkeRZ2gC6fO7bvhj2Mab0K+HieVW8tp2oSTRX3jsf5AUm2PNTecPMUTfvOC9YUOvQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796462814; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=rPlNd+nhetJyU1LmfSBRqFhLnq/j2HK8ry+AdMy7FbI=; b=3bOAg8B0Ffmj4W23GRDph5OBaZhbMgTa6K/vif8o2+0e1X7K5urayGCf6OyYkQSqxcCF 3fXpe2piAsPTH17wjm4/RSc1UbHI4Qu3iLIFe0KfyUvyvQuU95ZphgZORxS9fM9tqdDmo oYJFPSgoxqae8SEdY/lgnWaYulS2G5hxgvWmSnnJUsjRtVQ/9qr1uaNuolXKcMBu14CGV eyIA4DOL1yMy3eh4fJjDdJ+WL0k237keihiJUOBk7Otv5ays6FAvT8OnwYsG7rnLSMuF3 9nWrGjccXk3nwu8UyOntN/0wrJv1MV+ObfRsRyPtyEUHojd2ZP8XsDyncOtu8c0hh8Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a3osPMch; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF6D8606A322 for ; Sat, 5 Dec 2026 09:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=a3osPMch Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADED01F00A07; Sat, 5 Dec 2026 09:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796462813; bh=rPlNd+nhetJyU1LmfSBRqFhLnq/j2HK8ry+AdMy7FbI=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=a3osPMchENU3pOU/WP1GCvJOSPWRKPa43B5yAjVce4vTBP7HIlm2SmX6nqR7THgg4 NDPIs6gieJu6k0LUcegU9+fZLES52OQmFrjhgPASaSa5z+fg8gjShmBgK9nFxTwEi3 nYkAx3daRZ0ApqmV0N5gJUumBtUuPZA4LTK9uU7afsFE5HMUc+2kK5yrj8eTxeb/XY O0U5tNYug08gtcfHjLvEBexGyVrl0OrCn3c7rjhmzkulWVYrA9KtiOBxYwAVqWydQ0 MuskwSHhblMUiuXY0KiaBw40hwCsPwlnSDWfUAhnnPEJvAeKHdAaW/0FnwP8t07DPF 8kJpSMUOYy00Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf 1/2] bpf: Give a raw_tp test_run program the largest context when it does tail calls Reply-To: sashiko-reviews@lists.linux.dev To: "Pragyansh Chaturvedi" , bpf@vger.kernel.org In-Reply-To: <20261205090934.3813585-1-r41k0u@ubuntu.com> References: <20261205090934.3813585-1-r41k0u@ubuntu.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 09:26:53 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] bpf: Missing freplace tail_call_reachable check for raw_tp targets - [Medium] bpf: Over-allocating U16_MAX via kvzalloc() in bpf_prog_test_run_raw_tp() - [Low] bpf: Incorrect Fixes trailer citing 04fd61ab36ec instead of 1b4d60ec162f -- commit c2e6212f3159dac850a188417860abf3db30dfb8 Author: Pragyansh Chaturvedi > bpf: Give a raw_tp test_run program the largest context when it does tail= calls > > 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 =3D *(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 prog= rams") > Signed-off-by: Pragyansh Chaturvedi [Severity: Low] Commit 04fd61ab36ec ("bpf: allow bpf programs to tail-call other bpf programs") predates raw_tp test_run support. Should the Fixes tag cite the commit that introduced bpf_prog_test_run_raw_tp() instead? Fixes: 1b4d60ec162f ("bpf: Enable BPF_PROG_TEST_RUN for raw_tracepoint") > diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c > index d6c9dc62182ee..f951a41082cd9 100644 > --- a/net/bpf/test_run.c > +++ b/net/bpf/test_run.c [ ... ] > @@ -809,10 +810,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; > =20 > - if (ctx_size_in) { > - info.ctx =3D 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 =3D max_t(u32, size, U16_MAX); [Severity: High] Can a BPF_PROG_TYPE_EXT extension attached to a non-tail-call raw_tp program bypass this check and trigger a NULL pointer dereference or slab out-of-bounds read? prog->aux->tail_call_reachable is never updated when an freplace extension attaches, and bpf_tracing_prog_attach() does not reject tail-call-reachable extensions on non-tail-call BPF_PROG_TYPE_RAW_TRACEPOINT targets. Running BPF_PROG_TEST_RUN on such a raw_tp target with ctx_size_in 0 leaves info.ctx NULL, so a tail-called raw_tp callee reading *(u64 *)(ctx + 88) dereferences NULL (or reads past an 8-byte buffer when ctx_size_in is 8). Either bpf_tracing_prog_attach() should reject tail-call-reachable extensions on non-tail-call raw_tp targets, or bpf_prog_test_run_raw_tp() should unconditionally allocate the full 96-byte raw_tp context. > + > + if (size) { > + info.ctx =3D kvzalloc(size, GFP_KERNEL_ACCOUNT | __GFP_NOWARN); > + if (!info.ctx) > + return -ENOMEM; [Severity: Medium] Why pad info.ctx to U16_MAX with kvzalloc() instead of MAX_BPF_FUNC_ARGS * sizeof(u64) (96 bytes)? bpf_tracing_ctx_access() rejects any BPF_PROG_TYPE_RAW_TRACEPOINT context access at or above 96 bytes, and raw_tp programs can only tail-call other raw_tp programs, so no reachable target can ever access past 96 bytes. Allocating 65,535 bytes on every test_run (which does not support repeat) bypasses SLUB caches, hitting order-4 buddy allocations or vmalloc/vfree while zeroing 64 KiB instead of 96 bytes. Padding to MAX_BPF_FUNC_ARGS * sizeof(u64) via kzalloc() avoids this. The commit message example of *(u64 *)(ctx + 96) is also inaccurate, since bpf_tracing_ctx_access() rejects offsets >=3D 96. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205090934.3813= 585-1-r41k0u@ubuntu.com?part=3D1