return acc;
}
+/**
+ * alloc_elfnotes_buf - allocate buffer for ELF note segment in
+ * vmalloc memory
+ *
+ * @notes_sz: size of buffer
+ *
+ * If CONFIG_MMU is defined, use vmalloc_user() to allow users to mmap
+ * the buffer to user-space by means of remap_vmalloc_range().
+ *
+ * If CONFIG_MMU is not defined, use vzalloc() since mmap_vmcore() is
+ * disabled and there's no need to allow users to mmap the buffer.
+ */
+static inline char *alloc_elfnotes_buf(size_t notes_sz)
+{
+#ifdef CONFIG_MMU
+ return vmalloc_user(notes_sz);
+#else
+ return vzalloc(notes_sz);
+#endif
+}
+
+/*
+ * Disable mmap_vmcore() if CONFIG_MMU is not defined. MMU is
+ * essential for mmap_vmcore() in order to map physically
+ * non-contiguous objects (ELF header, ELF note segment and memory
+ * regions in the 1st kernel pointed to by PT_LOAD entries) into
+ * virtually contiguous user-space in ELF layout.
+ */
+#ifdef CONFIG_MMU
static int mmap_vmcore(struct file *file, struct vm_area_struct *vma)
{
size_t size = vma->vm_end - vma->vm_start;
do_munmap(vma->vm_mm, vma->vm_start, len);
return -EAGAIN;
}
+#else
+static int mmap_vmcore(struct file *file, struct vm_area_struct *vma)
+{
+ return -ENOSYS;
+}
+#endif
static const struct file_operations proc_vmcore_operations = {
.read = read_vmcore,
Elf64_Ehdr *ehdr_ptr;
Elf64_Phdr phdr;
u64 phdr_sz = 0, note_off;
- struct vm_struct *vm;
ehdr_ptr = (Elf64_Ehdr *)elfptr;
return rc;
*notes_sz = roundup(phdr_sz, PAGE_SIZE);
- *notes_buf = vzalloc(*notes_sz);
+ *notes_buf = alloc_elfnotes_buf(*notes_sz);
if (!*notes_buf)
return -ENOMEM;
- /*
- * Allow users to remap ELF note segment buffer on vmalloc memory using
- * remap_vmalloc_range.()
- */
- vm = find_vm_area(*notes_buf);
- BUG_ON(!vm);
- vm->flags |= VM_USERMAP;
-
rc = copy_notes_elf64(ehdr_ptr, *notes_buf);
if (rc < 0)
return rc;
Elf32_Ehdr *ehdr_ptr;
Elf32_Phdr phdr;
u64 phdr_sz = 0, note_off;
- struct vm_struct *vm;
ehdr_ptr = (Elf32_Ehdr *)elfptr;
return rc;
*notes_sz = roundup(phdr_sz, PAGE_SIZE);
- *notes_buf = vzalloc(*notes_sz);
+ *notes_buf = alloc_elfnotes_buf(*notes_sz);
if (!*notes_buf)
return -ENOMEM;
- /*
- * Allow users to remap ELF note segment buffer on vmalloc memory using
- * remap_vmalloc_range()
- */
- vm = find_vm_area(*notes_buf);
- BUG_ON(!vm);
- vm->flags |= VM_USERMAP;
-
rc = copy_notes_elf32(ehdr_ptr, *notes_buf);
if (rc < 0)
return rc;