Received: by 10.223.164.221 with SMTP id h29csp2531730wrb; Mon, 30 Oct 2017 05:40:29 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RE6x6mYgjYbYpRlAE0tANP78WhW/7DBVCzT/YmbYwFtzAIjNYer5fLr+KO9ntg+6UjzNwB X-Received: by 10.159.252.200 with SMTP id o8mr7311728pls.80.1509367229739; Mon, 30 Oct 2017 05:40:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509367229; cv=none; d=google.com; s=arc-20160816; b=lO+/REQqcKVoeBPR3u8SSoG+xPflAhSA3dCSBYHRQUppq2g6TxO+LaZxBcuON3pL73 yjZz/5tD2oZ0Sxvb0yGBzY6+TOy4SNG5Jt9uG3Agf/KhPJtoZr85GZ2NtxLOqLawMJ1s hn9xmt4mbF0zlx7Ithv1eQB2X7nu5dLDhSvTpFLPfuYeZfYZ0rVOJzD/GSh6kWCAkipe WebryPD5B78LN1cWb1HvR0/JPxgQvUjebFA6xy9J06/IucSr29L+B75BA/EViGl44YwA MjEt667AeP4816ACE/rn8kd/LI+X6QnuBcIuvprd6nDt1mqTCrUUjcnuLDA9J4oRFnI9 /A6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:cc:dkim-signature :arc-authentication-results; bh=q2Dv1jSo1GBNqCg1ptzaa1oL4b1sosF6Zl77Pmiz20I=; b=LhCMCMv40i+OAvDn3vCCnHID8gVmdBCXK9iqLmRtQUVhqa1jPAAgzXwn80PH5guv4o HlHcchG1x1rAxoRenc9ZyX0AbAYFELKrFhmMzVWzBGwdKacQbmt4OqhlI/oIloW8bC// 1ThAIXdjmLqN5YaVJ24gyUdfoNhpt8ggi0BSuleBx813GRZplKpYzeuTSTQctNACgc0B OpNpWq+U/fiOjPkvJR0tSpMVmDhvWwclfyXfZbiJGzHpbN6A70uTkKnzL456W64Sa1LR a0GFhbhtoCZIl48WWnesJjlOaQdFB0g/UWzQ0AaSEGH1dTsepC2Pea682oUuIqoTpdr3 sWsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SuJrnmcc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h12si9945492pfd.152.2017.10.30.05.40.16; Mon, 30 Oct 2017 05:40:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SuJrnmcc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752074AbdJ3Mi1 (ORCPT + 99 others); Mon, 30 Oct 2017 08:38:27 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:45622 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751975AbdJ3MiY (ORCPT ); Mon, 30 Oct 2017 08:38:24 -0400 Received: by mail-wm0-f44.google.com with SMTP id y80so8742385wmd.0; Mon, 30 Oct 2017 05:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=cc:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=q2Dv1jSo1GBNqCg1ptzaa1oL4b1sosF6Zl77Pmiz20I=; b=SuJrnmccu+EemImcnEM1E/W1U+fAL2amn71x6pxHrn1uMM6OhLRF/WEgg8ALNux6mu nCJfpYMB0aVCnW49GSkpBmqGvOrFEXjLPPhPn02C62zrOQqlxh2jOog2HyMLGUVAbRzm AhfjaTg41pgOSOS8WiK8iLXt1PxOb5+hbJAtWttN7T4n6/9G/ewRqxxthhpgdfCMTQ3u zFzs0K3Ee3PpTOy3RGzswuO9k9LExNam9jJA8nubhzJOrBpxgog0R6S8XZZsBuRG+nAl lBwdRHGw93gFbuy+VYOZO22ljbHRiBsUWQd6B7N3DrDWArVzM0whttRh96HYUqSqJBR7 hd8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:cc:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=q2Dv1jSo1GBNqCg1ptzaa1oL4b1sosF6Zl77Pmiz20I=; b=Op+zTInQPTpauSjKViQNtpnFSiM50P34xLsDucjjT32DSWdNtwkPRLCO86x76xqLJY tw7ZeNNbDI+uBTHj1U6uVni1RiNCur+KvDOMVGH+0upg7hGpFoz7k5Ao8XUhZyfIjUPY FM0eXpDjiG5nM05U2tWTloeFqZRB08JhQ3mb/0Ombmn9w4B38nm4edRC3xYu4i7aCLF3 mEX1DpxLlDPX1jwhiDHn2q+IZET/zPRT3nM6yZvF8mifiunqx+ujnK6CQU6O1QQTKbpz +Pkqcvf4pP3N8S7CQDLk/OK9HY6YMrjAJyR+mSGIRP6eavBqdxNazSFu0D5VqgdxeC9C sB6g== X-Gm-Message-State: AMCzsaWQGKqK4e3WSnNXGsiG0i2zN+20EHGptBnXseF22KIJcu9R4NO1 z6RbvuBpKxDuApfcZ7WUo7KEIYIm X-Received: by 10.28.202.9 with SMTP id a9mr3432861wmg.46.1509367102895; Mon, 30 Oct 2017 05:38:22 -0700 (PDT) Received: from [192.168.234.154] (mail2.jambit.com. [213.131.239.194]) by smtp.gmail.com with ESMTPSA id o14sm9476157wra.54.2017.10.30.05.38.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Oct 2017 05:38:21 -0700 (PDT) Cc: mtk.manpages@gmail.com, linux-man , Andy Lutomirski , Oleg Nesterov , lkml Subject: Re: Documenting sigaltstack SS_AUTODISRM To: Stas Sergeev References: <08467ae1-7187-3b2a-9a78-8af0c10bf816@list.ru> <3907bc2a-0645-8d93-6ee5-3f99874e7022@gmail.com> <32d95303-5839-9279-a1d3-a06f34e3484e@list.ru> <50de8f3b-8a1e-df50-b5dd-d1b74cb77fad@list.ru> <026308b5-4e92-4439-1eb2-82b67584d548@gmail.com> <6f622987-9517-ee7c-2016-ea8c43645e39@list.ru> From: "Michael Kerrisk (man-pages)" Message-ID: Date: Mon, 30 Oct 2017 13:38:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <6f622987-9517-ee7c-2016-ea8c43645e39@list.ru> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/24/2017 10:12 PM, Stas Sergeev wrote: > Hello, > > 24.05.2017 14:09, Michael Kerrisk (man-pages) пишет: >>> Could you please point and cite the spec that says >>> exactly this? >> I take your point: the text of the spec could be more precise. It >> does not provide a complete support for my assertion. >> >> But, I do think the interpretation I suggest is the more natural one, >> for many reasons: > Note: below I am not arguing to whether it is > good or bad to use SS_ONSTACK. This question > is closed as soon as you pointed to EINVAL in > other OSes (it doesn't make it bad immediately, > but at least the outcome of its usage is now > pretty clear for me). > What I still want to point out is the fact that the > implementation in linux was very unlikely caused > by a confusion. It was the decision made in agreement > with the most straight-forward reading of the posix > spec, just maybe without knowing about this EINVAL > problem. And it can't create a compatibility problem > by itself because no one have explicitly promoted its > use: 0 is still accepted. > Why it could create a compatibility problem is only > because people suddenly started to use it, and for > the very simple reason (judging by myself): I was > absolutely confused with this '0' in the example, and > after many attempts to find even a slightest hint in > the same doc why it is safe (why SS_DISABLE can't > be 0), I resorted to looking into the kernel and the > code of other projects. And SS_ONSTACK looked > like a perfectly valid solution, fully agreeing with > the text (i.e. SS_ONSTACK != SS_DISABLE). > So what really creates a compatibility problem here, > is only a misleading text (or a misleading implementation > of it in other OSes). And as such, stating that "someone > was confused" looks more like an unjustified insult to me. :) See previous mail :-). Just by the bye, the correct (according to my definition) way of doing things (ss.ss_flags == 0 to establish an alternate signal stack) has been documented in the manual page since 2001. (That page documented the Linux 2.2 behavior.) >> 1. The field is named '*flags', which commonly means a bit mask. > Indeed, but the value suggests otherwise. > The name for a flag could be "SS_DISABLED" > (with D at the end), while "SS_DISABLE" suggests > an action. And indeed, it doesn't change a property > of a performing action the way SS_AUTODISARM > does. Instead it changes the action itself: the sas > get cleared instead of being set, and all the other > arguments are ignored. Eg I would be very surprised > seeing the "MAP_UNMAP" flag to mmap() that turns > it into munmap(). This more resembles the "action" > argument of the sigprocmask() call. > >> 2. The example in that you mention that is in the spec is part of >> the spec. It illustrates the understanding of the developers >> of the spec about the interface they were specifying. >> 3. Various existing implementations treat the field as a bit mask >> for which there is only one valid bit (SS_DISABLE), doing >> tests of the form (ss.ss_flags & SS_DISABLE). >> 4. Some implementations (including *all* the ones that I looked at >> the source code for, that is Illumos, FreeBSD, OpenBSD) >> explicitly error if ss.ss_flags has bits other than SS_DISABLE set. > Well, yes, those are the practical arguments that > can't be ignored... Of course the one can try to > submit the patch to these projects that nullifies > this argument. :) > >> 6. Before kernel 2.4 (Jan 2001), Linux also used to do 3 & 4! > Is there a discussion about this change somewhere? > >> 8. The standard explicitly mentions that SS_ONSTACK may be returned >> in old_ss.ss_flags, but makes no mention of the use of SS_ONSTACK >> in ss.ss_flags. That fact should, IMO, be taken as a strong hint >> that the standard developers did not believe that SS_ONSTACK was >> to be used with ss.ss_flags. > But this doesn't matter as they "seemingly" allow > any other value than SS_DISABLE, and this one is > the most reasonable value of all (unless you know > this is a bitmask, of course). > > So to make it clear: I am not arguing to what is > better or more portable. I am just not satisfied > with the statement that whoever implemented > it that way (and whoever uses it, too, obviously), > was confused or read the standard badly. It is > not the case. Also I don't agree that this implementation > can create any (portability or any other) kind of > problem: it still accepts 0, and its author didn't > advice anyone to use SS_ONSTACK. So in my eyes > the implementation is perfectly valid, no ifs no > buts. :) Man page can warn people to not use > SS_ONSTACK, but it shouldn't blame the author > of the kernel code in question IMHO. > >>>>>> API history is littered with stories where users found out that >>>>>> something unforeseen "worked", and so they used it. The question >>>>>> is: what can go wrong if people do try using this "feature"? >>>>> It will disappear at the exit from SIGA. >>>>> To me this is "wrong enough" to not suggest doing so. >>>> See my comment above. It's weird because it will disappear at exit >>>> from SIGA, but not "wrong". >>> What do you mean? >>> There was no any notion of the "sigaltstack scope", >>> so with the existing semantic it is wrong, because >>> currently sigaltstack has no scope and can't change >> I'm not sure what you mean by "currently" here. I'm pointing >> out that whereas before one could not change the signal stack >> while executing a handler that is using a signal stack, now it >> seems to be possible. But, it's not random: the programmer must >> explicitly make this happen (and be lucky in the timing of signals). > By "random points" I meant that sas swaps back > to the previous one on a sighandler return. This > sighandler return is just a random point for anyone > who assumes the global scope of the sas. And the > scope of sas was always global, so from that POV > it doesn't work reliably. If you invent some notion > of the scoped sigaltstacks, then you will turn that > into a working functionality with new semantic. > But I don't think you can call this "working" without > first inventing an adequate semantic for it. > >>> at random moments. You can make it "not wrong" >>> by inventing a new semantic with some notion of >>> the "sigaltstack scope" though. Whether it worth the >>> troubles, is what we will see. :) >> I don't think I'm inventing a new semantic. I think you already >> did that :-). The question is what we should say about it in the >> man page. I don't think being silent on this detail is the way to >> go. Perhaps noting a few details and warning the reader strongly >> against relying on this "feature" in any way is appropriate? > This is entirely up to you. My point is just that it is > not a "few details", but really a new semantic with > a notion of a sas's scope. I.e. when the control goes > out of current scope (sighandler return), sas reverts > to the one of the parent scope. Since this was not > envisioned and is unlikely needed to anyone, I was > just suggesting to not do this, but if you want to spec > this all - why not. :) > >>>>> The kernel already has the sigaltstack test-case, >>>>> so maybe you can add some checks to it from your >>>>> test-case. >>>> I must admit I'm still trying to grasp some details of what's >>>> possible. What tests do you think could be usefully added? >>> If you are going to add the scoped/nested sigaltstacks, >>> then perhaps you should add the test that nesting works >>> correctly (you have that already in your test-case), and >>> maybe also the direct manipulations to uc_stack, as this >>> is the only _reliable_ way to set the new sas inside the >>> sighandler, that I can think of. >> See above. I'm not sure that we want to specify things to this >> level. But my point is that in the lack of any text in the man >> page on the topic, some user-space programmers will discover the >> feature and perhaps try to use it. The question is what the man >> page should say to those programmers. Do you see what I mean? > Yes, but I don't see what the man page should say > to those programmers. :) Or if I do, the description > would became too lengthy and complex. So, the man page text currently says: If old_ss is not NULL, then it is used to return information about the alternate signal stack which was in effect prior to the call to sigaltstack(). The old_ss.ss_sp and old_ss.ss_size fields return the starting address and size of that stack. The old_ss.ss_flags may return either of the following values: SS_ONSTACK The process is currently executing on the alternate signal stack. (Note that it is not possible to change the alter‐ nate signal stack if the process is currently executing on it.) SS_DISABLE The alternate signal stack is currently disabled. Alternatively, this value is returned if the process is currently executing on an alternate signal stack that was established using the SS_AUTODISARM flag. In this case, it is safe to switch away from the signal handler with swap‐ context(3). It is also possible to set up a different alternative signal stack using a further call to sigalt‐ stack(). So, given the discussion so far, I think that last sentence needs to be changed. A simple change would be to just remove the sentence. However, as I've tried to bring out, I think that *not* documenting something is generally not a winning strategy. Eventually, people figure out what's possible, and someone may try using the feature. So, as well as removing that sentence, how about some text something like the following in NOTES: When old_ss.ss_flags returns SS_DISABLE, meaning the process is currently executing a signal handler ("X") on an alternate signal stack that was established using the SS_AUTODISARM flag, then it is possible inside that handler to set up a new alternative signal stack using a further call to sigaltstack(). However, this is not recommended. Taking advantage of this possibility is inherently racy, since the new alternate signal stack settings will be removed when signal handler "X" returns. ? Thanks, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ From 1582685939604263469@xxx Mon Oct 30 12:35:31 +0000 2017 X-GM-THRID: 1582678540934340950 X-Gmail-Labels: Inbox,Category Forums