From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796225901; b=y0d5YvFqEKPKF5b+hJhQBrTy66tqOZPK0MeimStjrChUH97muBi6wlDSsfMe2cM8e3fA KaYl3RjXsA/Q/acUuv9is/yKuAwsHYexVrmwJZiAc+64Y+1l/3qcoZAjrp7ZA3IP2uAu7 HPEOUrvMLEeurB+UW7P31tTrfkLYnwgtUW6vLg2opj9akTMd367shJxEO1d4Q0d+HFVpj FXvhyIcLM8i+Mji/VA6KNqTHSoSjl3NFUWKKrSnNIcmjFKQT486wyNqLCaoCTQlsGeaWd ZTV5RravBAFGi1TpnIeQV3dsUn5BuW01rXPB6QRLC3odLga8x9x6sy61bNDkMQCtDSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796225901; 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=G7HKOU1aBiX12t/RXxo/kVrIEd0Byq8oUA7UsJxHVRQ=; b=l4FPM6AFgqDhZY5xicpHkmR0zPZ9g7vHwkM5CQJPG/FZKGyRUDoImjiwh2cLFzE1f1k8 mKWWaeTmmmw7KDyBmThG0paa+rZkStxC/UW5jtUv6ShynvU0ai9MJyNIwDrg6bDG4aMDY Z4XrtDGwRzeaC8Y/8c+/4GhzcykuQurElakFQAmpeH8SGbgf3viaf/Qaa6/Zcxv28/Gju 54ed848ZONR8p5PSoC0eBvKG7tZT2mUc4JUg634t5QIvtnSSPKXxzqWRwsbrqXL5Ontip mN9kT4wppTNxSjFhqiasS51c33vBPo4XawmzYjqSsVLgsHg2QWWZXS0I8C9QWOtVDxg== 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=Su9f5qH4; arc=none smtp.remote-ip=91.218.175.176 Received: from mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) (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 38AAC606A31A for ; Wed, 2 Dec 2026 15:38:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 38AAC606A31A 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=Su9f5qH4 X-Envelope-To: bpf@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=Bv3TMFd9baicE1N7AdbXezrGYscHQ6cDgbUYraAkGag=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796225899; v=1; x=1796830699; b=Su9f5qH471aDM7A0CW6TTF+PiG4Kd4xhjMWjlsBT+ixID5GtvHfJLwOlv0H6VkTEjVBLYIcO QHRdt2GXs8AnXvt2G8fkSiGmWUOmI7s6cbeSfI6rK3bZqAl7zAl6wQCk/Ch6nqmE5Wlqy4fp0lJ Fh3KPQH8fTIaT+iVE20sfj/U= X-Envelope-To: bpf@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 9f52c3a9194ac0d1; Wed, 02 Dec 2026 15:38:19 +0000 X-Mizu-Trace-ID: 9f52c3a9194ac0d1 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 2/4] bpf: Add log support for kprobe_multi link_create Date: Wed, 2 Dec 2026 23:37:37 +0800 Message-ID: <20261202153739.57959-3-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 for unreadable kprobe_multi target or cookie arrays. It also returns -E2BIG for both too many probes and an overlong symbol name. Pass the link log through kprobe multi and session attachment. Identify the failed check or unreadable array, and include the index when reading a symbol pointer or name fails or the name is too long. Signed-off-by: Leon Hwang --- include/linux/trace_events.h | 6 ++-- kernel/bpf/syscall.c | 2 +- kernel/trace/bpf_trace.c | 66 ++++++++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 0fe900813581..e855ca8a10f1 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -796,7 +796,8 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id, u32 *fd_type, const char **buf, u64 *probe_offset, u64 *probe_addr, unsigned long *missed); -int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog); +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_tracing_multi_attach(struct bpf_prog *prog, const union bpf_attr *attr, struct bpf_verifier_log *log); @@ -849,7 +850,8 @@ static inline int bpf_get_perf_event_info(const struct perf_event *event, return -EOPNOTSUPP; } static inline int -bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) +bpf_kprobe_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 2cd1846e5c76..25f4a0c9c9c1 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -6042,7 +6042,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_a ret = bpf_perf_link_attach(attr, prog, log); else if (attr->link_create.attach_type == BPF_TRACE_KPROBE_MULTI || attr->link_create.attach_type == BPF_TRACE_KPROBE_SESSION) - ret = bpf_kprobe_multi_link_attach(attr, prog); + 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); diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 44ea62054f81..9ab7ceaed014 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2404,7 +2404,8 @@ static unsigned long ftrace_get_entry_ip(unsigned long fentry_ip) return ip ? : fentry_ip; } -static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt) +static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt, + struct bpf_verifier_log *log) { unsigned long __user usymbol; const char **syms = NULL; @@ -2412,8 +2413,10 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 int err = -ENOMEM; unsigned int i; - if (!access_ok(usyms, cnt * sizeof(*usyms))) + if (!access_ok(usyms, cnt * sizeof(*usyms))) { + bpf_log(log, "Symbols access check failed.\n"); return -EFAULT; + } syms = kvmalloc_objs(*syms, cnt); if (!syms) @@ -2425,14 +2428,20 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 for (p = buf, i = 0; i < cnt; i++) { if (get_user(usymbol, usyms + i)) { + bpf_log(log, "Read syms[%u] pointer failed.\n", i); err = -EFAULT; goto error; } err = strncpy_from_user(p, (const char __user *) usymbol, KSYM_NAME_LEN); - if (err == KSYM_NAME_LEN) + if (err == KSYM_NAME_LEN) { + bpf_log(log, "Syms[%u] is too long.\n", i); err = -E2BIG; - if (err < 0) goto error; + } + if (err < 0) { + bpf_log(log, "Copy syms[%u] name failed.\n", i); + goto error; + } syms[i] = p; p += err + 1; } @@ -2813,7 +2822,8 @@ static int addrs_check_error_injection_list(unsigned long *addrs, u32 cnt) return 0; } -int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) +int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog, + struct bpf_verifier_log *log) { struct bpf_kprobe_multi_link *link = NULL; struct bpf_link_primer link_primer; @@ -2825,38 +2835,53 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr void __user *usyms; 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_kprobe_multi(prog)) + if (!is_kprobe_multi(prog)) { + bpf_log(log, "expected_attach_type must be kprobe_multi or kprobe_session.\n"); return -EINVAL; + } - /* kprobe_multi is not allowed to be sleepable. */ - if (prog->sleepable) + if (prog->sleepable) { + bpf_log(log, "Sleepable prog is not allowed.\n"); return -EINVAL; + } - /* Writing to context is not allowed for kprobes. */ - if (prog->aux->kprobe_write_ctx) + if (prog->aux->kprobe_write_ctx) { + bpf_log(log, "Writing to context is not allowed.\n"); return -EINVAL; + } flags = attr->link_create.kprobe_multi.flags; - if (flags & ~BPF_F_KPROBE_MULTI_RETURN) + if (flags & ~BPF_F_KPROBE_MULTI_RETURN) { + bpf_log(log, "Invalid kprobe_multi.flags.\n"); return -EINVAL; + } uaddrs = u64_to_user_ptr(attr->link_create.kprobe_multi.addrs); usyms = u64_to_user_ptr(attr->link_create.kprobe_multi.syms); - if (!!uaddrs == !!usyms) + if (!!uaddrs == !!usyms) { + bpf_log(log, + "Exactly one of kprobe_multi.addrs and kprobe_multi.syms must be set.\n"); return -EINVAL; + } cnt = attr->link_create.kprobe_multi.cnt; if (!cnt) return -EINVAL; - if (cnt > MAX_KPROBE_MULTI_CNT) + if (cnt > MAX_KPROBE_MULTI_CNT) { + bpf_log(log, "kprobe_multi.cnt %u is larger than limit %u.\n", + cnt, MAX_KPROBE_MULTI_CNT); return -E2BIG; + } size = cnt * sizeof(*addrs); addrs = kvmalloc_objs(*addrs, cnt); @@ -2871,6 +2896,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr goto error; } if (copy_from_user(cookies, ucookies, size)) { + bpf_log(log, "Read cookies failed.\n"); err = -EFAULT; goto error; } @@ -2878,6 +2904,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr if (uaddrs) { if (copy_from_user(addrs, uaddrs, size)) { + bpf_log(log, "Read addrs failed.\n"); err = -EFAULT; goto error; } @@ -2887,7 +2914,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr }; struct user_syms us; - err = copy_user_syms(&us, usyms, cnt); + err = copy_user_syms(&us, usyms, cnt, log); if (err) goto error; @@ -2904,6 +2931,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr } if (prog->kprobe_override && addrs_check_error_injection_list(addrs, cnt)) { + bpf_log(log, "All kprobe override targets must be on the error injection list.\n"); err = -EINVAL; goto error; } @@ -2969,8 +2997,10 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr return err; } #else /* !CONFIG_FPROBE */ -int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) +int bpf_kprobe_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 fprobe.\n"); return -EOPNOTSUPP; } static u64 bpf_kprobe_multi_cookie(struct bpf_run_ctx *ctx) -- 2.55.0