mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jamie Lokier <lk@tantalophile.demon.co.uk>
To: "Andrew V. Samoilov" <kai@cmail.ru>
Cc: linux-kernel@vger.kernel.org
Subject: Re: mmap successed but SIGBUS generated on access
Date: Wed, 19 Sep 2001 23:51:53 +0100	[thread overview]
Message-ID: <20010919235153.A22429@kushida.degree2.com> (raw)
In-Reply-To: <200109191657.f8JGvPJ06663@cmail.ru>
In-Reply-To: <200109191657.f8JGvPJ06663@cmail.ru>; from kai@cmail.ru on Wed, Sep 19, 2001 at 08:57:25PM +0400

Andrew V. Samoilov wrote:
>> It is possible to do something useful with a signal handler sometimes.
>> For example, you can mmap() a zero page into the offending page once
>> you've got the fault address, or read() a zero page if you did
>> MAP_PRIVATE (this produces fewer VMAs), set a flag, and let the program
>> continue until it checks the flag and aborts the parsing or whatever
>> operation it's doing.
> 
> So, I must read all of the mapped area and even this
> does not saves me of faulting next time if somebody
> change file permission. Does I understand this situation
> right?

If you use MAP_PRIVATE, then after your process modifies the mapped
page, you have the data for sure.  This includes calling read() over a
page that raises a SIGBUS -- the page is "modified" by this operation,
although the contents should hopefully be the correct file contents if
read() succeeds.  Any subsequent change to the file, including
permission changes and data changes, won't affect the data you have in
memory.

If you do not modify the pages (and usually, for efficiency, you
wouldn't), then yes a change in file permissions can mean you can read
data one second and will get a SIGBUS later.  You're not guaranteed to
get a SIGBUS, but you might get one -- it depends on whether the OS
decides to reclaim the page's memory temporarily in between.

If you want to do something like an Editor's "Load File" operation, then
you need to read the whole file.  Either call read(), or call mmap() and
then modify every page by reading one byte from each page and writing
the same value back to the same place.  read() is probably quicker, but
I've never checked.

-- Jamie

  reply	other threads:[~2001-09-19 22:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-19 16:57 Andrew V. Samoilov
2001-09-19 22:51 ` Jamie Lokier [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-09-19 10:36 Andrew V. Samoilov
2001-09-19 13:00 ` Jamie Lokier

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=20010919235153.A22429@kushida.degree2.com \
    --to=lk@tantalophile.demon.co.uk \
    --cc=kai@cmail.ru \
    --cc=linux-kernel@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

Powered by JetHome