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=-13.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 6FFDCC433E1 for ; Tue, 25 Aug 2020 14:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44E842076C for ; Tue, 25 Aug 2020 14:25:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726104AbgHYOZT (ORCPT ); Tue, 25 Aug 2020 10:25:19 -0400 Received: from foss.arm.com ([217.140.110.172]:59990 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725893AbgHYOZT (ORCPT ); Tue, 25 Aug 2020 10:25:19 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B9A4B1FB; Tue, 25 Aug 2020 07:25:18 -0700 (PDT) Received: from arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D544A3F71F; Tue, 25 Aug 2020 07:25:16 -0700 (PDT) Date: Tue, 25 Aug 2020 15:25:14 +0100 From: Dave Martin To: Peter Collingbourne Cc: Parisc List , Catalin Marinas , Kevin Brodsky , Oleg Nesterov , Evgenii Stepanov , "James E.J. Bottomley" , Kostya Serebryany , "Eric W. Biederman" , Andrey Konovalov , David Spickett , Vincenzo Frascino , Will Deacon , Linux ARM , Richard Henderson Subject: Re: [PATCH v9 3/6] signal: clear non-uapi flag bits when passing/returning sa_flags Message-ID: <20200825142512.GQ6642@arm.com> References: <68bd2d6544fb17bbe2fb90862e28ec38e079549a.1597720138.git.pcc@google.com> <20200819103948.GF6642@arm.com> <20200824134000.GK6642@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org On Mon, Aug 24, 2020 at 05:51:34PM -0700, Peter Collingbourne wrote: > On Mon, Aug 24, 2020 at 6:40 AM Dave Martin wrote: > > > > On Wed, Aug 19, 2020 at 04:39:53PM -0700, Peter Collingbourne wrote: > > > On Wed, Aug 19, 2020 at 3:39 AM Dave Martin wrote: > > > > > > > > On Mon, Aug 17, 2020 at 08:33:48PM -0700, Peter Collingbourne wrote: [...] > > > > > diff --git a/kernel/signal.c b/kernel/signal.c > > > > > index 42b67d2cea37..348b7981f1ff 100644 > > > > > --- a/kernel/signal.c > > > > > +++ b/kernel/signal.c > > > > > @@ -3984,6 +3984,16 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) > > > > > if (oact) > > > > > *oact = *k; > > > > > > > > > > + /* > > > > > + * Clear unknown flag bits in order to allow userspace to detect missing > > > > > + * support for flag bits and to allow the kernel to use non-uapi bits > > > > > + * internally. > > > > > + */ > > > > > + if (act) > > > > > + act->sa.sa_flags &= SA_UAPI_FLAGS; > > > > > + if (oact) > > > > > + oact->sa.sa_flags &= SA_UAPI_FLAGS; > > > > > + > > > > > > > > Seems reasonable. > > > > > > Thanks. I also decided to check how other operating systems handle > > > unknown flag bits in sigaction.sa_flags. It looks like OpenBSD and > > > illumos also accept unknown bits but (implicitly, as a result of using > > > a different internal representation) end up clearing them in oldact: > > > > > > https://github.com/openbsd/src/blob/f634a6a4b5bf832e9c1de77f7894ae2625e74484/sys/kern/kern_sig.c#L278 > > > https://github.com/illumos/illumos-gate/blob/76f19f5fdc974fe5be5c82a556e43a4df93f1de1/usr/src/uts/common/syscall/sigaction.c#L86 > > XNU does the same: > > https://github.com/apple/darwin-xnu/blob/a449c6a3b8014d9406c2ddbdc81795da24aa7443/bsd/kern/kern_sig.c#L480 > > > > > > > and FreeBSD and NetBSD fail the syscall if unknown bits are set: > > > > > > https://github.com/freebsd/freebsd/blob/eded70c37057857c6e23fae51f86b8f8f43cd2d0/sys/kern/kern_sig.c#L699 > > > https://github.com/NetBSD/src/blob/3365779becdcedfca206091a645a0e8e22b2946e/sys/kern/sys_sig.c#L473 > > > > > > So there is some precedent for doing what we're planning to do here, > > > which makes it yet more likely that we'll be okay doing this. > > > > Ack, it's good to have that extra evidence to support this approach. > > > > This also means that other OSes could adopt the new Linux flag(s) with > > comatible semantics, if they wanted to. Or have I misunderstood > > something there? > > The other OSs could adopt SA_XFLAGS, but they would probably have no > need for SA_UNSUPPORTED because they already have a protocol for > detecting missing flag support in the kernel (Linux is really the odd > one out here in not supporting such a protocol from the start). > Userspace programs running on OpenBSD, illumos and XNU could use the > Linux protocol without the SA_UNSUPPORTED part, while programs running > on FreeBSD and NetBSD could do something like: > > static bool has_xflags = true; > [...] > struct sigaction act; > act.sa_flags = SA_SIGINFO | SA_XFLAGS; > if (sigaction(SIGSEGV, &act, 0) != 0) { > has_xflags = false; > act.sa_flags = SA_SIGINFO; > if (sigaction(SIGSEGV, &act, 0) != 0) > perror("sigaction"); > } > > It would probably be possible to write a unified function that would > support all three protocols. Ack, I think that's about as well as we can reasonably do in the circumstances. Cheers ---Dave 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=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,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 666C8C433E1 for ; Tue, 25 Aug 2020 14:26:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 2DFA52076C for ; Tue, 25 Aug 2020 14:26:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sT4l6QOA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DFA52076C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CUIRBKW5z2UYiL8EMLfnXXUsri3iDk6ZoPD4yyMnbkw=; b=sT4l6QOASli28Qbr1W6LzQdsD nzbpN3dmmZh9PrmIlNpR6lu6UtW9w+eY4Az0rJzQWeC4dIdfTQfKjJ3aBqikB6Y3jQ5Nl202n3LK6 kHrxx+ukxWBc6oXAQ/3Q7CqATYN9sUv3TJ1E2xWYubJwboiDy0dDLdzRkV6BniWpuCIcKjZiJoTWo bSRLLsaaHkgc/DI1dj8duz22EsaEWVGo2BN7TCZ3V3AiBm1AcUGw6sguFiu8llpQAS2dN2HCVCHkm 0NC02spWYgzjnTO5xNsggCvp1jNxYQ78y6iytYnpXm8WZJbyZYoKNI/wdMIvv9OcvpYAvL4xN1PMV vDHYNrQJA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAZt6-0006Ui-Ln; Tue, 25 Aug 2020 14:25:24 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAZt4-0006Tf-Gt for linux-arm-kernel@lists.infradead.org; Tue, 25 Aug 2020 14:25:23 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B9A4B1FB; Tue, 25 Aug 2020 07:25:18 -0700 (PDT) Received: from arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D544A3F71F; Tue, 25 Aug 2020 07:25:16 -0700 (PDT) Date: Tue, 25 Aug 2020 15:25:14 +0100 From: Dave Martin To: Peter Collingbourne Subject: Re: [PATCH v9 3/6] signal: clear non-uapi flag bits when passing/returning sa_flags Message-ID: <20200825142512.GQ6642@arm.com> References: <68bd2d6544fb17bbe2fb90862e28ec38e079549a.1597720138.git.pcc@google.com> <20200819103948.GF6642@arm.com> <20200824134000.GK6642@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200825_102522_666356_E1CFA0B5 X-CRM114-Status: GOOD ( 30.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linux ARM , Parisc List , Catalin Marinas , Kevin Brodsky , Oleg Nesterov , "James E.J. Bottomley" , Kostya Serebryany , "Eric W. Biederman" , Andrey Konovalov , David Spickett , Vincenzo Frascino , Will Deacon , Evgenii Stepanov , Richard Henderson 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 On Mon, Aug 24, 2020 at 05:51:34PM -0700, Peter Collingbourne wrote: > On Mon, Aug 24, 2020 at 6:40 AM Dave Martin wrote: > > > > On Wed, Aug 19, 2020 at 04:39:53PM -0700, Peter Collingbourne wrote: > > > On Wed, Aug 19, 2020 at 3:39 AM Dave Martin wrote: > > > > > > > > On Mon, Aug 17, 2020 at 08:33:48PM -0700, Peter Collingbourne wrote: [...] > > > > > diff --git a/kernel/signal.c b/kernel/signal.c > > > > > index 42b67d2cea37..348b7981f1ff 100644 > > > > > --- a/kernel/signal.c > > > > > +++ b/kernel/signal.c > > > > > @@ -3984,6 +3984,16 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) > > > > > if (oact) > > > > > *oact = *k; > > > > > > > > > > + /* > > > > > + * Clear unknown flag bits in order to allow userspace to detect missing > > > > > + * support for flag bits and to allow the kernel to use non-uapi bits > > > > > + * internally. > > > > > + */ > > > > > + if (act) > > > > > + act->sa.sa_flags &= SA_UAPI_FLAGS; > > > > > + if (oact) > > > > > + oact->sa.sa_flags &= SA_UAPI_FLAGS; > > > > > + > > > > > > > > Seems reasonable. > > > > > > Thanks. I also decided to check how other operating systems handle > > > unknown flag bits in sigaction.sa_flags. It looks like OpenBSD and > > > illumos also accept unknown bits but (implicitly, as a result of using > > > a different internal representation) end up clearing them in oldact: > > > > > > https://github.com/openbsd/src/blob/f634a6a4b5bf832e9c1de77f7894ae2625e74484/sys/kern/kern_sig.c#L278 > > > https://github.com/illumos/illumos-gate/blob/76f19f5fdc974fe5be5c82a556e43a4df93f1de1/usr/src/uts/common/syscall/sigaction.c#L86 > > XNU does the same: > > https://github.com/apple/darwin-xnu/blob/a449c6a3b8014d9406c2ddbdc81795da24aa7443/bsd/kern/kern_sig.c#L480 > > > > > > > and FreeBSD and NetBSD fail the syscall if unknown bits are set: > > > > > > https://github.com/freebsd/freebsd/blob/eded70c37057857c6e23fae51f86b8f8f43cd2d0/sys/kern/kern_sig.c#L699 > > > https://github.com/NetBSD/src/blob/3365779becdcedfca206091a645a0e8e22b2946e/sys/kern/sys_sig.c#L473 > > > > > > So there is some precedent for doing what we're planning to do here, > > > which makes it yet more likely that we'll be okay doing this. > > > > Ack, it's good to have that extra evidence to support this approach. > > > > This also means that other OSes could adopt the new Linux flag(s) with > > comatible semantics, if they wanted to. Or have I misunderstood > > something there? > > The other OSs could adopt SA_XFLAGS, but they would probably have no > need for SA_UNSUPPORTED because they already have a protocol for > detecting missing flag support in the kernel (Linux is really the odd > one out here in not supporting such a protocol from the start). > Userspace programs running on OpenBSD, illumos and XNU could use the > Linux protocol without the SA_UNSUPPORTED part, while programs running > on FreeBSD and NetBSD could do something like: > > static bool has_xflags = true; > [...] > struct sigaction act; > act.sa_flags = SA_SIGINFO | SA_XFLAGS; > if (sigaction(SIGSEGV, &act, 0) != 0) { > has_xflags = false; > act.sa_flags = SA_SIGINFO; > if (sigaction(SIGSEGV, &act, 0) != 0) > perror("sigaction"); > } > > It would probably be possible to write a unified function that would > support all three protocols. Ack, I think that's about as well as we can reasonably do in the circumstances. Cheers ---Dave _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel