🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16358

[PATCH bpf-next v2 3/9] bpf: Add log support for iter link_create

#16358
From: Leon Hwang
Date: Sat, 14 Nov 2026 15:06
117 lines
13194 bytes
iter BPF_LINK_CREATE returns an error without explaining invalid target
FDs, flags, or iterator information, or an unsupported program.

Pass the BPF_LINK_CREATE log to the iter attach path and report these
failures.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
 include/linux/bpf.h   |  3 ++-
 kernel/bpf/bpf_iter.c | 27 +++++++++++++++++++++------
 kernel/bpf/syscall.c  |  2 +-
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 36587b63ce13..c3f6364bc1d8 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -3276,7 +3276,8 @@ void bpf_iter_unreg_target(const struct bpf_iter_reg *reg_info);
 int bpf_iter_prog_supported(struct bpf_prog *prog);
 const struct bpf_func_proto *
 bpf_iter_get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog);
-int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_prog *prog);
+int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr, struct bpf_prog *prog,
+			 struct bpf_verifier_log *log);
 int bpf_iter_new_fd(struct bpf_link *link);
 bool bpf_link_is_iter(struct bpf_link *link);
 struct bpf_prog *bpf_iter_get_info(struct bpf_iter_meta *meta, bool in_stop);
diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
index f0b29a170935..4a9e08fb8e75 100644
--- a/kernel/bpf/bpf_iter.c
+++ b/kernel/bpf/bpf_iter.c
@@ -5,6 +5,7 @@
 #include <linux/anon_inodes.h>
 #include <linux/filter.h>
 #include <linux/bpf.h>
+#include <linux/bpf_verifier.h>
 #include <linux/rcupdate_trace.h>
 
 struct bpf_iter_target_info {
@@ -528,7 +529,7 @@ bool bpf_link_is_iter(struct bpf_link *link)
 }
 
 int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
-			 struct bpf_prog *prog)
+			 struct bpf_prog *prog, struct bpf_verifier_log *log)
 {
 	struct bpf_iter_target_info *tinfo = NULL, *iter;
 	struct bpf_link_primer link_primer;
@@ -538,24 +539,36 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
 	bpfptr_t ulinfo;
 	int err;
 
-	if (attr->link_create.target_fd || attr->link_create.flags)
+	if (attr->link_create.target_fd) {
+		bpf_log(log, "Invalid target_fd.\n");
+		return -EINVAL;
+	}
+	if (attr->link_create.flags) {
+		bpf_log(log, "Invalid flags.\n");
 		return -EINVAL;
+	}
 
 	memset(&linfo, 0, sizeof(union bpf_iter_link_info));
 
 	ulinfo = make_bpfptr(attr->link_create.iter_info, uattr.is_kernel);
 	linfo_len = attr->link_create.iter_info_len;
-	if (bpfptr_is_null(ulinfo) ^ !linfo_len)
+	if (bpfptr_is_null(ulinfo) ^ !linfo_len) {
+		bpf_log(log, "iter_info and iter_info_len must be both set or both unset.\n");
 		return -EINVAL;
+	}
 
 	if (!bpfptr_is_null(ulinfo)) {
 		err = bpf_check_uarg_tail_zero(ulinfo, sizeof(linfo),
 					       linfo_len);
-		if (err)
+		if (err) {
+			bpf_log(log, "Invalid iter_info_len.\n");
 			return err;
+		}
 		linfo_len = min_t(u32, linfo_len, sizeof(linfo));
-		if (copy_from_bpfptr(&linfo, ulinfo, linfo_len))
+		if (copy_from_bpfptr(&linfo, ulinfo, linfo_len)) {
+			bpf_log(log, "Invalid iter_info.\n");
 			return -EFAULT;
+		}
 	}
 
 	prog_btf_id = prog->aux->attach_btf_id;
@@ -570,8 +583,10 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
 	if (!tinfo)
 		return -ENOENT;
 
-	if (!bpf_iter_target_support_prog(tinfo, prog))
+	if (!bpf_iter_target_support_prog(tinfo, prog)) {
+		bpf_log(log, "The iter target does not support the bpf prog.\n");
 		return -EINVAL;
+	}
 
 	link = kzalloc_obj(*link, GFP_USER | __GFP_NOWARN);
 	if (!link)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 3c7bedced354..9627dfc982ff 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -5929,7 +5929,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_a
 			ret = bpf_raw_tp_link_attach(prog, NULL, attr->link_create.tracing.cookie,
 						     attr->link_create.attach_type);
 		else if (prog->expected_attach_type == BPF_TRACE_ITER)
-			ret = bpf_iter_link_attach(attr, uattr, prog);
+			ret = bpf_iter_link_attach(attr, uattr, prog, log);
 		else if (prog->expected_attach_type == BPF_LSM_CGROUP)
 			ret = cgroup_bpf_link_attach(attr, prog);
 		else if (is_tracing_multi(prog->expected_attach_type))
-- 
2.55.0
Technical Details
Message-ID: <20261114150610.84507-4-leon.hwang@linux.dev>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363326-linux-kernel-netdev=dewy.ru
References: <20261114150610.84507-1-leon.hwang@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363326-linux-kernel-netdev=dewy.ru
From: leon.hwang@linux.dev (Leon Hwang)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf-next v2 3/9] bpf: Add log support for iter link_create
Date: Sat, 14 Nov 2026 23:06:04 +0800
Organization: Usenet Network
Message-ID: <20261114150610.84507-4-leon.hwang@linux.dev>
References: <20261114150610.84507-1-leon.hwang@linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1595569"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ION0mnEdE/sr1sSfzH6BtdrJM9U= sha256:wl6adcg/iKRnYbFyPpmqzM5dyIt2jM3RtrDj0cVsY18=
	sha1:yRPQx1xir5Su3iXk8Ca07GrZwUU= sha256:yuuOtwBDRUlKgAyoy90Lfh0NIktB4uXRouJJNDnXWHk=
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 607E6114841; Sat, 14 Nov 2026 18:07:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 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, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
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 nwce7casY6F3;
	Sat, 14 Nov 2026 18:07:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-363326-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id B4C6911480E; Sat, 14 Nov 2026 18:07:24 +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 E477161330; Sat, 14 Nov 2026 15:07:06 +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=1794668814;
	b=3wr27qT+7+yg6ETFPoEbXeI18yzngIndIPhkAOHCWwFDBisdeGPO24a+Lc79Nt3ApT/s
	 sQJVWyeuLVNinbAiANyJjJvAuzfLvbbq3cTynh+ziuIjFziNUFh1rRpGcljCg/K7ywMU3
	 q2wGSbaPOemgm6JiBdXvzLb51m2VIHCawfLfG1y0KZZ657JVjDnkcfo3iJcbI7/ApJ+pG
	 xc4IhCYBUCib4odRzAYGQSydldrsvL+tG2jqFaEqbR1G6+eS/YHFbevknI4kczwxkcm1r
	 jPI+U4+/9veXWjH0a5SdFhtL0yfkIPKLeH7y82NBYsfz7B0UNdIv2cIwoWsO8Qw13hA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794668814;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:
	 Subject:Date:Message-ID: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=RsHHVBz4ZNykhyuHHl7F7hpn28PT4e0tNAmtvkjgmeE=;
	b=VJaBsCjRCmo+z13//xyJ0lT4IJi3il+SVQhV2oHyYh+hJoTUPEszDOMvwOURJSfQWcIN
	 LKlRz2EONkP4vZyaBJhozG17EdUV/+/f09KOWrJwMAu9j0Yn4phMlzznvJ4OURcNMPYrm
	 sWaFu8tgHcW0DStlKbeI/I8x5h6pojl0hISqltVu3k9Unj/3zLYMcBVwlrZzIvYEPYMAY
	 gGYi+GmvkK31Gr0/AwfpLAO0bkDKHMAhZPfq57dvS0dRBOTQminQFW+zkCSmV5So3mdpL
	 FF7ngm/oBaaey7sqDB3nPO/xJU6d6AjU3te9wm5WiFgF9bgRX4aZGboIYtD39YRLJxQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=dG7Yrpcg;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	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 5721C606A8B4;
	Sat, 14 Nov 2026 15:06:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=dG7Yrpcg
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.236
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794668813;
	b=EFXUEd2hfifORGv9lnRtYZSac/pvsFvtK6HwDnY0okeuUGvXa8t7g559wnOL4gUUZ4c4
	 LeizpyrdrFVI7B6xHGktmFRI3elcv8ANclNbiyANxkg592znNM4l1zwQXgppEwM1TYE1W
	 uMb68d7N7WaB+qGIDkaB21y9cma6dt9AfZ+N3TKEThgRXrXWaCcyBOKL1M7NCmduexVQl
	 upSi499P3Z4wU5oDJ7uo+hscLaPf7LwWn65xR8ProIklIl+JXTjOO1+tYkjv5nRM4dUr3
	 +WX2Nps6s5LAuyYsWdCBUO4XTCER3AD6WOXdR/Y1JrqSwcYxL59Az7OyElX/XLOyc1A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794668813;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=RsHHVBz4ZNykhyuHHl7F7hpn28PT4e0tNAmtvkjgmeE=;
	b=0FYWN1DpOlxg0UAhGnIVofolij4qZvEOKdUux9Rv52gFaNboSNgMfKtrD0Dxf3RYisRx
	 ECiyTwgCh71ZiHtZA2BEmQZmfdWSMjFq+Zzx50/4ht0XQVVmM9BJNcUZLtK69ieq6PelZ
	 ukzauX5DQhfohfHRhSr8w250LPKCgyBFdA0hhEs/gSCNks+i9JoyKCVrYC/GEoPm1OQUP
	 hCZJcvUVOdizIa5cJM2tzQQym14Wvr5lK49sgMXynXn0jySvGka0GZbDw+h3tia05uW0e
	 W/ZHK1fJdn2dnQhAxtK1PKF3d5o3As0sBzgVxpAZ2fPTjQaLBwApunmP90UI7flu6Ow==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=dG7Yrpcg;
	arc=none smtp.remote-ip=95.215.58.236
X-Received: from mta1.migadu.com (out-236.mta1.migadu.com [95.215.58.236])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8D81606A8A0
	for <netdev@vger.kernel.org>; Sat, 14 Nov 2026 15:06:52 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D8D81606A8A0
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=/d5WAk3pXKg0/LNXjM0Lk5R7/0/qIg0Q1jedtEcIIb0=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1794668811; v=1; x=1795273611;
 b=dG7Yrpcg1mN8kPaNV1EMEe+tWt/1GdxH1CJSlTEWC3TXoUfvgddVWP+f6xtFB3VBJxSYEzhA
 n/VwZS3sfwwJKyTCJuw6bUHogI/ADfqZp3wUn2E9/mXyNV/1nw5cZJpfl6RTmnil+94dygZklvh
 3nwXATlj0emev0xoMiNuFUt0=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 1b8f8a06801f7860;
	Sat, 14 Nov 2026 15:06:50 +0000
X-Mizu-Trace-ID: 1b8f8a06801f7860
X-Migadu-Flow: FLOW_OUT
X-Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	KP Singh <kpsingh@kernel.org>,
	Matt Bobrowski <matt@bobrowski.net>,
	Shuah Khan <shuah@kernel.org>,
	Leon Hwang <leon.hwang@linux.dev>,
	linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	netdev@vger.kernel.org
X-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261114150610.84507-1-leon.hwang@linux.dev>
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