From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr2-f1.google.com (mail-wr2-f1.google.com [74.125.225.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28AED3542F6 for ; Tue, 4 Aug 2026 09:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785835856; cv=none; b=e3E/UxgJsm9cHbs4foL1n1OWxgRANx+P4xbKVExZ27hCpdC9rFYvPwd4ZjI05tgcyiN5nbXqMS61efo2MnaEggSfp6TrougR1jWui1SY8MK3ZP4neTWETvECvqLhB5cXDNVFcWEZ4+c5y6DXqpW19aU9OqE725wdtphVSJVrHYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785835856; c=relaxed/simple; bh=Ve4w0qhxPiVUoHXilOQZmyI2gnoEdRUoGilk/iIGVYc=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=Y0kKN4uLdNlropgWNw1BcGL5KMoIvhCBZubSB4CzNJtMyeYZ6cSfT5J5IhxUPhyjQIi1hQeHQaYVant4N4alG9jLWRJZhwjDLMlS9lAWil0OSm5wEbdhk5Xv09iJN8vT71ah00V9ISqVG8Te/fWS+wePCCOcNn8SMJu43mCYwOI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bZynF5jY; arc=none smtp.client-ip=74.125.225.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bZynF5jY" Received: by mail-wr2-f1.google.com with SMTP id ffacd0b85a97d-47fad256d40so1856601f8f.0 for ; Tue, 04 Aug 2026 02:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785835851; x=1786440651; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=Ve4w0qhxPiVUoHXilOQZmyI2gnoEdRUoGilk/iIGVYc=; b=bZynF5jYPZcYTuqWj6rsvri34QpkQT9E0gng26Hp34cpVy/kkLIczXAODW0qo3Au6H MFqxOtGBS3MZwjjvVVxCXKL97jLi7USJTcQb8qhLzocVwWvmhNSvKm6yCBNu+AANqIBb +DPaz0pVdXy4xifwESvREKGvnTeiqKgS7YTsO608vsluzzp0yvrmhSlqp2q7OoaLxw4z NP6s19Pu4YT98oi9iiIioN174mgH80oPOtK9RNqZKJo8cZUe3wKtqMPulhgVXJTRzIRf aAPffBJFCXMmoP43zDiNSef2oJeoZW9vyDzJ/v1USC3dFuenlPIw1T2NS9Ger1omkpJn lu7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785835851; x=1786440651; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Ve4w0qhxPiVUoHXilOQZmyI2gnoEdRUoGilk/iIGVYc=; b=SaUPHT4XhVUN2O4N1Hjd90mJXiAURguLp88n4el/nsazHBbWUfCABDfK5KAhmSzlTp UnmqZ6bvto5EvI00x50st9bphyUie286ih6L+m8TOCm1NyV6FhjsZNH0+lv6M7r/+kBd ooRlCpE/aTKvXUKPwsj3LKDOC8Ua/3qjUw3JxLTkp+SGnhi6PzhA5xxOamm8d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32a9 with SMTP id ffacd0b85a97d-47fd72a8f3fmr34666122f8f.12.1785835851289; Tue, 04 Aug 2026 02:30:51 -0700 (PDT) Received: from localhost (nat-icclus-192-26-29-3.epfl.ch. [192.26.29.3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47fd458bb4esm40503735f8f.30.2026.08.04.02.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2026 02:30:50 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 04 Aug 2026 11:30:50 +0200 Message-Id: Cc: "Alexei Starovoitov" , "Daniel Borkmann" , "John Fastabend" , "Andrii Nakryiko" , "Eduard Zingerman" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" , "Ihor Solodrai" , "Dave Marchevsky" , Subject: Re: [PATCH bpf-next v2 1/2] bpf: Invalidate RCU pointers after final spin unlock From: "Kumar Kartikeya Dwivedi" To: "Ning Ding" , X-Mailer: aerc 0.21.0 References: <20260803112615.3362122-1-dingning04@gmail.com> <20260803112615.3362122-2-dingning04@gmail.com> In-Reply-To: <20260803112615.3362122-2-dingning04@gmail.com> On Mon Aug 3, 2026 at 1:26 PM CEST, Ning Ding wrote: > In a sleepable BPF program, a spin lock can provide the only RCU protecti= on > for a kptr. The final bpf_spin_unlock() ends that protection, but the > verifier leaves the pointer valid. Another CPU can then free the object > before the pointer is used. A capability-limited runtime PoC triggered a > task_struct use-after-free in __bpf_get_task_stack(). > > Record whether the program is in an RCU-protected context before releasin= g > the lock. Invalidate RCU-protected pointers only when the unlock leaves t= he > final such context. This preserves valid pointers in non-sleepable progra= ms > and inside an explicit RCU read-side section. > > Fixes: 5861d1e8dbc4 ("bpf: Allow bpf_spin_{lock,unlock} in sleepable prog= s") > Assisted-by: Codex:gpt-5.6-sol > Assisted-by: ChatGPT:GPT-5.6-Pro > Signed-off-by: Ning Ding > --- This patch set makes sense. I think while we are at it, we should improve t= he behavior here. For RCU unlock, we currently unconditionally invalidate refs when it hits z= ero, even though we may have other sources of RCU protection. The only reason it doesn't matter right now is probably because we cannot do a RCU read unlock within a spin lock critical section. We also do not currently consider bpf_preempt_disable() as providing RCU protection, even though we should. Could you extend the series with these changes? And corresponding tests whe= re possible? It might not be possible for all combinations, but we can test th= ose that are permitted. Unlike the correctness fix in this change, these are mostly usability paper cuts, so do not need a Fixes: tag. Thanks! > [...]