From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796225914; b=JOjFcbUele08+kyxmabbET4oQ25n1OSnkMGCs2G4kWg+AebegcWM2qkuMOU1tslB13tF l1p709U+Fl1zJQLcJrHD7l9lEbmydCGRjki9F+9V8NkKydL6P43X5J2pyB++UdHWjMzA5 445+Ux/F1TDl2HUz7N1kEhNkCYXfyPhxZdVvJQm4nzgO/sm6wChAXugA0JSaUtNcMY7BJ sgWssWP9EkiN40Z0tnuLTu+Pw26PvggUPgvRi3nSfJi+VBbf6+9a/1a01UxuCp1Dy9W3+ +/eWf3bL+pu8+2/ihAhsfy9m7G6prkm9Ul5ynVJpMk9HgHtllbOWH0fMN9kBeLWq+4A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796225914; 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=esUX2qovnrqem5zBuMjub+QkrfctfbO+pt12he6JBJo=; b=WbiRzORWq0MVRr1F2MyR8J4aU0TN1beGOqifcLFxcM95EwazPOgiMEN9g0u0ROuJdnwO iP2IURj5W+Tq/djVbPrQxX1s8JlHDd6CHLnSPDMrP50mmbdqd11xJZ//POo18PV3G+ict cxKxyPGeLCscbf4QyXm6H9tSeGue/4osrzm15LINlIopmVphJx01Lo6GLb1pf81mMtjUy n0G3uDvaOprVxR1agz96iT2nXwHnh2kwqBKDX22jcBM3Z7y66+fbMJExbzysa+0ktov58 zeyKSlYIEm7ScNn7txXGAfVZA9aozvIoGoXMQM0mViyrTJFeIRR3OVRivjAagN5olng== 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=rsbjJerw; arc=none smtp.remote-ip=95.215.58.9 Received: from mta1.migadu.com (out-9.mta1.migadu.com [95.215.58.9]) (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 DB061606A322 for ; Wed, 2 Dec 2026 15:38:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DB061606A322 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=rsbjJerw X-Envelope-To: bpf@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ZrrEC7Ihig+uRALHBA1L8I+NeT8LWSw1a3n9Lyv0K6M=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796225912; v=1; x=1796830712; b=rsbjJerwao3d/Bsv7E6F0Ur60JNDk4yLF7zehOECmuV42gRfLyUVk+T9Q5xW0mvqHmk0ETww NhWOd9/KE/FdDRD2FIlcsTu9C4/CTh5QG+fyyiF3NdHmyMdKuUSIkjZVJc06G/wVNtNb70AMt9s xuAC89Cz61O7VafNZjVqQDqY= X-Envelope-To: bpf@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id dddfbdf704c04d8c; Wed, 02 Dec 2026 15:38:31 +0000 X-Mizu-Trace-ID: dddfbdf704c04d8c X-Migadu-Flow: FLOW_OUT From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , John Fastabend , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , James Clark , KP Singh , Matt Bobrowski , Shuah Khan , Leon Hwang , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next 3/4] bpf: Add log support for uprobe_multi link_create Date: Wed, 2 Dec 2026 23:37:38 +0800 Message-ID: <20261202153739.57959-4-leon.hwang@linux.dev> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261202153739.57959-1-leon.hwang@linux.dev> References: <20261202153739.57959-1-leon.hwang@linux.dev> X-Mailing-List: bpf@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 BPF_LINK_CREATE returns -EFAULT when it cannot read an offset, reference counter offset, or cookie. Userspace cannot tell which array or entry caused the failure from errno alone. Pass the link_create log through the uprobe multi and session attach path. Report invalid target path arguments and identify the failing entry when reading probe attributes or registering a uprobe. Signed-off-by: Leon Hwang --- include/linux/trace_events.h | 6 ++- kernel/bpf/syscall.c | 2 +- kernel/trace/bpf_trace.c | 77 ++++++++++++++++++++++++++++-------- 3 files changed, 66 insertions(+), 19 deletions(-) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index e855ca8a10f1..6e46a2a75e4c 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -798,7 +798,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id, unsigned long *missed); int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog, struct bpf_verifier_log *log); -int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog); +int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog, + struct bpf_verifier_log *log); int bpf_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr, struct bpf_verifier_log *log); #else @@ -856,7 +857,8 @@ bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog, return -EOPNOTSUPP; } static inline int -bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) +bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog, + struct bpf_verifier_log *log) { return -EOPNOTSUPP; } diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 25f4a0c9c9c1..152044e5fb62 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -6045,7 +6045,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_a ret = bpf_kprobe_multi_link_attach(attr, prog, log); else if (attr->link_create.attach_type == BPF_TRACE_UPROBE_MULTI || attr->link_create.attach_type == BPF_TRACE_UPROBE_SESSION) - ret = bpf_uprobe_multi_link_attach(attr, prog); + ret = bpf_uprobe_multi_link_attach(attr, prog, log); break; default: bpf_log(log, "Invalid prog type.\n"); diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 9ab7ceaed014..79e85c940f55 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -3282,23 +3282,30 @@ static u64 bpf_uprobe_multi_cookie(struct bpf_run_ctx *ctx) return run_ctx->uprobe->cookie; } -static int bpf_uprobe_multi_get_path(const union bpf_attr *attr, struct path *path) +static int bpf_uprobe_multi_get_path(const union bpf_attr *attr, struct path *path, + struct bpf_verifier_log *log) { void __user *upath = u64_to_user_ptr(attr->link_create.uprobe_multi.path); u32 path_fd = attr->link_create.uprobe_multi.path_fd; u32 flags = attr->link_create.uprobe_multi.flags; + int ret; if (flags & BPF_F_UPROBE_MULTI_PATH_FD) { /* * When BPF_F_UPROBE_MULTI_PATH_FD is set, the executable is * identified by path_fd, upath must be NULL. */ - if (upath) + if (upath) { + bpf_log(log, + "uprobe_multi.path must not be set when BPF_F_UPROBE_MULTI_PATH_FD is set.\n"); return -EINVAL; + } CLASS(fd, f)(path_fd); - if (fd_empty(f)) + if (fd_empty(f)) { + bpf_log(log, "Invalid uprobe_multi.path_fd.\n"); return -EBADF; + } *path = fd_file(f)->f_path; path_get(path); return 0; @@ -3308,13 +3315,23 @@ static int bpf_uprobe_multi_get_path(const union bpf_attr *attr, struct path *pa * When BPF_F_UPROBE_MULTI_PATH_FD is not set, the path is resolved * relative to the cwd (AT_FDCWD) or absolute using the upath string. */ - if (!upath || path_fd) + if (!upath) { + bpf_log(log, "uprobe_multi.path must be set.\n"); return -EINVAL; + } + if (path_fd) { + bpf_log(log, "uprobe_multi.path_fd must not be set.\n"); + return -EINVAL; + } - return user_path_at(AT_FDCWD, upath, LOOKUP_FOLLOW, path); + ret = user_path_at(AT_FDCWD, upath, LOOKUP_FOLLOW, path); + if (ret) + bpf_log(log, "Lookup path failed.\n"); + return ret; } -int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) +int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog, + struct bpf_verifier_log *log) { struct bpf_uprobe_multi_link *link = NULL; unsigned long __user *uref_ctr_offsets; @@ -3329,19 +3346,26 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr pid_t pid; int err; - /* no support for 32bit archs yet */ - if (sizeof(u64) != sizeof(void *)) + if (sizeof(u64) != sizeof(void *)) { + bpf_log(log, "No support for 32bit archs yet.\n"); return -EOPNOTSUPP; + } - if (attr->link_create.flags) + if (attr->link_create.flags) { + bpf_log(log, "flags must be zero.\n"); return -EINVAL; + } - if (!is_uprobe_multi(prog)) + if (!is_uprobe_multi(prog)) { + bpf_log(log, "expected_attach_type must be uprobe_multi or uprobe_session.\n"); return -EINVAL; + } flags = attr->link_create.uprobe_multi.flags; - if (flags & ~(BPF_F_UPROBE_MULTI_RETURN | BPF_F_UPROBE_MULTI_PATH_FD)) + if (flags & ~(BPF_F_UPROBE_MULTI_RETURN | BPF_F_UPROBE_MULTI_PATH_FD)) { + bpf_log(log, "Invalid uprobe_multi.flags.\n"); return -EINVAL; + } /* * offsets and cnt are mandatory, @@ -3353,8 +3377,11 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr if (!uoffsets || !cnt || pid < 0) return -EINVAL; - if (cnt > MAX_UPROBE_MULTI_CNT) + if (cnt > MAX_UPROBE_MULTI_CNT) { + bpf_log(log, "uprobe_multi.cnt %u is larger than limit %u.\n", + cnt, MAX_UPROBE_MULTI_CNT); return -E2BIG; + } uref_ctr_offsets = u64_to_user_ptr(attr->link_create.uprobe_multi.ref_ctr_offsets); ucookies = u64_to_user_ptr(attr->link_create.uprobe_multi.cookies); @@ -3365,15 +3392,25 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr * fails before anything is looked up or allocated. */ size = sizeof(*uoffsets) * cnt; - if (!access_ok(uoffsets, size) || !access_ok(uref_ctr_offsets, size) || - !access_ok(ucookies, size)) + if (!access_ok(uoffsets, size)) { + bpf_log(log, "offsets access check failed.\n"); return -EFAULT; + } + if (!access_ok(uref_ctr_offsets, size)) { + bpf_log(log, "ref_ctr_offsets access check failed.\n"); + return -EFAULT; + } + if (!access_ok(ucookies, size)) { + bpf_log(log, "cookies access check failed.\n"); + return -EFAULT; + } - err = bpf_uprobe_multi_get_path(attr, &path); + err = bpf_uprobe_multi_get_path(attr, &path, log); if (err) return err; if (!d_is_reg(path.dentry)) { + bpf_log(log, "Invalid path.\n"); err = -EBADF; goto error_path_put; } @@ -3383,6 +3420,7 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr task = get_pid_task(find_vpid(pid), PIDTYPE_TGID); rcu_read_unlock(); if (!task) { + bpf_log(log, "Invalid uprobe_multi.pid.\n"); err = -ESRCH; goto error_path_put; } @@ -3398,18 +3436,22 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr for (i = 0; i < cnt; i++) { if (get_user(uprobes[i].offset, uoffsets + i)) { + bpf_log(log, "Read offsets[%u] failed.\n", i); err = -EFAULT; goto error_free; } if (uprobes[i].offset < 0) { + bpf_log(log, "offsets[%u] must not be negative.\n", i); err = -EINVAL; goto error_free; } if (uref_ctr_offsets && get_user(uprobes[i].ref_ctr_offset, uref_ctr_offsets + i)) { + bpf_log(log, "Read ref_ctr_offsets[%u] failed.\n", i); err = -EFAULT; goto error_free; } if (ucookies && get_user(uprobes[i].cookie, ucookies + i)) { + bpf_log(log, "Read cookies[%u] failed.\n", i); err = -EFAULT; goto error_free; } @@ -3441,6 +3483,7 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr uprobes[i].ref_ctr_offset, &uprobes[i].consumer); if (IS_ERR(uprobes[i].uprobe)) { + bpf_log(log, "Register uprobes[%u] failed.\n", i); err = PTR_ERR(uprobes[i].uprobe); link->cnt = i; goto error_unregister; @@ -3466,8 +3509,10 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr return err; } #else /* !CONFIG_UPROBES */ -int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) +int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog, + struct bpf_verifier_log *log) { + bpf_log(log, "This kernel does not support uprobes.\n"); return -EOPNOTSUPP; } static u64 bpf_uprobe_multi_cookie(struct bpf_run_ctx *ctx) -- 2.55.0