From: "Darrick J. Wong" <djwong@kernel.org>
To: Carlos Maiolino <cmaiolino@redhat.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH] Prevent mmap command to map beyond EOF
Date: Tue, 5 Oct 2021 15:36:53 -0700 [thread overview]
Message-ID: <20211005223653.GG24307@magnolia> (raw)
In-Reply-To: <20211004141140.53607-1-cmaiolino@redhat.com>
On Mon, Oct 04, 2021 at 04:11:40PM +0200, Carlos Maiolino wrote:
> 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?
What's the motivation for checking this in userspace? Programs are
allowed to set up this (admittedly minimally functional) configuration,
or even set it up after the mmap by truncating the file.
OTOH if your goal is to write a test to check the SIGBUS functionality,
you could install a sigbus handler to report the signal to stderr, which
would avoid bash writing junk about the sigbus to the terminal.
--D
>
> 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
>
next prev parent reply other threads:[~2021-10-05 22:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-04 14:11 [PATCH] Prevent mmap command to map beyond EOF Carlos Maiolino
2021-10-05 22:36 ` Darrick J. Wong [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211005223653.GG24307@magnolia \
--to=djwong@kernel.org \
--cc=cmaiolino@redhat.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox