filemap: Cache the value of vm_flags
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 25 May 2022 18:23:45 +0000 (14:23 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 9 Jun 2022 20:24:25 +0000 (16:24 -0400)
commitdcfa24ba68991ab69a48254a18377b45180ae664
tree1095030522aad702805d25d23b91fe13320fabb9
parent6bf74cddcffac0bc5ee0fad724aac778d2e53f75
filemap: Cache the value of vm_flags

After we have unlocked the mmap_lock for I/O, the file is pinned, but
the VMA is not.  Checking this flag after that can be a use-after-free.
It's not a terribly interesting use-after-free as it can only read one
bit, and it's used to decide whether to read 2MB or 4MB.  But it
upsets the automated tools and it's generally bad practice anyway,
so let's fix it.

Reported-by: syzbot+5b96d55e5b54924c77ad@syzkaller.appspotmail.com
Fixes: 4687fdbb805a ("mm/filemap: Support VM_HUGEPAGE for file mappings")
Cc: stable@vger.kernel.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
mm/filemap.c