]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
binfmt_elf: Take the mmap lock when walking the VMA list
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 26 Oct 2021 21:20:15 +0000 (17:20 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Sat, 30 Oct 2021 03:38:44 +0000 (23:38 -0400)
I'm not sure if the VMA list can change under us, but dump_vma_snapshot()
is very careful to take the mmap_lock in write mode.  We only need to
take it in read mode here as we do not care if the size of the stack
VMA changes underneath us.

If it can be changed underneath us, this is a potential use-after-free
for a multithreaded process which is dumping core.

Fixes: 2aa362c49c31 ("coredump: extend core dump note section to contain file names of mapped files")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
fs/binfmt_elf.c

index fd82040a01a9fa1bfe9301ffeb91ba4f0500b1e6..25b4d70981103ce89e2c159f6e6961983bf66c7c 100644 (file)
@@ -1639,6 +1639,7 @@ static int fill_files_note(struct memelfnote *note)
        name_base = name_curpos = ((char *)data) + names_ofs;
        remaining = size - names_ofs;
        count = 0;
+       mmap_read_lock(mm);
        for_each_vma(vmi, vma) {
                struct file *file;
                const char *filename;
@@ -1649,6 +1650,7 @@ static int fill_files_note(struct memelfnote *note)
                filename = file_path(file, name_curpos, remaining);
                if (IS_ERR(filename)) {
                        if (PTR_ERR(filename) == -ENAMETOOLONG) {
+                               mmap_read_unlock(mm);
                                kvfree(data);
                                size = size * 5 / 4;
                                goto alloc;
@@ -1668,6 +1670,7 @@ static int fill_files_note(struct memelfnote *note)
                *start_end_ofs++ = vma->vm_pgoff;
                count++;
        }
+       mmap_read_unlock(mm);
 
        /* Now we know exact count of files, can store it */
        data[0] = count;