From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.112 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795447710; b=ohG4NI/3dZVmcawOLoIIDF0djgpBRPcUGj+nORe2M5igUxenXnwjhcIwHZ6SvwNS/xor z96cSrMrpaOlnjx9aKtLraQCx3xsoueph6KpS53SFOR9Li3df711O6UaGR939oVjjD3Hp MT42UNmlszQxFrX8cFINK9jaWXmetzo+kV159XwNMp00cq+TdTitCVYgdz0Z9Urry5p4k fCKKF6LsVF1QReyoPHkqzvjwZ2+W6hzAmtmZCKwTB+V9WKqgYTS7nzZVcX0TJ6aiTbsrb yPrpf0CVJPT/pg6y67ykqd7HnIEWvcZ8kN6U6z+Hfxv6VioppjquRCGy1hzJNh0I97A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795447710; 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=Xs14XeQIZZkFw3Clk4NIQHwRh+SuvZy2JNfCZ3YgPSk=; b=oW3lztlwIkuxL4XDdwVNRqCB+1cB8AVlFlVjiFjvrSJ6Poke2iXNS54+DyP1MeeU4/qM 7rI7reEzuiG/XeK7tdrqWOU4NWFZPWVnWaDrNymS+wWBBKrGiSm4tISrXZVDUCGzlKq9H 4a0B2ubKoP7iba/MRkyHgR9DSyG5uEunlO8b50EBYh9qpALV92djruZ+OieppCmf3EUT9 Lu2CTIEzGGvB+PfIsuLbEynrAEMkgBXl2drkrC+Y97WOz0o6ng1TGFMxlgEGqZYVxp8i+ un4ehTKrqcXQvrIHengYMeV6pue+1RSulgWTMMNG2GryTWPuAs/k3XnLiZ0PTb8sLUw== 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=ZI6uBJU5; arc=none smtp.remote-ip=95.215.58.112 Received: from mta1.migadu.com (out-112.mta1.migadu.com [95.215.58.112]) (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 CCDB5606A686 for ; Mon, 23 Nov 2026 15:28:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CCDB5606A686 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, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ZI6uBJU5 X-Envelope-To: linux-kselftest@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=eN/P0YGXODFl8WgmNNVBV2e2BDrvPZXuR1IIeoT2jzg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795447708; v=1; x=1796052508; b=ZI6uBJU53DWqPSRDIHqYitrRs3RX9N6IHPEl4JFfo39wOZAHsjF45hO5dMNbdD1dB6mdaNsy c1a3lNe5RVmReBERVbozhIivoqXLB1z6JvlGnhql0fxr6qjjjvYad7bkhEL0Gtg+lLFNlJXzSQy IfPb3KWB4+aB1P0toGotHjI4= X-Envelope-To: linux-kselftest@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id b990c6dbfefbb923; Mon, 23 Nov 2026 15:28:27 +0000 X-Mizu-Trace-ID: b990c6dbfefbb923 X-Migadu-Flow: FLOW_OUT From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , KP Singh , Matt Bobrowski , Shuah Khan , Leon Hwang , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH bpf-next v3 3/9] bpf: Add log support for iter link_create Date: Mon, 23 Nov 2026 23:27:37 +0800 Message-ID: <20261123152743.19629-4-leon.hwang@linux.dev> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261123152743.19629-1-leon.hwang@linux.dev> References: <20261123152743.19629-1-leon.hwang@linux.dev> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 a1ba3f54ba6a..e6d6a34a2818 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -3272,7 +3272,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 #include #include +#include #include 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 d3ab9c695129..f485e68a14ee 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -5950,7 +5950,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