Skip to content

Commit 1b110b9

Browse files
evelikovlucasdemarchi
authored andcommitted
libkmod: enforce non-null memory in kmod_elf_new()
In practise none of our code-paths will use a NULL pointer so we might as well enforce that. To stay aligned with the kernel behaviour update our init_module() preload library to return EFAULT... Should we get confused and pass NULL in the future. Signed-off-by: Emil Velikov <[email protected]> Link: #346 Signed-off-by: Lucas De Marchi <[email protected]>
1 parent 132eb4c commit 1b110b9

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

libkmod/libkmod-elf.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,6 @@ struct kmod_elf *kmod_elf_new(const void *memory, off_t size)
317317
assert_cc(sizeof(uint32_t) == sizeof(Elf32_Word));
318318
assert_cc(sizeof(uint32_t) == sizeof(Elf64_Word));
319319

320-
if (!memory) {
321-
errno = -EINVAL;
322-
return NULL;
323-
}
324-
325320
elf = malloc(sizeof(struct kmod_elf));
326321
if (elf == NULL) {
327322
return NULL;

libkmod/libkmod-internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct kmod_modversion {
152152
const char *symbol;
153153
};
154154

155-
struct kmod_elf *kmod_elf_new(const void *memory, off_t size);
155+
_nonnull_all_ struct kmod_elf *kmod_elf_new(const void *memory, off_t size);
156156
_nonnull_all_ void kmod_elf_unref(struct kmod_elf *elf);
157157
_must_check_ _nonnull_all_ const void *kmod_elf_get_memory(const struct kmod_elf *elf);
158158
_must_check_ _nonnull_all_ int kmod_elf_get_modinfo_strings(const struct kmod_elf *elf, char ***array);

testsuite/init_module.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ long init_module(void *mem, unsigned long len, const char *args)
234234

235235
init_retcodes();
236236

237+
if (mem == NULL) {
238+
errno = EFAULT;
239+
return -1;
240+
}
241+
237242
elf = kmod_elf_new(mem, len);
238243
if (elf == NULL)
239244
return -1;

0 commit comments

Comments
 (0)