From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 8B16C1A6819 for ; Mon, 30 Mar 2026 05:51:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774849906; cv=none; b=q+FauzBZU+JEB29RtUJ2nscdNEDwt3FrOxnk15tLJSVYrNLW8qgMjhNuh2bacd/B1aENpsY35dwvksYjcCwPiDr0rnpil5CJyx2gZBcFSWqik4vQ5Upw+9OYV1QT80Y0j03/QoVmreYaaQAsp7NU6++Dtvfg8qEyHrA7gDdcH6k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774849906; c=relaxed/simple; bh=h69unk6IdGQcnGcEAbMDZVMrP7GK6c3oW9vGjsESLkQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ftd3m5Xuu/AVNINXQkSmHyM5OXdnEpCl/fyFqx/7mRya/n2L5UpjpIA2WEVJDIRWFeAvWocoRUzwQEr3qQHFV2leqPrtSK3zYxz/ePT+xsotfmvkqcl9oUF6n/lIShgnhhAr/RohiN3DijqGQf9wF4tVeGsHY9K7Nc47goABdYk= 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=CSFe3j4v; arc=none smtp.client-ip=91.218.175.170 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="CSFe3j4v" Message-ID: <964c4090-d939-4d0b-a0fc-156feb3c0c68@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1774849901; 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=hCV2Xx45S8pCgxzDwB3s2LIMPJDnbsciGgZ7CqnTIaM=; b=CSFe3j4voYTNDqEEpPKqluWLTk+J3NFXow3aJ4jXqCVvqrmEFrJUTtTthn8f/AzprCXLQE 5w+GuGAB5Hghm/8bzU4hyuNjMfvI7/YidsRiv7fn0wJVfQinwcGR4XC6eq0V3dN3VgYkJ7 GD6VxxxfePe2LJZAIAw88ONWSGH1Z4A= Date: Mon, 30 Mar 2026 13:51:29 +0800 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next 2/3] bpf: Disallow freplace on kprobe with mismatched kprobe_write_ctx values Content-Language: en-US To: Jiri Olsa Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Shuah Khan , "David S . Miller" , Jakub Kicinski , Jesper Dangaard Brouer , Toke Hoiland-Jorgensen , Lorenzo Bianconi , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, kernel-patches-bot@fb.com References: <20260324150444.68166-1-leon.hwang@linux.dev> <20260324150444.68166-3-leon.hwang@linux.dev> 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: 7bit X-Migadu-Flow: FLOW_OUT On 28/3/26 04:41, Jiri Olsa wrote: > On Tue, Mar 24, 2026 at 11:04:43PM +0800, Leon Hwang wrote: [...] >> --- a/kernel/bpf/verifier.c >> +++ b/kernel/bpf/verifier.c >> @@ -6404,6 +6404,14 @@ static int check_ctx_access(struct bpf_verifier_env *env, int insn_idx, int off, >> /* remember the offset of last byte accessed in ctx */ >> if (env->prog->aux->max_ctx_offset < off + size) >> env->prog->aux->max_ctx_offset = off + size; >> + if (env->prog->type == BPF_PROG_TYPE_EXT) { >> + struct bpf_prog *dst_prog = env->prog->aux->dst_prog; >> + >> + if (env->prog->aux->kprobe_write_ctx != dst_prog->aux->kprobe_write_ctx) { >> + verbose(env, "Extension program cannot have different kprobe_write_ctx value with target prog\n"); >> + return -EINVAL; >> + } >> + } > > would it be more clear to check this in bpf_check_attach_target, > instead of depending on actual write to context > I've considered it. But we can't, because bpf_check_attach_target is before check_ctx_access at load time. Besides, sashiko has pointed out that this check in check_ctx_access can be bypassed when attaching to kprobe_write_ctx=false target [1]. So, I posted v2 to do the check in bpf_tracing_prog_attach at attach time [2]. [1] https://sashiko.dev/#/patchset/20260324150444.68166-1-leon.hwang%40linux.dev [2] https://lore.kernel.org/bpf/20260326141718.17731-1-leon.hwang@linux.dev/ Thanks, Leon