Skip to content

Commit b2fe954

Browse files
anakryikogregkh
authored andcommitted
lib/buildid: Handle memfd_secret() files in build_id_parse()
commit 5ac9b4e upstream. >From memfd_secret(2) manpage: The memory areas backing the file created with memfd_secret(2) are visible only to the processes that have access to the file descriptor. The memory region is removed from the kernel page tables and only the page tables of the processes holding the file descriptor map the corresponding physical memory. (Thus, the pages in the region can't be accessed by the kernel itself, so that, for example, pointers to the region can't be passed to system calls.) We need to handle this special case gracefully in build ID fetching code. Return -EFAULT whenever secretmem file is passed to build_id_parse() family of APIs. Original report and repro can be found in [0]. [0] https://lore.kernel.org/bpf/ZwyG8Uro%2FSyTXAni@ly-workstation/ Fixes: de3ec36 ("lib/buildid: add single folio-based file reader abstraction") Reported-by: Yi Lai <[email protected]> Suggested-by: Shakeel Butt <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Shakeel Butt <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Link: https://lore.kernel.org/bpf/[email protected] [ Chen Linxuan: backport same logic without folio-based changes ] Fixes: 88a16a1 ("perf: Add build id data in mmap2 event") Signed-off-by: Chen Linxuan <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent aa4d9b5 commit b2fe954

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/buildid.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/elf.h>
66
#include <linux/kernel.h>
77
#include <linux/pagemap.h>
8+
#include <linux/secretmem.h>
89

910
#define BUILD_ID 3
1011

@@ -157,6 +158,10 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
157158
if (!vma->vm_file)
158159
return -EINVAL;
159160

161+
/* reject secretmem folios created with memfd_secret() */
162+
if (vma_is_secretmem(vma))
163+
return -EFAULT;
164+
160165
page = find_get_page(vma->vm_file->f_mapping, 0);
161166
if (!page)
162167
return -EFAULT; /* page not mapped */

0 commit comments

Comments
 (0)