Skip to content

Commit 4e9d360

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
lib/buildid: remove single-page limit for PHDR search
Now that freader allows to access multiple pages transparently, there is no need to limit program headers to the very first ELF file page. Remove this limitation, but still put some sane limit on amount of program headers that we are willing to iterate over (set arbitrarily to 256). Reviewed-by: Eduard Zingerman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent d4deb82 commit 4e9d360

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/buildid.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#define BUILD_ID 3
1010

11+
#define MAX_PHDR_CNT 256
12+
1113
struct freader {
1214
void *buf;
1315
u32 buf_sz;
@@ -223,9 +225,9 @@ static int get_build_id_32(struct freader *r, unsigned char *build_id, __u32 *si
223225
phnum = READ_ONCE(ehdr->e_phnum);
224226
phoff = READ_ONCE(ehdr->e_phoff);
225227

226-
/* only supports phdr that fits in one page */
227-
if (phnum > (PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
228-
return -EINVAL;
228+
/* set upper bound on amount of segments (phdrs) we iterate */
229+
if (phnum > MAX_PHDR_CNT)
230+
phnum = MAX_PHDR_CNT;
229231

230232
/* check that phoff is not large enough to cause an overflow */
231233
if (phoff + phnum * sizeof(Elf32_Phdr) < phoff)
@@ -260,9 +262,9 @@ static int get_build_id_64(struct freader *r, unsigned char *build_id, __u32 *si
260262
phnum = READ_ONCE(ehdr->e_phnum);
261263
phoff = READ_ONCE(ehdr->e_phoff);
262264

263-
/* only supports phdr that fits in one page */
264-
if (phnum > (PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))
265-
return -EINVAL;
265+
/* set upper bound on amount of segments (phdrs) we iterate */
266+
if (phnum > MAX_PHDR_CNT)
267+
phnum = MAX_PHDR_CNT;
266268

267269
/* check that phoff is not large enough to cause an overflow */
268270
if (phoff + phnum * sizeof(Elf64_Phdr) < phoff)

0 commit comments

Comments
 (0)