Re: [PATCH v6 3/6] fs/procfs: add build ID fetching to PROCMAP_QUERY API

From: Jann Horn
Date: Mon Jul 29 2024 - 11:48:56 EST


On Thu, Jun 27, 2024 at 7:08 PM Andrii Nakryiko <andrii@xxxxxxxxxx> wrote:
> The need to get ELF build ID reliably is an important aspect when
> dealing with profiling and stack trace symbolization, and
> /proc/<pid>/maps textual representation doesn't help with this.
[...]
> @@ -539,6 +543,21 @@ static int do_procmap_query(struct proc_maps_private *priv, void __user *uarg)
> }
> }
>
> + if (karg.build_id_size) {
> + __u32 build_id_sz;
> +
> + err = build_id_parse(vma, build_id_buf, &build_id_sz);
> + if (err) {
> + karg.build_id_size = 0;
> + } else {
> + if (karg.build_id_size < build_id_sz) {
> + err = -ENAMETOOLONG;
> + goto out;
> + }
> + karg.build_id_size = build_id_sz;
> + }
> + }

The diff doesn't have enough context lines to see it here, but the two
closing curly braces above are another copy of exactly the same code
block from the preceding patch. The current state in mainline looks
like this, with two repetitions of exactly the same block:

[...]
karg.dev_minor = 0;
karg.inode = 0;
}

if (karg.build_id_size) {
__u32 build_id_sz;

err = build_id_parse(vma, build_id_buf, &build_id_sz);
if (err) {
karg.build_id_size = 0;
} else {
if (karg.build_id_size < build_id_sz) {
err = -ENAMETOOLONG;
goto out;
}
karg.build_id_size = build_id_sz;
}
}

if (karg.build_id_size) {
__u32 build_id_sz;

err = build_id_parse(vma, build_id_buf, &build_id_sz);
if (err) {
karg.build_id_size = 0;
} else {
if (karg.build_id_size < build_id_sz) {
err = -ENAMETOOLONG;
goto out;
}
karg.build_id_size = build_id_sz;
}
}

if (karg.vma_name_size) {
[...]