🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12950

Re: [PATCH bpf] bpf: check cpu_possible() in per-cpu helpers

#12950
From: bo cao
Date: Mon, 09 Nov 2026 02:41
43 lines
10977 bytes
> please trim the commit message down, it's way too verbose

Will do -- a trimmed version follows as v4.

> not sure this is right, bpf_per_cpu_ptr_proto specifies
>
>  .ret_type      = RET_PTR_TO_MEM_OR_BTF_ID | PTR_MAYBE_NULL | MEM_RDONLY,
>
> it already is marked as maybe_null

The proto is marked, but check_helper_call() drops the flag on the
path this hunk touches.  For BPF_FUNC_per_cpu_ptr with a percpu obj
argument (R1 tagged MEM_RCU), returns_cpu_specific_alloc_ptr is set,
and the return type is then assigned as:

	if (returns_cpu_specific_alloc_ptr) {
		regs[BPF_REG_0].type = PTR_TO_BTF_ID | MEM_ALLOC | MEM_RCU;
	} else {
		/* MEM_RDONLY may be carried from ret_flag, but it
		 * doesn't apply on PTR_TO_BTF_ID.  Fold it, otherwise ...
		 */
		ret_flag &= ~MEM_RDONLY;
		regs[BPF_REG_0].type = PTR_TO_BTF_ID | ret_flag;
	}

The cpu-specific branch does not carry ret_flag at all, so
PTR_MAYBE_NULL never reaches R0 there -- only the ksym path (the
else branch) keeps it.  Nothing after the switch re-adds the flag
for this case either: the code below only assigns an id when the
register type is already maybe-null, and clears the flag for
ptr-cast functions.

Since bpf_per_cpu_ptr() does return NULL for cpu >= nr_cpu_ids
(since 01cc55af9388), a program that calls it on a percpu obj and
writes through the result without the NULL test passes verification
and oopses on NULL + offset at run time.  The hunk carries
(ret_flag & PTR_MAYBE_NULL) into that branch, which only restores
what the proto already declares.

Thanks,
Bo Cao
Technical Details
Message-ID: <tencent_3455CE5C67BEF809176851A476321557E70A@qq.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358983-linux-kernel-netdev=dewy.ru
References: <CAEf4BzYDmzNoN-5Rnfj4RrAU8wKnZe+tDFApng61L0mubXqung@mail.gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358983-linux-kernel-netdev=dewy.ru
From: treebacker@foxmail.com (bo cao)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH bpf] bpf: check cpu_possible() in per-cpu helpers
Date: Mon,  9 Nov 2026 10:41:34 +0800
Organization: Usenet Network
Message-ID: <tencent_3455CE5C67BEF809176851A476321557E70A@qq.com>
References: <CAEf4BzYDmzNoN-5Rnfj4RrAU8wKnZe+tDFApng61L0mubXqung@mail.gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="255103"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:nXTVrJmRQs345DclH3lNJwuIALo= sha256:lOtryF6tTobJVCOVkdxUTRtFoglnRfrA/gtav2HgrhA=
	sha1:kNEuwwB/LWqYorlWdOqZManIU2U= sha256:Dw7qYXbW7QNq4utilOcq7OuzfHh+6AxyZfVmSdwEA4s=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 7BE091136AA; Mon,  9 Nov 2026 05:42:32 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.575
X-Spam-Status: No, score=-0.575 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SORTED_RECIPS=2.474,
	SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=foxmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id c4AXE-yUkKug;
	Mon,  9 Nov 2026 05:42:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-358983-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=foxmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id B02E811362C; Mon,  9 Nov 2026 05:42:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id C028D8708C; Mon,  9 Nov 2026 02:41:51 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794192111;
	b=21TkDD+L/WWEeXkiJ4G7hN0ahLSEGRca9X0dXUg2iqxyiDe2+FP8ugfwc60TplmbtddY
	 GFjOZz4n3WnuyhVCEEtxEQV2MiAIP+6R7DuRZrsOn99H38G8ZX384Hx9qvkH7RwjZhiqi
	 +NdcuVk5avMacXtxrIQVRcHKMNlgQuGy4c+sRNhvFZumobN+h34aVJ8kjpKkaPCIry/v7
	 qPbbYtcIubKXnbeWfaHSTWIJ7hgWp6zRWwYIF+oAgma7yvxjuCWZ+E8L0Pj6VShSyQpwQ
	 vmPGf8r+h4jOi948JbhANGJGEA86fU8DmiNndE26wdFJythHbuD+FXgHkiIMUbMjvmw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794192111;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:
	 Message-ID:X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:
	 X-OQ-MSGID:X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Transfer-Encoding;
	bh=7Oaet72IvSMtzXaUg0NEIECqrGi+MmFL4ZFRzLknTqI=;
	b=cs0BznCnNl2KQZnVV44cP/6Lz24P9WXGdb4fanVqzbnhC6XkEMexztaWeejPUER0syFC
	 exCZxY4nk1bfH4/QQb35lsjIfBpoBI9MFDEyqHSSt1Zp53x8kpve4N2t3IdfIV40TL81Z
	 Sf+sV1y6L0qUx3jxYvWnE85lR09mZ+dCMlOW0uVPefMhoP4nkWpJCSQKefhlPovT3lCog
	 uOVe9I3YFs0eb+wqlbe0KgQ9ToOFhyjYVTJo96HRvbjE2iMuh1GFQsZ4R4IuMXO+oDkgx
	 uHMJbXAw1hP4JD/SLvwXHLRLtLNecULDNYrF3BMtQCsYEKFCaCohg/Mns3S5NltF1wA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=foxmail.com header.i=@foxmail.com header.a=rsa-sha256 header.s=s201512 header.b=rWOopgiE;
	dmarc=pass header.from=foxmail.com;
	spf=pass smtp.mailfrom=foxmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E789606A326;
	Mon,  9 Nov 2026 02:41:51 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.a=rsa-sha256 header.s=s201512 header.b=rWOopgiE
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=203.205.221.192
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794192103;
	b=FJWyuVfv2p60gUxCuDmbE4HGkxEfIVNj3d05Jr57Q2NKTAX2a1hGazGln4Cy4y2FEYii
	 fvWLjX6UP/supeE6EE+Bx36ZYSgkzdJmIc4JsVNNLnToGXjsXSwzuN/QIk5b80IoYZxsj
	 +3maj5rm5SeLzRjJJw/KhoHisvM66zH67sAWNQGH8iJJIng2mrWxoOcJR82rQPp7ApJm7
	 V2Qw5d7yNsBkiMzkHaAlY3ErrJdKRFkE4dXsTpvrQy2kXczpHLozJrvksGBIOi7h5yeX5
	 gmXM6dE/XbBq17440leiJLUWMoO7cssswRX3yeFXgcfYEtdZJF+wAVnXFyIB8/UEaFA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794192103;
	h=DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:Message-ID:
	 X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:X-OQ-MSGID:
	 X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=7Oaet72IvSMtzXaUg0NEIECqrGi+MmFL4ZFRzLknTqI=;
	b=uXtDTnE/ZOXI5C8CHEyU2DrM41M+svyz1WUN+CQ2CRVrrX26Q//aQtzVUPIswrCE0kHF
	 LKCe7mzYNdP1nIm9n0QOhUZdB5bF2kKXoAfPZ6aXuDeE19sJkk+mtigl49KW3uPbLnuoM
	 SvfmMPA1iNVw8IhKYcg9SRTJWv9JjBrIFAXxW93bWrwDMrVP3UuaRyuLMmWcVpNqJvq4J
	 z3ODo/1WXgddL4kPD4/nSUrqOs/WKGgmvap+RNjVHxULQym3ZO+XxQs5FMQwWuOleMT3K
	 N8vStcO3bgPBXHgtNTkzA9lpC82NDcsBODKHsKCGk/I0Z/aeCoHHOPKfr03U2kvIUAA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=foxmail.com;
	spf=pass smtp.mailfrom=foxmail.com;
	dkim=pass header.d=foxmail.com header.i=@foxmail.com header.a=rsa-sha256 header.s=s201512 header.b=rWOopgiE;
	arc=none smtp.remote-ip=203.205.221.192
X-Received: from out203-205-221-192.mail.qq.com (out203-205-221-192.mail.qq.com [203.205.221.192])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BBEF606A31C;
	Mon,  9 Nov 2026 02:41:40 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0BBEF606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foxmail.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com;
	s=s201512; t=1794192097;
	bh=7Oaet72IvSMtzXaUg0NEIECqrGi+MmFL4ZFRzLknTqI=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=rWOopgiEHK1q4WHZL/AlV2073gW+V3gZAMwMyxI8bxN7SXTNinr0gz8VCy9siesfk
	 ePzhUU/sypy1qy38nMn/97nOCZdZ63mAS1mXJvugb4JHBNfmrOa4jH7aTNquuvBJ7g
	 QDClkO3dKmLRgpXWFQ6sb4Cg5tRVfYIqpc8EKNU0=
X-Received: from HAPYCAO-MC1.tencent.com ([101.226.143.240])
	by newxmesmtplogicsvrszc50-0.qq.com (NewEsmtp) with SMTP
	id A628646A; Mon, 09 Nov 2026 10:41:34 +0800
X-QQ-mid: xmsmtpt1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h+vyaZXKZ6uT9+V9985ACODeyN8TYmGFDVCwlT
	 G9UBLgkNEUHggaanInWikx32g4PsHnD0+fgYhBNfsJpUnrmbx65FmszsbefJs=
X-QQ-XMRINFO: OD9hHCdaPRBwH5bRRRw8tsiH4UAatJqXfg==
X-Cc: andrii@kernel.org,
	ast@kernel.org,
	bpf@vger.kernel.org,
	daniel@iogearbox.net,
	netdev@vger.kernel.org,
	stable@vger.kernel.org
X-OQ-MSGID: <20261109024134.771-1-treebacker@foxmail.com>
X-Mailer: git-send-email 2.39.5 (Apple Git-154)
X-In-Reply-To: <CAEf4BzYDmzNoN-5Rnfj4RrAU8wKnZe+tDFApng61L0mubXqung@mail.gmail.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list