Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1401062

Re: [PATCH 1/4] signals/sigaltstack: If SS_AUTODISARM, bypass on_sig_stack

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Andy Lutomirski <luto@amacapital.net>
Newsgroups linux.kernel
Subject Re: [PATCH 1/4] signals/sigaltstack: If SS_AUTODISARM, bypass on_sig_stack
Date Sat, 14 May 2016 06:20:01 +0200
Message-ID <ryzdv-1ev-1@gated-at.bofh.it> (permalink)
References <ruMsG-3Sd-9@gated-at.bofh.it> <ruMsI-3Sd-57@gated-at.bofh.it> <rwbyG-398-5@gated-at.bofh.it> <rwIkV-1K9-1@gated-at.bofh.it> <rwINY-2jj-5@gated-at.bofh.it>
X-Original-To Stas Sergeev <stsp@list.ru>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=dXqRLk35ZSDDlBVbaeOUhFG5/00MwhRWB/WnrHbrHME=; b=znEA1ZKiC8qmWPvyJBl9pxyeTuOTq6JrfNF0ytgN4u/60+70jJbf38nzcIli/k7ZIL GlOcqPDfjcf6VuMCGAB/lTlMYQvWIi97F6JwlgMhJe7X84AyLIlIUeHTKzWKKVhCJ8Hm W63kx8U9cRxLbQ2IfnvhW7C53AgdotSLRijEJM+cy1g0RqY/1yrQ5BvObfBbNzX1Dwt7 V2SKknivwv63dF+HI6I1zCA2Li5YR1dSlZaZFfp0ANlZHkpx/Zq17CfVq+0MNQYQjxrF QvWXALP7OCI4PtvWPOuRmLmHGPh8xH1I57VMQ5AxVDa18IEV2MzKHAbqApXmiOsaHTAW 8GsQ==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=dXqRLk35ZSDDlBVbaeOUhFG5/00MwhRWB/WnrHbrHME=; b=kD2DRMYmekr+YZGnz2oOaU680uYHB2nyVQHIyEKgPMwgW4Tm4+xo9a8f6G4aK1F48g 5WadkVC21KjW0GCAqhdKn9jGvM4oEfkkiOu4vfP6/2+kVMIkO+UPUVpdBpJJPDHvp9lG Muii2E17Z1mMW8rlOir8TQJEGBHKpFEoTx/lT71fhwSzG+VdZmHsbs5C0ut6gtBg9BXU umrZ/HC4XRlrhicUrv/YveE74ACnouqF+3fapMnQBWET4cY0ax7dr/myo7T9ZgwXq+Ap 4JXW07+h6Ts9E+UrOVLhg50sSWmOAGw2eqsRnWMEBmlqScYJIyOqKRwqfHKNdSetA5/K U3lg==
X-Gm-Message-State AOPr4FUF0fjSeK4yfQG6NnZdE1KIaIKPfXPHqn6x5wlve9WlnZLBLadwbMI1H9ch0PiNQbiI+a+a62KEgzZL+Q24
X-Received by 10.202.81.212 with SMTP id f203mr2733510oib.114.1463199520859; Fri, 13 May 2016 21:18:40 -0700 (PDT)
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8BIT
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 120
Organization linux.* mail to news gateway
X-Original-Cc Thomas Gleixner <tglx@linutronix.de>, Pavel Emelyanov <xemul@parallels.com>, Shuah Khan <shuahkh@osg.samsung.com>, X86 ML <x86@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Linux API <linux-api@vger.kernel.org>, Jason Low <jason.low2@hp.com>, "Eric W. Biederman" <ebiederm@xmission.com>, Aleksa Sarai <cyphar@cyphar.com>, Josh Triplett <josh@joshtriplett.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, Paul Moore <pmoore@redhat.com>, Sasha Levin <sasha.levin@oracle.com>, Denys Vlasenko <dvlasenk@redhat.com>, Al Viro <viro@zeniv.linux.org.uk>, Borislav Petkov <bp@alien8.de>, "Amanieu d'Antras" <amanieu@gmail.com>, Konstantin Khlebnikov <khlebnikov@yandex-team.ru>, Heinrich Schuchardt <xypron.glpk@gmx.de>, Brian Gerst <brgerst@gmail.com>, Tejun Heo <tj@kernel.org>, Linus Torvalds <torvalds@linux-foundation.org>, Andrea Arcangeli <aarcange@redhat.com>, Frederic Weisbecker <fweisbec@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Vladimir Davydov <vdavydov@parallels.com>, Oleg Nesterov <oleg@redhat.com>, Richard Weinberger <richard@nod.at>, "H. Peter Anvin" <hpa@zytor.com>, Peter Zijlstra <peterz@infradead.org>
X-Original-Date Fri, 13 May 2016 21:18:21 -0700
X-Original-Message-ID <CALCETrV+gmXn-kTJmKBDPM8HaRTcvp+eGmeF7mOES6bCje2AGQ@mail.gmail.com>
X-Original-References <cover.1462296606.git.luto@kernel.org> <c46bee4654ca9e68c498462fd11746e2bd0d98c8.1462296606.git.luto@kernel.org> <0081b876-033b-4fb7-3daf-d38b2df1fda6@list.ru> <CALCETrX4AMCUkYMXe6-RoHTHQ=bpunM5keHSxMg=fEVtb1EmqA@mail.gmail.com> <97f8e27a-019c-a5d4-2d2c-c2a9627cf23d@list.ru>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1401062

Show key headers only | View raw


On May 8, 2016 7:05 PM, "Stas Sergeev" <stsp@list.ru> wrote:
>
> 09.05.2016 04:32, Andy Lutomirski пишет:
>
>> On May 7, 2016 7:38 AM, "Stas Sergeev" <stsp@list.ru> wrote:
>>>
>>> 03.05.2016 20:31, Andy Lutomirski пишет:
>>>
>>>> If a signal stack is set up with SS_AUTODISARM, then the kernel
>>>> inherently avoids incorrectly resetting the signal stack if signals
>>>> recurse: the signal stack will be reset on the first signal
>>>> delivery.  This means that we don't need check the stack pointer
>>>> when delivering signals if SS_AUTODISARM is set.
>>>>
>>>> This will make segmented x86 programs more robust: currently there's
>>>> a hole that could be triggered if ESP/RSP appears to point to the
>>>> signal stack but actually doesn't due to a nonzero SS base.
>>>>
>>>> Signed-off-by: Stas Sergeev <stsp@list.ru>
>>>> Cc: Al Viro <viro@zeniv.linux.org.uk>
>>>> Cc: Aleksa Sarai <cyphar@cyphar.com>
>>>> Cc: Amanieu d'Antras <amanieu@gmail.com>
>>>> Cc: Andrea Arcangeli <aarcange@redhat.com>
>>>> Cc: Andrew Morton <akpm@linux-foundation.org>
>>>> Cc: Andy Lutomirski <luto@amacapital.net>
>>>> Cc: Borislav Petkov <bp@alien8.de>
>>>> Cc: Brian Gerst <brgerst@gmail.com>
>>>> Cc: Denys Vlasenko <dvlasenk@redhat.com>
>>>> Cc: Eric W. Biederman <ebiederm@xmission.com>
>>>> Cc: Frederic Weisbecker <fweisbec@gmail.com>
>>>> Cc: H. Peter Anvin <hpa@zytor.com>
>>>> Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
>>>> Cc: Jason Low <jason.low2@hp.com>
>>>> Cc: Josh Triplett <josh@joshtriplett.org>
>>>> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
>>>> Cc: Linus Torvalds <torvalds@linux-foundation.org>
>>>> Cc: Oleg Nesterov <oleg@redhat.com>
>>>> Cc: Palmer Dabbelt <palmer@dabbelt.com>
>>>> Cc: Paul Moore <pmoore@redhat.com>
>>>> Cc: Pavel Emelyanov <xemul@parallels.com>
>>>> Cc: Peter Zijlstra <peterz@infradead.org>
>>>> Cc: Richard Weinberger <richard@nod.at>
>>>> Cc: Sasha Levin <sasha.levin@oracle.com>
>>>> Cc: Shuah Khan <shuahkh@osg.samsung.com>
>>>> Cc: Tejun Heo <tj@kernel.org>
>>>> Cc: Thomas Gleixner <tglx@linutronix.de>
>>>> Cc: Vladimir Davydov <vdavydov@parallels.com>
>>>> Cc: linux-api@vger.kernel.org
>>>> Cc: linux-kernel@vger.kernel.org
>>>> Signed-off-by: Andy Lutomirski <luto@kernel.org>
>>>> ---
>>>>    include/linux/sched.h | 12 ++++++++++++
>>>>    1 file changed, 12 insertions(+)
>>>>
>>>> diff --git a/include/linux/sched.h b/include/linux/sched.h
>>>> index 2950c5cd3005..8f03a93348b9 100644
>>>> --- a/include/linux/sched.h
>>>> +++ b/include/linux/sched.h
>>>> @@ -2576,6 +2576,18 @@ static inline int kill_cad_pid(int sig, int priv)
>>>>     */
>>>>    static inline int on_sig_stack(unsigned long sp)
>>>>    {
>>>> +       /*
>>>> +        * If the signal stack is AUTODISARM then, by construction, we
>>>> +        * can't be on the signal stack unless user code deliberately set
>>>> +        * SS_AUTODISARM when we were already on the it.
>>>
>>> "on the it" -> "on it".
>>>
>>> Anyway, I am a bit puzzled with this patch.
>>> You say "unless user code deliberately set
>>>
>>> SS_AUTODISARM when we were already on the it"
>>> so what happens in case it actually does?
>>>
>> Stack corruption.  Don't do that.
>
> Only after your change, I have to admit. :)
>
>
>>> Without your patch: if user sets up the same sas - no stack switch.
>>> if user sets up different sas - stack switch on nested signal.
>>>
>>> With your patch: stack switch in any case, so if user
>>> set up same sas - stack corruption by nested signal.
>>>
>>> Or am I missing the intention?
>>
>> The intention is to make everything completely explicit.  With
>> SS_AUTODISARM, the kernel knows directly whether you're on the signal
>> stack, and there should be no need to look at sp.  If you set
>> SS_AUTODISARM and get a signal, the signal stack gets disarmed.  If
>> you take a nested signal, it's delivered normally.  When you return
>> all the way out, the signal stack is re-armed.
>>
>> For DOSEMU, this means that no 16-bit register state can possibly
>> cause a signal to be delivered wrong, because the register state when
>> a signal is raised won't affect delivery, which seems like a good
>> thing to me.
>
> Yes, but doesn't affect dosemu1 which doesn't use SS_AUTODISARM.
> So IMHO the SS check should still be added, even if not for dosemu2.
>
>
>> If this behavior would be problematic for you, can you explain why?
>
> Only theoretically: if someone sets SS_AUTODISARM inside a
> sighandler. Since this doesn't give EPERM, I wouldn't deliberately
> make it a broken scenario (esp if it wasn't before the particular change).
> Ideally it would give EPERM, but we can't, so doesn't matter much.
> I just wanted to warn about the possible regression.

I suppose we could return an error if you are on the sigstack when
setting SS_AUTODISARM, although I was hoping to avoid yet more special
cases.

> --
> To unsubscribe from this list: send the line "unsubscribe linux-api" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH 1/4] signals/sigaltstack: If SS_AUTODISARM, bypass on_sig_stack Andy Lutomirski <luto@amacapital.net> - 2016-05-14 06:20 +0200
  Re: [PATCH 1/4] signals/sigaltstack: If SS_AUTODISARM, bypass  on_sig_stack Stas Sergeev <stsp@list.ru> - 2016-05-14 13:20 +0200
    Re: [PATCH 1/4] signals/sigaltstack: If SS_AUTODISARM, bypass on_sig_stack Andy Lutomirski <luto@amacapital.net> - 2016-05-14 18:40 +0200

csiph-web