linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stas Sergeev <stsp@list.ru>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: sigaltstack breaks swapcontext()
Date: Fri, 8 Jan 2016 16:49:04 +0300	[thread overview]
Message-ID: <568FBE50.7040504@list.ru> (raw)
In-Reply-To: <CALCETrX+nvBy5JTOsgz-gR9OaT2C7C_Gi-grt_rUJmkXuwX6QQ@mail.gmail.com>

06.01.2016 21:05, Andy Lutomirski пишет:
> On Wed, Jan 6, 2016 at 7:45 AM, Stas Sergeev <stsp@list.ru> wrote:
>> Hello.
>>
>> swapcontext() can be used with signal handlers,
>> it swaps the signal masks together with the other
>> parts of the context.
>> Unfortunately, linux implements the sigaltstack()
>> in a way that makes it impossible to use with
>> swapcontext().
>> Per the man page, sigaltstack is allowed to return
>> EPERM if the process is altering its sigaltstack while
>> running on sigaltstack. This is likely needed to
>> consistently return oss->ss_flags, that indicates
>> whether the process is being on sigaltstack or not.
>> Unfortunately, linux takes that permission to return
>> EPERM too literally: it returns EPERM even if you
>> don't want to change to another sigaltstack, but
>> only want to disable sigaltstack with SS_DISABLE.
>> To my reading of a man page, this is not a desired
>> behaviour. Moreover, you can't use swapcontext()
>> without disabling sigaltstack first, or the stack will
>> be re-used and overwritten by a subsequent signal.
>>
> The EPERM thing is probably also to preserve the behavior that nested
> SA_ONSTACK signals are supposed to work.  (Of course, the kernel gets
> this a bit wrong because it forgets to check ss in addition to sp.
> That would be relatively straightforward to fix.)
I don't think it needs a fix: in 64bit mode SS doesn't matter, and
in 32bit mode the SS is properly restored in a sighandler, so no
one can run sigaltstack() with non-flat SS (unless the DOS code
itself does this, which it does not).

  parent reply	other threads:[~2016-01-08 13:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-06 15:45 sigaltstack breaks swapcontext() Stas Sergeev
2016-01-06 18:05 ` Andy Lutomirski
2016-01-06 18:42   ` Stas Sergeev
2016-01-06 19:14     ` Andy Lutomirski
2016-01-06 19:31       ` Stas Sergeev
2016-01-06 19:53         ` Andy Lutomirski
2016-01-07 15:33           ` Stas Sergeev
2016-01-07 17:23             ` Andy Lutomirski
2016-01-07 19:10               ` Stas Sergeev
2016-01-08 13:49   ` Stas Sergeev [this message]
2016-01-08 23:24     ` Andy Lutomirski
2016-01-08 23:40       ` Stas Sergeev
2016-01-09  1:43       ` Stas Sergeev
2016-01-09  1:48         ` Andy Lutomirski
2016-03-07 20:02           ` Stas Sergeev
2016-03-07 21:10             ` Andy Lutomirski
2016-03-07 21:20               ` Stas Sergeev
2016-03-07 21:32                 ` Andy Lutomirski
2016-03-07 21:38                   ` One Thousand Gnomes
2016-03-07 21:45                   ` Stas Sergeev

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=568FBE50.7040504@list.ru \
    --to=stsp@list.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    /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).