kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: ydroneaud@opteya.com (Yann Droneaud)
To: kernelnewbies@lists.kernelnewbies.org
Subject: hook SIGSEGV
Date: Tue, 13 May 2014 18:02:11 +0200	[thread overview]
Message-ID: <1399996931.3017.33.camel@localhost.localdomain> (raw)
In-Reply-To: <20140513152938.GA4835@grml>

Hi,

Le mardi 13 mai 2014 ? 17:29 +0200,
michi1 at michaelblizek.twilightparadox.com a ?crit :

> On 21:46 Sat 10 May     , net.study.sea at gmail.com wrote:
> > 
> > Hi all :
> >      I want to know is it possible to hook SIGSEGV to restart the thread which the signal is sent to,without restart the whole process? And record the place where has caused this signal?
> > 
> > Thanks!
> 
> Yes, you can hook SIGSEGV like a normal signal. However, I have never tried to
> do so...
> 

I've played with this: in the segv signal handler, using SA_SIGINFO 
(see sigaction(3), I've retrieved the fault address and mmap() some 
anonymous memory page here, then leave the handler.
At this point the kernel will resume the process/thread where it has 
triggered the fault. And voila. The process/thread will issue again the 
previously faulty instruction and succeed.

This approach works when fault happen on a unmapped address.

But if your process/thread is trying to read some values there and
instead found a page full of 0, it might trigger more segfault.
Especially if it's using the zero as a pointer: it's going to try to 
access to page 0, which, by default, is not map'able by userspace 
process to defeat kernel NULL pointer dereference vulns.

For write access to a read only page, depending on the underlying
mapping, you will not be able to recover from the error easily: You
probably have to unmap the read-only page, map an anonymous page
instead, and don't forget to restore the content the process was
expected to find there.

I've never tried the later, nor played with multiple threads triggering
fault. So YMMV.

Regards.

-- 
Yann Droneaud
OPTEYA

  parent reply	other threads:[~2014-05-13 16:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-10 13:46 hook SIGSEGV net.study.sea at gmail.com
2014-05-13 15:29 ` michi1 at michaelblizek.twilightparadox.com
2014-05-13 15:43   ` Sam Dodrill
2014-05-13 16:02   ` Yann Droneaud [this message]
2014-05-14 12:14 ` Kristof Provost
2014-05-14 22:15   ` Max Filippov

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=1399996931.3017.33.camel@localhost.localdomain \
    --to=ydroneaud@opteya.com \
    --cc=kernelnewbies@lists.kernelnewbies.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;
as well as URLs for NNTP newsgroup(s).