1212 */
1313static 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 );
132145out :
133146 kunmap_atomic (page_addr );
134147 put_page (page );
0 commit comments