From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0100C12002 for ; Wed, 14 Jul 2021 23:35:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8D63B613C8 for ; Wed, 14 Jul 2021 23:35:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D63B613C8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:Cc:To:Subject:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=fRmFAa/Zfwbq1xqJkWevG7YhDXXw4sfJzqC0CQQRzXI=; b=Pttp2zXRtQadglNsRCYjRx11a1 Qmn4AGIt+tB8HIFIdEHX1wpbCXTabhMqBC+o4GdCaI+ozBtLUkecxqAzqiQubTAZ5FmfGhmWBZevL 4J+B08nFf4SsIgRHOBZ7ccZr91RvNcmcsOuB0DOZp7Ed87KlV+BHEy6X32qmNRMv2w8TV/tpf1n3z rWTbJeZ/PgIYkNMAEshskp8a30qLks5+cH5Z1f6k6DgJQTJPIpmq2eaJxJvhGjqnO3eL2JT4c7LGq bYWnuBJ2YPAZmK7CzgvA3SogxYIvpFiZkB5CHyJWr3uJ7UZkKj0sWndtLG6wUi7YB5zQ0VogV0pdJ TtrElqQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3oMe-00GJlX-Ve; Wed, 14 Jul 2021 23:32:29 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3lcy-00F3UD-2q for linux-arm-kernel@lists.infradead.org; Wed, 14 Jul 2021 20:37:10 +0000 Received: by mail-wm1-x32a.google.com with SMTP id o30-20020a05600c511eb029022e0571d1a0so2225167wms.5 for ; Wed, 14 Jul 2021 13:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=xPnLqVSYQ1uaB/yCls0QSqt5u2fz2yirntcHS/Cl+bU=; b=LizqDyKU9mSnk4N4xorkw1xNc8lRItlnBuSWiBDuHH44sIL+5Q0A9yjdWCUmflcr9A 5N5yj9RE0buOwoxBkK1PaoMIPSS/gtreGDyTvaX2TdL9mBlCAW4M4wtsJh0diNqoNC5v P1j+m9MGJyTrfbL4GbUu7p5DL4l3fMKMYGlSOE2OKHsRONMbJWY/vbAJVhuNknZcETpm 21RNRLK4J2yScgTtx3UlndQOLbR4UmecG/skHINafYkAiYLB/LtCYicLDmHuTyqlQbD6 0bbHBEKAI7/OL7BFkRd+xRAxtcImlU653Qr9SSxfkYuBgEvZ6ZrhD8S8k+uSkfVrYZt8 qwew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=xPnLqVSYQ1uaB/yCls0QSqt5u2fz2yirntcHS/Cl+bU=; b=jzLjXfFVlrF/AfuVTG2cY/5dGDGae96VxN44D842petIdzHCgUSfpi2uf9lzZ143jC dZVsRGj5MOhZ6WMONY4J4aVvVTezFn+yjjoVONxeeldxvD2Ff17NfvIKqqNR0vHkNN1y RDAwBT9jV3qW1H85yr9XOlLcAhbD9E7FJqoMUWmpSBD5yc/eao1Bz1yboMAC2gtfrrmB sui36bptZIPvTBBgnHHgEbvJJHprsDTykiqpjy8QLqod36LD+ERTJQCGflFBw1k2CiNV QVkzuI3MNmkdFdN9Op4Ey18yw1kF7eA8fwDpNFhu0OOoyuV+DoJBRfyzxgNOumSrJgXe vngg== X-Gm-Message-State: AOAM5309OXTGOVu2CFJUdEQMykL9Y456SPd7bFrVPZFHWbkNr4fuTsZe BOetrZvPxY8ke1jdK76i9as= X-Google-Smtp-Source: ABdhPJypnGGTNbeoNLZaaMxJJLMVr/4rkPJ3Mh9LuAmL6rpspoKLO185M5Ulg/6jtMcdEowglLbCNQ== X-Received: by 2002:a7b:cc15:: with SMTP id f21mr6083429wmh.5.1626295023836; Wed, 14 Jul 2021 13:37:03 -0700 (PDT) Received: from [192.168.0.160] ([170.253.36.171]) by smtp.gmail.com with ESMTPSA id n18sm3736231wrt.89.2021.07.14.13.37.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Jul 2021 13:37:03 -0700 (PDT) Subject: Re: [PATCH v3] sigaction.2: Document SA_EXPOSE_TAGBITS and the flag support detection protocol To: Peter Collingbourne , Catalin Marinas , Evgenii Stepanov , Kostya Serebryany , Vincenzo Frascino , Dave Martin , Will Deacon , Oleg Nesterov , "Eric W. Biederman" , "James E.J. Bottomley" , Michael Kerrisk Cc: Linux ARM , Kevin Brodsky , Andrey Konovalov , linux-api@vger.kernel.org, Helge Deller , David Spickett , linux-man@vger.kernel.org References: <20210713013857.3237634-1-pcc@google.com> From: "Alejandro Colomar (man-pages)" Message-ID: Date: Wed, 14 Jul 2021 22:37:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210713013857.3237634-1-pcc@google.com> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210714_133708_208172_6D028A08 X-CRM114-Status: GOOD ( 43.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Peter, On 7/13/21 3:38 AM, Peter Collingbourne wrote: > Signed-off-by: Peter Collingbourne > --- > This feature landed back in 5.11, but the manpage > update seems to have fallen through the cracks. Sorry, I don't remember what happened :/ Thanks for the ping. > Here's a v3 with the introducing version specified > and with one formatting nit fixed. Please See some comments below (especially in the example code). BTW, could you please link to the thread in the kernel mailing list that added this feature? Thanks, Alex > > v3: > - s/5.x/5.11/g > - s/.IR/.I/ in one location > > v2: > - fix formatting > - address feedback from Dave > > man2/sigaction.2 | 125 +++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 125 insertions(+) > > diff --git a/man2/sigaction.2 b/man2/sigaction.2 > index 57ad6418c..6b90982d4 100644 > --- a/man2/sigaction.2 > +++ b/man2/sigaction.2 > @@ -261,6 +261,44 @@ This flag is meaningful only when establishing a signal handler. > .\" .I sa_sigaction > .\" field was added in Linux 2.1.86.) > .\" > +.TP > +.BR SA_UNSUPPORTED s/.BR/.B/ > +Used to dynamically probe for flag bit support. > +.IP > +If an attempt to register a handler succeeds with this flag set in > +.I act->sa_flags > +alongside other flags that are potentially unsupported by the kernel, > +and an immediately subsequent > +.BR sigaction () > +call specifying the same signal number n and with non-NULL > +.I oldact > +yields > +.B SA_UNSUPPORTED > +.I clear > +in > +.IR oldact->sa_flags , > +then > +.I oldact->sa_flags > +may be used as a bitmask > +describing which of the potentially unsupported flags are, > +in fact, supported. > +See the section "Dynamically probing for flag bit support" > +below for more details. > +.TP > +.BR SA_EXPOSE_TAGBITS " (since Linux 5.11)" > +Normally, when delivering a signal, > +an architecture-specific set of tag bits are cleared from the > +.I si_addr > +field of > +.IR siginfo_t . > +If this flag is set, > +an architecture-specific subset of the tag bits will be preserved in > +.IR si_addr . > +.IP > +Programs that need to be compatible with Linux versions older than 5.11 > +must use > +.B SA_UNSUPPORTED > +to probe for support. > .SS The siginfo_t argument to a SA_SIGINFO handler > When the > .B SA_SIGINFO > @@ -846,6 +884,93 @@ Triggered by a > .BR seccomp (2) > filter rule. > .RE > +.SS Dynamically probing for flag bit support > +The > +.BR sigaction () > +call on Linux accepts unknown bits set in > +.I act->sa_flags > +without error. > +The behavior of the kernel starting with Linux 5.11 is that a second > +.BR sigaction () > +will clear unknown bits from > +.IR oldact->sa_flags . > +However, historically, a second > +.BR sigaction () > +call would typically leave those bits set in > +.IR oldact->sa_flags . > +.PP > +This means that support for new flags cannot be detected > +simply by testing for a flag in > +.IR sa_flags , > +and a program must test that > +.B SA_UNSUPPORTED > +has been cleared before relying on the contents of > +.IR sa_flags . > +.PP > +Since the behavior of the signal handler cannot be guaranteed > +unless the check passes, > +it is wise to either block the affected signal > +while registering the handler and performing the check in this case, > +or where this is not possible, > +for example if the signal is synchronous, to issue the second > +.BR sigaction () > +in the signal handler itself. > +.PP > +In kernels that do not support a specific flag, > +the kernel's behavior is as if the flag was not set, > +even if the flag was set in > +.IR act->sa_flags . > +.PP > +The flags > +.BR SA_NOCLDSTOP , > +.BR SA_NOCLDWAIT , > +.BR SA_SIGINFO , > +.BR SA_ONSTACK , > +.BR SA_RESTART , > +.BR SA_NODEFER , > +.BR SA_RESETHAND , > +and, if defined by the architecture, > +.B SA_RESTORER > +may not be reliably probed for using this mechanism, > +because they were introduced before Linux 5.11. > +However, in general, programs may assume that these flags are supported, > +since they have all been supported since Linux 2.6, > +which was released in the year 2003. > +.PP > +The following example program exits with status 0 if > +.B SA_EXPOSE_TAGBITS > +is determined to be supported, and 1 otherwise. > +.PP > +.EX > +#include > +#include > +#include > + > +void handler(int signo, siginfo_t *info, void *context) { Use 4-space indents. > + struct sigaction oldact; > + if (sigaction(SIGSEGV, 0, &oldact) == 0 && > + !(oldact.sa_flags & SA_UNSUPPORTED) && > + (oldact.sa_flags & SA_EXPOSE_TAGBITS)) { > + _exit(0); > + } else { > + _exit(1); > + } > +} > + > +int main(void) { > + struct sigaction act = {}; The {} initializer is a GCC extension. Please use the C99-conforming {0} zero initializer. See . > + act.sa_flags = SA_SIGINFO | SA_UNSUPPORTED | SA_EXPOSE_TAGBITS; > + act.sa_sigaction = handler; > + if (sigaction(SIGSEGV, &act, 0) != 0) { > + perror("sigaction"); > + return 1; > + } > + > + /* Force a SIGSEGV. */ > + *(volatile int *)0 = 0; Isn't this equivalent to the following (which wouldn't need a comment)?: raise(SIGSEGV); > + return 1; > +} > +.EE > .SH RETURN VALUE > .BR sigaction () > returns 0 on success; on error, \-1 is returned, and > -- Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel