All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Prevent mmap command to map beyond EOF
@ 2021-10-04 14:11 Carlos Maiolino
  2021-10-05 22:36 ` Darrick J. Wong
  0 siblings, 1 reply; 6+ messages in thread
From: Carlos Maiolino @ 2021-10-04 14:11 UTC (permalink / raw)
  To: linux-xfs

Attempting to access a mmapp'ed region that does not correspond to the
file results in a SIGBUS, so prevent xfs_io to even attempt to mmap() a
region beyond EOF.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---

There is a caveat about this patch though. It is possible to mmap() a
non-existent file region, extent the file to go beyond such region, and run
operations in this mmapped region without such operations triggering a SIGBUS
(excluding the file corruption factor here :). So, I'm not quite sure if it
would be ok to check for this in mmap_f() as this patch does, or create a helper
to check for such condition, and use it on the other operations (mread_f,
mwrite_f, etc). What you folks think?


 io/mmap.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/io/mmap.c b/io/mmap.c
index 9816cf68..77c5f2b6 100644
--- a/io/mmap.c
+++ b/io/mmap.c
@@ -242,6 +242,13 @@ mmap_f(
 		return 0;
 	}
 
+	/* Check if we are mmapping beyond EOF */
+	if ((offset + length) > filesize()) {
+		printf(_("Attempting to mmap() beyond EOF\n"));
+		exitcode = 1;
+		return 0;
+	}
+
 	/*
 	 * mmap and munmap memory area of length2 region is helpful to
 	 * make a region of extendible free memory. It's generally used
-- 
2.31.1


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

end of thread, other threads:[~2021-10-07 10:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 14:11 [PATCH] Prevent mmap command to map beyond EOF Carlos Maiolino
2021-10-05 22:36 ` Darrick J. Wong
2021-10-06 11:34   ` Carlos Maiolino
2021-10-06 15:54     ` Darrick J. Wong
2021-10-06 16:54       ` Carlos Maiolino
2021-10-07 10:45         ` Carlos Maiolino

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.