Skip to content

Commit 28bba2c

Browse files
ryanhrobakpm00
authored andcommitted
fsnotify: pass correct offset to fsnotify_mmap_perm()
fsnotify_mmap_perm() requires a byte offset for the file about to be mmap'ed. But it is called from vm_mmap_pgoff(), which has a page offset. Previously the conversion was done incorrectly so let's fix it, being careful not to overflow on 32-bit platforms. Discovered during code review. Link: https://lkml.kernel.org/r/[email protected] Fixes: 066e053 ("fsnotify: add pre-content hooks on mmap()") Signed-off-by: Ryan Roberts <[email protected]> Reviewed-by: Kiryl Shutsemau <[email protected]> Cc: Amir Goldstein <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Liam Howlett <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent f04aad3 commit 28bba2c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mm/util.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,15 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
566566
unsigned long len, unsigned long prot,
567567
unsigned long flag, unsigned long pgoff)
568568
{
569+
loff_t off = (loff_t)pgoff << PAGE_SHIFT;
569570
unsigned long ret;
570571
struct mm_struct *mm = current->mm;
571572
unsigned long populate;
572573
LIST_HEAD(uf);
573574

574575
ret = security_mmap_file(file, prot, flag);
575576
if (!ret)
576-
ret = fsnotify_mmap_perm(file, prot, pgoff >> PAGE_SHIFT, len);
577+
ret = fsnotify_mmap_perm(file, prot, off, len);
577578
if (!ret) {
578579
if (mmap_write_lock_killable(mm))
579580
return -EINTR;

0 commit comments

Comments
 (0)