Re: [PATCH bpf-next v3 3/9] kallsyms: Add KALLSYMS_QUERY_BY_NAME ioctl to /proc/kallsyms
From: Samuel Wu
Date: Wed Nov 25 2026 - 19:48:31 EST
[...]
> > +/*
> > + * Find a symbol by exact name, or by prefix with KALLSYMS_QUERY_NAME_PREFIX,
> > + * in the entries of /proc/kallsyms, except undefined module symbols. vmlinux
> > + * matches come first. A module_filter of "vmlinux" selects the core kernel.
> > + *
> > + * Each call returns one match and sets pos to its position, even on
> > + * -ENAMETOOLONG. Start with pos 0 and use pos + 1 for the next match, until
> > + * -ENOENT. Use pos only with the same query. Matches can be skipped or
> > + * repeated if symbols change between calls.
> > + */
> > +struct kallsyms_query_by_name {
> > + __u64 size; /* in - sizeof(struct kallsyms_query_by_name) */
> > + __u64 query_flags; /* in - enum kallsyms_query_flags */
> > + __u64 query_name; /* in - user ptr to name or prefix */
> > + __u64 module_filter; /* in - user ptr to loaded module name, or 0 */
>
> similar to the comment on the previous patch, how does the user
> express that it only wants to search vmlinux image and not consult
> module?
>
> and naming nit: query_module to be consistent with "query_name"?
Passing "vmlinux" selects only the core kernel (noted in the block
comment above, missing inline). Will rename to query_module and note
"vmlinux" inline.
>
> > + __u64 pos; /* in/out - start position / match position */
> > + __u64 sym; /* in - user ptr to struct kallsyms_query_sym */
> > + __u64 sym_struct_size; /* in - sizeof(struct kallsyms_query_sym) */
>
> I'd name it "sym_size" for consistency with "sym" naming, and the
> comment/doc here is unambiguous about what that is (struct size, not
> the symbol's recorded size). seems fine as far as UX goes
>
Ack, will switch to sym_len
>
> other than nits, this API looks great
>
> [...]
>
> > +/* On -ENAMETOOLONG, *ksym is still copied, to return the required sizes. */
> > +static int kallsyms_copy_sym_to_user(u64 usym, u64 usym_size,
> > + struct kallsyms_query_sym *ksym,
> > + const struct kallsyms_sym_match *m)
> > +{
> > + size_t copy_sz = min_t(size_t, usym_size, sizeof(*ksym));
> > + bool too_long = false;
> > + int err;
> > +
> > + ksym->sym_addr = m->addr;
> > + ksym->sym_size = m->size;
> > + err = kallsyms_copy_str_to_user(ksym->sym_name, &ksym->sym_name_len,
> > + m->name);
> > + if (err == -EFAULT)
> > + return -EFAULT;
> > + too_long |= (err == -ENAMETOOLONG);
>
> nit: if (err == -ENAMETOOLONG) too_long = true; is just as short
>
> but also you are eating any other error, maybe write it so that
> original err is preserved as is, not special-casing ENAMETOOLONG? if
> you get EFAULT later, original error still takes precedence
Sounds good- I'll simplify this to preserve the first error via
something like `ret = ret ?: err` without any special handling for
ENAMETOOLONG.
[...]