Skip to content

Commit 8bbb0c4

Browse files
olsajirikernel-patches-bot
authored andcommitted
bpf: Add size arg to build_id_parse function
It's possible to have other build id types (other than default SHA1). Currently there's also ld support for MD5 build id. Adding size argument to build_id_parse function, that returns (if defined) size of the parsed build id, so we can recognize the build id type. Cc: Alexei Starovoitov <ast@kernel.org> Cc: Song Liu <songliubraving@fb.com> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 14fc331 commit 8bbb0c4

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

include/linux/buildid.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#define BUILD_ID_SIZE_MAX 20
88

9-
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id);
9+
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
10+
__u32 *size);
1011

1112
#endif

kernel/bpf/stackmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs,
189189

190190
for (i = 0; i < trace_nr; i++) {
191191
vma = find_vma(current->mm, ips[i]);
192-
if (!vma || build_id_parse(vma, id_offs[i].build_id)) {
192+
if (!vma || build_id_parse(vma, id_offs[i].build_id, NULL)) {
193193
/* per entry fall back to ips */
194194
id_offs[i].status = BPF_STACK_BUILD_ID_IP;
195195
id_offs[i].ip = ips[i];

lib/buildid.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
static inline int parse_build_id(void *page_addr,
1414
unsigned char *build_id,
15+
__u32 *size,
1516
void *note_start,
1617
Elf32_Word note_size)
1718
{
@@ -38,6 +39,8 @@ static inline int parse_build_id(void *page_addr,
3839
nhdr->n_descsz);
3940
memset(build_id + nhdr->n_descsz, 0,
4041
BUILD_ID_SIZE_MAX - nhdr->n_descsz);
42+
if (size)
43+
*size = nhdr->n_descsz;
4144
return 0;
4245
}
4346
new_offs = note_offs + sizeof(Elf32_Nhdr) +
@@ -50,7 +53,8 @@ static inline int parse_build_id(void *page_addr,
5053
}
5154

5255
/* Parse build ID from 32-bit ELF */
53-
static int get_build_id_32(void *page_addr, unsigned char *build_id)
56+
static int get_build_id_32(void *page_addr, unsigned char *build_id,
57+
__u32 *size)
5458
{
5559
Elf32_Ehdr *ehdr = (Elf32_Ehdr *)page_addr;
5660
Elf32_Phdr *phdr;
@@ -65,7 +69,7 @@ static int get_build_id_32(void *page_addr, unsigned char *build_id)
6569

6670
for (i = 0; i < ehdr->e_phnum; ++i) {
6771
if (phdr[i].p_type == PT_NOTE &&
68-
!parse_build_id(page_addr, build_id,
72+
!parse_build_id(page_addr, build_id, size,
6973
page_addr + phdr[i].p_offset,
7074
phdr[i].p_filesz))
7175
return 0;
@@ -74,7 +78,8 @@ static int get_build_id_32(void *page_addr, unsigned char *build_id)
7478
}
7579

7680
/* Parse build ID from 64-bit ELF */
77-
static int get_build_id_64(void *page_addr, unsigned char *build_id)
81+
static int get_build_id_64(void *page_addr, unsigned char *build_id,
82+
__u32 *size)
7883
{
7984
Elf64_Ehdr *ehdr = (Elf64_Ehdr *)page_addr;
8085
Elf64_Phdr *phdr;
@@ -89,16 +94,24 @@ static int get_build_id_64(void *page_addr, unsigned char *build_id)
8994

9095
for (i = 0; i < ehdr->e_phnum; ++i) {
9196
if (phdr[i].p_type == PT_NOTE &&
92-
!parse_build_id(page_addr, build_id,
97+
!parse_build_id(page_addr, build_id, size,
9398
page_addr + phdr[i].p_offset,
9499
phdr[i].p_filesz))
95100
return 0;
96101
}
97102
return -EINVAL;
98103
}
99104

100-
/* Parse build ID of ELF file mapped to vma */
101-
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id)
105+
/*
106+
* Parse build ID of ELF file mapped to vma
107+
* @vma: vma object
108+
* @build_id: buffer to store build id, at least BUILD_ID_SIZE long
109+
* @size: returns actual build id size in case of success
110+
*
111+
* Returns 0 on success, otherwise error (< 0).
112+
*/
113+
int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id,
114+
__u32 *size)
102115
{
103116
Elf32_Ehdr *ehdr;
104117
struct page *page;
@@ -126,9 +139,9 @@ int build_id_parse(struct vm_area_struct *vma, unsigned char *build_id)
126139
goto out;
127140

128141
if (ehdr->e_ident[EI_CLASS] == ELFCLASS32)
129-
ret = get_build_id_32(page_addr, build_id);
142+
ret = get_build_id_32(page_addr, build_id, size);
130143
else if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
131-
ret = get_build_id_64(page_addr, build_id);
144+
ret = get_build_id_64(page_addr, build_id, size);
132145
out:
133146
kunmap_atomic(page_addr);
134147
put_page(page);

0 commit comments

Comments
 (0)