From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 956AA27280F for ; Wed, 25 Feb 2026 15:16:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772032579; cv=none; b=E7sDDSBaBMi0TZEJBjMhdCLP4fAg1wGVeLNB6EeonZllPtQscfgqYBoBlTNVimGbM6fKjAdoMK/+iofe+WpfpnGSjzGxshCnNIrwdc7MU+rlgw2rPSddX+aOxgQkvr6IccUBHaagHU22NTcrgflP2FB3PZM3GUPc7YF530ewa70= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772032579; c=relaxed/simple; bh=2v4+h7fONrljMow2c+RVTQnuVYSvEGGP7MQ7qIyqGpc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KIeMvKa11KBJhiczeB2cxvjdRjx/6f8OiG43HG5M/X+2WGmW7kTDa7+DUhl3R2eeQqs/Qrpc9Tkm4lsoAxC5MpWeqjsZCnVPc/P5bakGcCsqkHJQLcGc7bwNy8dCNLF24D4H80nPvlfxrH77g6LZU+Ao573w8QurwrQbtK+tSqc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=wtFB3V3h; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="wtFB3V3h" Message-ID: <0383ff36-df20-4376-9374-99ff32a527f4@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772032575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+ht1IsfkuNiCWNDQxQQ9oeNsmgvwISL3gSGHhQ9b5ks=; b=wtFB3V3hJzoIj/6NCuu3CNIh/Ni0VeK128IyhG0t+3YpgSOC3/IIplpDBSjrRLxQ6uFU0E OOT9IHx1+YFteW01mvPoNroI5jrz/FoIOqnIUUeLVf1zFZQyfPr/axPf9h3HUj1g1i7JCN dmNqcRNbf5fp3U4Vq8kXZ1O+wL5qpXg= Date: Wed, 25 Feb 2026 23:15:52 +0800 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next 2/8] bpf: Disallow !kprobe_write_ctx progs tail-calling kprobe_write_ctx progs To: Alexei Starovoitov Cc: bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Feng Yang , Menglong Dong , Puranjay Mohan , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Pu Lehui , LKML , "open list:KERNEL SELFTEST FRAMEWORK" , Network Development , kernel-patches-bot@fb.com References: <20260224154024.12504-1-leon.hwang@linux.dev> <20260224154024.12504-3-leon.hwang@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Leon Hwang In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2026/2/25 00:57, Alexei Starovoitov wrote: > On Tue, Feb 24, 2026 at 7:41 AM Leon Hwang wrote: >> >> uprobe programs that can modify pt_regs require different runtime >> assumptions than pt_regs-read-only uprobe programs. Mixing both in >> one prog_array can make owner expectations diverge from callee behavior. >> >> Reject the combination of !kprobe_write_ctx progs with kprobe_write_ctx >> progs in __bpf_prog_map_compatible() to address the issue. >> >> Fixes: 7384893d970e ("bpf: Allow uprobe program to change context registers") >> Signed-off-by: Leon Hwang >> --- >> include/linux/bpf.h | 7 ++++--- >> kernel/bpf/core.c | 3 +++ >> 2 files changed, 7 insertions(+), 3 deletions(-) >> >> diff --git a/include/linux/bpf.h b/include/linux/bpf.h >> index b78b53198a2e..2a2f6448a5fb 100644 >> --- a/include/linux/bpf.h >> +++ b/include/linux/bpf.h >> @@ -285,9 +285,10 @@ struct bpf_list_node_kern { >> */ >> struct bpf_map_owner { >> enum bpf_prog_type type; >> - bool jited; >> - bool xdp_has_frags; >> - bool sleepable; >> + u32 jited:1, >> + xdp_has_frags:1, >> + sleepable:1, >> + kprobe_write_ctx:1; > > Don't you see how much churn you're adding this way? > Every patch has to touch two lines instead of one. > Use > u32 jited:1; > u32 xdp_has_frags:1; > Ack. > also the bot is correct on patch 2 and 3. Agreed. Here's a concrete example that breaks the constraint: struct { __uint(type, BPF_MAP_TYPE_PROG_ARRAY); __uint(max_entries, 1); __uint(key_size, sizeof(__u32)); __uint(value_size, sizeof(__u32)); } jmp_table SEC(".maps"); SEC("?kprobe") int prog_a(struct pt_regs *regs) { regs->ax = 0; bpf_tail_call_static(regs, &jmp_table, 0); return 0; } SEC("?kprobe") int prog_b(struct pt_regs *regs) { bpf_tail_call_static(regs, &jmp_table, 0); return 0; } The jmp_table is shared between prog_a and prog_b. The constraint can be broken by: * Load prog_a first. At this point, owner->kprobe_write_ctx=true. * Load prog_b next. At this point, prog_b passes the prog map compatibility validation. * Add prog_a to jmp_table. * Attach prog_b to a kernel function. When the kernel function runs, the regs will be updated via prog_a. > Don't be fancy. Require strict conformance both ways in *all* patches. > It was to avoid awkward UX. For example, the tail call from prog_a (kprobe_write_ctx=true) to prog_b (kprobe_write_ctx=false) should be allowed. If prog_b is required to be kprobe_write_ctx=true, prog_b will break user's expectation that prog_b should not always update ctx. The same awkward UX applies to call_get_func_ip, call_session_cookie, and call_session_is_return. I'll find a way to avoid such awkward UX by keeping the one-directional validation, and to avoid the aforementioned constraint-broken issue at the same time. > And your codex selftests are garbage. I don't have other words > to describe it. They are not testing the actual bug that > your patches are fixing. Think of what you're doing. > Asking LLM to write a test for your other patch is not what you > should be asking it to do. The selftest should be such that > it proves the unsafety/crash before the fix. > OK. I'll reimplement the selftests by myself in the next revision. Thanks, Leon