Received: by 10.223.164.202 with SMTP id h10csp739755wrb; Mon, 6 Nov 2017 14:45:58 -0800 (PST) X-Google-Smtp-Source: ABhQp+Ts42donVGDGxzch000DrpieFnfdZdxoWj6GUnuZ8zroy9yDpXOtNYeoq7YkLgk9F8n3s2L X-Received: by 10.101.91.78 with SMTP id y14mr16752884pgr.380.1510008358405; Mon, 06 Nov 2017 14:45:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510008358; cv=none; d=google.com; s=arc-20160816; b=rUuwkdxxf26Vgk5e374JIFbv9Rzz/9rlQRX+5Lll4Bx9XgXD4t8CEwSkHMy/pFEDG6 HsWiBxiajOCtHg6gOe4LJQPdd5Yt5r0R8QcHmsrNcWGGZFi+gmi13Mi3ihsEaqB36zy1 BohOYR0e+zMGjw6x/YgCmkLB9rTXugNREYOafZJMoy/Z7dae+b5JfQYlJVeanTXpHZv2 JBMcoUiRw6sg9pu9o+InV1+mREiU2ztjNx9r0PcmB3XEfqaVCVZAX7GsfALqehw0sCLE w1N6UtJdzUHcI1Km3nOXxlvqCdoNwxRVfOhtU0ASYMb3ZBxVcvkm/Nfa7EPqKIookT7s 0SdQ== 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=z/i+J8LaMUJsBQxB9lL2eqWkjLXhwhP+Fj356daycUE=; b=lEhqEEU4n8QWRpX9Dal+RbtytM/sGli6VaPLwSB16MTk0z+uDuvs1DpexX26mc689t ZWkmh1QinsMmUHmTdYvw5XF+asfP/8cjJ2czMSIe7PdersQKQx8dAQkDMtMmV1GTGIak Uz96M2d75XC2pDd2BvH5ouGSn/XU14kMyIeRedRd7hRWnGvIt+IJhnP9H2FDn/xQLuOo 1PGS52ZAQng8OUpgXopEr3J4gtyAdFBeWJqwg5p85UUG2uNsJ3Lr9Au0KgOKn2Z+62aJ LeXf2yt8Owfmb5uEgEX8ynRuPnXmr2/a4h7kTRO14jx4s+o/f0/c5xAMbvQeGfy7+9ly Yxgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IUchr++f; 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 t61si10758766plb.707.2017.11.06.14.45.44; Mon, 06 Nov 2017 14:45:58 -0800 (PST) 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=IUchr++f; 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 S1752916AbdKFW0Z (ORCPT + 94 others); Mon, 6 Nov 2017 17:26:25 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:55777 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751622AbdKFW0X (ORCPT ); Mon, 6 Nov 2017 17:26:23 -0500 Received: by mail-wm0-f45.google.com with SMTP id y83so89345wmc.4; Mon, 06 Nov 2017 14:26:22 -0800 (PST) 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=z/i+J8LaMUJsBQxB9lL2eqWkjLXhwhP+Fj356daycUE=; b=IUchr++ffsn5Jj+e68Vfz9OhNDoNiwvHrj1zaF4bkpM9H3aUw2Z9Dt3lVTYMB/1Svm HvX9hZ4mZLbS1izqzxx1v4vce0oMgHMJBF0ATOQmGNKf2yJ49iQRaR2poUomA8l7hJcS s7mEOCOu1PxZLvV4F4FPfbNXPuZai7m9Cj6jZWwTosT0vGX7q0BLwiew/xvfJjqUbMi6 oPwfLKsVBPMaIq873YUyWL9G3UWmXBF3AeiF6i0U4MsO83PJVig7fJaxBE+/LxGxPEbA vJidFMruDjfRIG29OyrGnUuC1GOhiQQEmlh+ZtmPAhdpng/ly+guLUWJ+lV+s9w+JFBq PgfA== 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=z/i+J8LaMUJsBQxB9lL2eqWkjLXhwhP+Fj356daycUE=; b=nrF/i3zDSm8QgjEoj91FRU02+s6+dsyQciBaAB/0dM0efrh36rw5tC/IxqX6bmgf51 CZqcBBW+yLVNzC+DjhYk3gXlyl1z1Reu1Hxs7Mp1CsrkDLRYEg4MgwHO29lsm/9ZlhnH 38lRBETr+v4u+Uc3CVodZlhPxpnIuhB0PJzlPycrF9HKolIoK5ObcgXnp/jB3qpUn4OW Q0P0BUs4VHnB+2+EBKMCmaPpgYvf3Bl+mmMh6Xdm8et3KSDA0W484uaYA5GBVtT/+hMM uqtpg5nqbXXW9o02jay6T7vSDxFlgNzdzEjdsaUVp35IhtWkugcsANkRuGikLLvjHLB0 X07w== X-Gm-Message-State: AJaThX67oUSOJ6lGITgpIF2eDkIhZJjt0rZOLFzhrZZjmw+9/iEymbrF iBQ1ewc1+Kbvs7Ob6VQmIRZ1td3X X-Received: by 10.28.144.140 with SMTP id s134mr7000147wmd.82.1510007181872; Mon, 06 Nov 2017 14:26:21 -0800 (PST) Received: from ?IPv6:2001:a61:2446:4700:7ee9:d3ff:fef5:1a91? ([2001:a61:2446:4700:7ee9:d3ff:fef5:1a91]) by smtp.gmail.com with ESMTPSA id q74sm12405187wrb.51.2017.11.06.14.26.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 14:26:20 -0800 (PST) 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, 6 Nov 2017 23:26:20 +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: 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 Hello Stas, Ping on the below? Cheers, Michael On 10/30/2017 01:38 PM, Michael Kerrisk (man-pages) wrote: > 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 1582687220985006577@xxx Mon Oct 30 12:55:53 +0000 2017 X-GM-THRID: 1582678540934340950 X-Gmail-Labels: Inbox,Category Forums