linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] fsnotify: Pass correct offset to fsnotify_mmap_perm()
@ 2025-10-03 15:52 Ryan Roberts
  2025-10-03 16:00 ` Kiryl Shutsemau
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Ryan Roberts @ 2025-10-03 15:52 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Amir Goldstein
  Cc: Ryan Roberts, linux-mm, linux-kernel, stable

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.

Cc: <stable@vger.kernel.org>
Fixes: 066e053fe208 ("fsnotify: add pre-content hooks on mmap()")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
Applies against today's mm-unstable (aa05a436eca8).

Thanks,
Ryan


 mm/util.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/util.c b/mm/util.c
index 6c1d64ed0221..8989d5767528 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -566,6 +566,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
 	unsigned long flag, unsigned long pgoff)
 {
+	loff_t off = (loff_t)pgoff << PAGE_SHIFT;
 	unsigned long ret;
 	struct mm_struct *mm = current->mm;
 	unsigned long populate;
@@ -573,7 +574,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,

 	ret = security_mmap_file(file, prot, flag);
 	if (!ret)
-		ret = fsnotify_mmap_perm(file, prot, pgoff >> PAGE_SHIFT, len);
+		ret = fsnotify_mmap_perm(file, prot, off, len);
 	if (!ret) {
 		if (mmap_write_lock_killable(mm))
 			return -EINTR;
--
2.43.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-10-14 13:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-03 15:52 [PATCH v1] fsnotify: Pass correct offset to fsnotify_mmap_perm() Ryan Roberts
2025-10-03 16:00 ` Kiryl Shutsemau
2025-10-03 16:36   ` Ryan Roberts
2025-10-03 16:54     ` Kiryl Shutsemau
2025-10-06 11:36 ` David Hildenbrand
2025-10-06 12:14   ` Ryan Roberts
2025-10-06 13:53     ` David Hildenbrand
2025-10-06 14:40       ` Amir Goldstein
2025-10-07 11:08         ` Amir Goldstein
2025-10-06 14:55 ` Jan Kara
2025-10-06 15:04   ` Ryan Roberts
2025-10-06 15:16     ` Jan Kara
2025-10-14 13:38 ` Lorenzo Stoakes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox