Re: [PATCH] buildid: validate page-backed file before parsing build ID

From: Andrew Morton

Date: Tue Dec 23 2025 - 12:29:33 EST


On Tue, 23 Dec 2025 18:32:07 +0800 Jinchao Wang <wangjinchao600@xxxxxxxxx> wrote:

> __build_id_parse() only works on page-backed storage. Its helper paths
> eventually call mapping->a_ops->read_folio(), so explicitly reject VMAs
> that do not map a regular file or lack valid address_space operations.
>
> Reported-by: syzbot+e008db2ac01e282550ee@xxxxxxxxxxxxxxxxxxxxxxxxx
> Signed-off-by: Jinchao Wang <wangjinchao600@xxxxxxxxx>
>
> ...
>
> --- a/lib/buildid.c
> +++ b/lib/buildid.c
> @@ -280,7 +280,10 @@ static int __build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
> int ret;
>
> /* only works for page backed storage */
> - if (!vma->vm_file)
> + if (!vma->vm_file ||
> + !S_ISREG(file_inode(vma->vm_file)->i_mode) ||
> + !vma->vm_file->f_mapping->a_ops ||
> + !vma->vm_file->f_mapping->a_ops->read_folio)
> return -EINVAL;
>
> freader_init_from_file(&r, buf, sizeof(buf), vma->vm_file, may_fault);

Thanks. Seems this one needs additional paperwork.

I added the below:

Fixes: ad41251c290d ("lib/buildid: implement sleepable build_id_parse() API")
Tested-by: <syzbot+e008db2ac01e282550ee@xxxxxxxxxxxxxxxxxxxxxxxxx>
Link: https://lkml.kernel.org/r/694a67ab.050a0220.19928e.001c.GAE@xxxxxxxxxx
Closes: https://lkml.kernel.org/r/693540fe.a70a0220.38f243.004c.GAE@xxxxxxxxxx
Cc: <stable@xxxxxxxxxxxxxxx>

and a large number of cc's which I scraped together from various
emails.

Could people please eyeball all of this and verify that everything is
good?



From: Jinchao Wang <wangjinchao600@xxxxxxxxx>
Subject: buildid: validate page-backed file before parsing build ID
Date: Tue, 23 Dec 2025 18:32:07 +0800

__build_id_parse() only works on page-backed storage. Its helper paths
eventually call mapping->a_ops->read_folio(), so explicitly reject VMAs
that do not map a regular file or lack valid address_space operations.

Link: https://lkml.kernel.org/r/20251223103214.2412446-1-wangjinchao600@xxxxxxxxx
Fixes: ad41251c290d ("lib/buildid: implement sleepable build_id_parse() API")
Signed-off-by: Jinchao Wang <wangjinchao600@xxxxxxxxx>
Reported-by: <syzbot+e008db2ac01e282550ee@xxxxxxxxxxxxxxxxxxxxxxxxx>
Tested-by: <syzbot+e008db2ac01e282550ee@xxxxxxxxxxxxxxxxxxxxxxxxx>
Link: https://lkml.kernel.org/r/694a67ab.050a0220.19928e.001c.GAE@xxxxxxxxxx
Closes: https://lkml.kernel.org/r/693540fe.a70a0220.38f243.004c.GAE@xxxxxxxxxx
Cc: Axel Rasmussen <axelrasmussen@xxxxxxxxxx>
Cc: David Hildenbrand (Red Hat) <david@xxxxxxxxxx>
Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
Cc: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxxxx>
Cc: Qi Zheng <zhengqi.arch@xxxxxxxxxxxxx>
Cc: Shakeel Butt <shakeel.butt@xxxxxxxxx>
Cc: Wei Xu <weixugc@xxxxxxxxxx>
Cc: Yuanchu Xie <yuanchu@xxxxxxxxxx>
Cc: Andrii Nakryiko <andrii@xxxxxxxxxx>
Cc: Eduard Zingerman <eddyz87@xxxxxxxxx>
Cc: Omar Sandoval <osandov@xxxxxx>
Cc: Deepanshu Kartikey <kartikey406@xxxxxxxxx>
Cc: Alexei Starovoitov <ast@xxxxxxxxxx>
Cc: Daniel Borkman <daniel@xxxxxxxxxxxxx>
Cc: Hao Luo <haoluo@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: John Fastabend <john.fastabend@xxxxxxxxx>
Cc: KP Singh <kpsingh@xxxxxxxxxx>
Cc: Martin KaFai Lau <martin.lau@xxxxxxxxx>
Cc: Song Liu <song@xxxxxxxxxx>
Cc: Stanislav Fomichev <sdf@xxxxxxxxxxx>
Cc: Yonghong Song <yonghong.song@xxxxxxxxx>
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

lib/buildid.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

--- a/lib/buildid.c~buildid-validate-page-backed-file-before-parsing-build-id
+++ a/lib/buildid.c
@@ -288,7 +288,10 @@ static int __build_id_parse(struct vm_ar
int ret;

/* only works for page backed storage */
- if (!vma->vm_file)
+ if (!vma->vm_file ||
+ !S_ISREG(file_inode(vma->vm_file)->i_mode) ||
+ !vma->vm_file->f_mapping->a_ops ||
+ !vma->vm_file->f_mapping->a_ops->read_folio)
return -EINVAL;

freader_init_from_file(&r, buf, sizeof(buf), vma->vm_file, may_fault);
_