Skip to content

Commit cdbb44f

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
lib/buildid: don't limit .note.gnu.build-id to the first page in ELF
With freader we don't need to restrict ourselves to a single page, so let's allow ELF notes to be at any valid position with the file. We also merge parse_build_id() and parse_build_id_buf() as now the only difference between them is note offset overflow, which makes sense to check in all situations. 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 ad41251 commit cdbb44f

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

lib/buildid.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,18 @@ static void freader_cleanup(struct freader *r)
155155
* 32-bit and 64-bit system, because Elf32_Nhdr and Elf64_Nhdr are
156156
* identical.
157157
*/
158-
static int parse_build_id_buf(struct freader *r,
159-
unsigned char *build_id, __u32 *size,
160-
loff_t note_off, Elf32_Word note_size)
158+
static int parse_build_id(struct freader *r, unsigned char *build_id, __u32 *size,
159+
loff_t note_off, Elf32_Word note_size)
161160
{
162161
const char note_name[] = "GNU";
163162
const size_t note_name_sz = sizeof(note_name);
164163
u32 build_id_off, new_off, note_end, name_sz, desc_sz;
165164
const Elf32_Nhdr *nhdr;
166165
const char *data;
167166

168-
note_end = note_off + note_size;
167+
if (check_add_overflow(note_off, note_size, &note_end))
168+
return -EINVAL;
169+
169170
while (note_end - note_off > sizeof(Elf32_Nhdr) + note_name_sz) {
170171
nhdr = freader_fetch(r, note_off, sizeof(Elf32_Nhdr) + note_name_sz);
171172
if (!nhdr)
@@ -204,23 +205,6 @@ static int parse_build_id_buf(struct freader *r,
204205
return -EINVAL;
205206
}
206207

207-
static inline int parse_build_id(struct freader *r,
208-
unsigned char *build_id,
209-
__u32 *size,
210-
loff_t note_start_off,
211-
Elf32_Word note_size)
212-
{
213-
/* check for overflow */
214-
if (note_start_off + note_size < note_start_off)
215-
return -EINVAL;
216-
217-
/* only supports note that fits in the first page */
218-
if (note_start_off + note_size > PAGE_SIZE)
219-
return -EINVAL;
220-
221-
return parse_build_id_buf(r, build_id, size, note_start_off, note_size);
222-
}
223-
224208
/* Parse build ID from 32-bit ELF */
225209
static int get_build_id_32(struct freader *r, unsigned char *build_id, __u32 *size)
226210
{

0 commit comments

Comments
 (0)