From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER,SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 272961F4B4 for ; Mon, 12 Oct 2020 14:13:26 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5C1A386F447; Mon, 12 Oct 2020 14:13:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5C1A386F447 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1602512005; bh=eDrGUf94UFA4haB+NT9jVUkoAjn/c/EYI9gqK0z+kmg=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fVNUVx9K+SBspdtXeLKNBKZJ2WjHZYl2KVPB4N3aOiCIvsmEBGTzIyl8+Kzf8VXAd QXcrVQdp4onOFkWZkP3OoxEvm5NEGIUEIae9aB1qQiW/7mudJEbqO2d9mDl2Ln3s9t mnItTKSm/j2liIX3gLKen9PPyYcOVe184Vxsq3do= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2082.outbound.protection.outlook.com [40.107.21.82]) by sourceware.org (Postfix) with ESMTPS id 20A89386F446 for ; Mon, 12 Oct 2020 14:13:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 20A89386F446 Received: from AM6PR05CA0010.eurprd05.prod.outlook.com (2603:10a6:20b:2e::23) by DB7PR08MB3705.eurprd08.prod.outlook.com (2603:10a6:10:78::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.22; Mon, 12 Oct 2020 14:13:19 +0000 Received: from AM5EUR03FT026.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2e:cafe::b) by AM6PR05CA0010.outlook.office365.com (2603:10a6:20b:2e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.21 via Frontend Transport; Mon, 12 Oct 2020 14:13:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT026.mail.protection.outlook.com (10.152.16.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.23 via Frontend Transport; Mon, 12 Oct 2020 14:13:18 +0000 Received: ("Tessian outbound a0bffebca527:v64"); Mon, 12 Oct 2020 14:13:18 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3f8a87e61c5d8698 X-CR-MTA-TID: 64aa7808 Received: from c36409d4c3af.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0E6559F4-BBDC-4626-9B8C-E9906A7AC790.1; Mon, 12 Oct 2020 14:12:41 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c36409d4c3af.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 12 Oct 2020 14:12:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FZ2Wwr+3vpJSaVVewl5FFRoxFNk3VpzvM1yAB1khQqLXPbydfw+D5gS0jsMOIQM49rSYLL1pG+H14hXMLukjZ59VTLH+0m8vOXO66B+egge3lKbeV1hCu/juOTgL1/Vms738deXgueJuruy5j6W+LU7/leDpFpBaB+YIxrKwBv41WGcXUICD6CgYiI391iUhv3h0f0YH983PdVEe80ASUkMEu4bLOWjTAcofMRHkV+AdJLDcWTGUbdNu1ixT8rGdWd7G2NKv1cUrksmIbETyr857kVejpEybCd0qIjNXtfjgChaa4tJBwVz0bJBpDo9EANM6bkzz/qeKywOPno4Kqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eDrGUf94UFA4haB+NT9jVUkoAjn/c/EYI9gqK0z+kmg=; b=nUOnRmcMg77tg6+qqFeSADHUu5JoKgkW71KXP5YXRt4CNMkLw4ZzIi7IXfLqawA+gppg8b+8EDOGxrsGuZ41SLzk8Y3l+4CYZc9BF6g6Z17402JSVkm9ZDePtAJ/4RLCmTaQ+lY94b+6oFVDoYpd3G/jqQcz38t1wJmuzti8dca1J9KjXKrRH9kwTBVlatMSXsdnQSDEfpBaruGCk1EKhmumkhuF+YVQpBwFpxCXWr7THjuO451vJ9t4foI/1tL7kb/jWE6p0x2Ga35XMSMbkCuwF/76yEFIBQYe+JAG7YuDNkteHeVS6bpwi/Zkj9vCm2ld1wGXWkGxjhVyMkhWfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; Received: from PR3PR08MB5564.eurprd08.prod.outlook.com (2603:10a6:102:87::18) by PA4PR08MB6269.eurprd08.prod.outlook.com (2603:10a6:102:ed::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.28; Mon, 12 Oct 2020 14:12:40 +0000 Received: from PR3PR08MB5564.eurprd08.prod.outlook.com ([fe80::957e:c80e:98f4:23d6]) by PR3PR08MB5564.eurprd08.prod.outlook.com ([fe80::957e:c80e:98f4:23d6%6]) with mapi id 15.20.3455.030; Mon, 12 Oct 2020 14:12:40 +0000 Date: Mon, 12 Oct 2020 15:12:38 +0100 To: Dave Martin Subject: Re: [PATCH] sysconf: Add _SC_MINSIGSTKSZ/_SC_SIGSTKSZ [BZ #20305] Message-ID: <20201012141237.GC3819@arm.com> References: <20201010121935.3263605-1-hjl.tools@gmail.com> <20201012075332.GB3819@arm.com> <20201012110359.GA32292@arm.com> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201012110359.GA32292@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: LO2P265CA0107.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::23) To PR3PR08MB5564.eurprd08.prod.outlook.com (2603:10a6:102:87::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.54) by LO2P265CA0107.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.21 via Frontend Transport; Mon, 12 Oct 2020 14:12:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ed0b426c-8c9d-4710-0a79-08d86eb8f82b X-MS-TrafficTypeDiagnostic: PA4PR08MB6269:|DB7PR08MB3705: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: UYSDqE++O3g4i+XnQ1UegQ2JfgWTnourYwigPsZ/eQb4NfmKxb5+4T3irut9ngkTKQdOXuL8e6dqGcZCxocrn7ILdRLIwa34YzeWleHwTefCsLJbYbJ/wOhpULOdNKKqKQ7BSyLbtH43yCj+MUlyp902Yy6xG9dXr3QQOytPfv14FSGGtbZe2wmo/AAMnRgUSezWRWt1gfeP8YbzRKxvXdFxPhvFMeMfaTKOAwPHumFgasuBV6vmy+TPKsex+kxZllRyBXEGfWXiSvz3gep6ihzYFJ+7JOEjgZVSYe6h3OByAF4T/k/HhxhJ6lB3CF/MmBQA3xPfQRXiMJLRwQ4UcA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PR3PR08MB5564.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(136003)(376002)(346002)(39860400002)(396003)(7696005)(86362001)(36756003)(2616005)(55016002)(83380400001)(2906002)(16526019)(186003)(52116002)(4326008)(33656002)(44832011)(478600001)(6636002)(1076003)(316002)(956004)(8936002)(26005)(6862004)(5660300002)(8676002)(66946007)(8886007)(66476007)(66556008)(37006003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vQA1dtR7dx5Q1mNA44aU6tOatdp42HfKIGGyzOQPmbFCXOvjY32rHXGpiiDxnQGKIHYW9hydr1DKYQQG2YG4zWocbH4nwyY9vGsOHXMhY0TZl59QEWgeWiRMiLa7HNjOOtqw/6NJLun/k7SXF3LN3S3S3J9gv3hjnLfAiFrtRtJvanQd4QpEOyUpjdnoCFBY5vDSPPQdaqOLCwTT8ulSIDT2S2nzM7dGt8/vrkTZX1DWEbQFLgb+i56F8Uq6AAWls+OI+IziGo+Nur3UiIbPNBAruIFaa614YwdwjHPdI0+jozyaLlLQ5NohibUEwCIlq8pBFguba7d0zKt5mQAzenQSae2hTCFtojnlDA7YoLC6KZX+b5qR81evfwG50vU+0eeACDfgufaJuuecyaHSTe29Exo0EWUuFNeTXET7lhodZwdBAK0QDvuGEnh98EHqXnYSiAUZKiMNNK0PHaSSprRyEA2CVJtMekrzErjT/2wI3KNTFmU8VS6km9nz/vJOTyXhUknxNySmnje5aqDXYGRV4OXqBTPvLb0/NMwQqZlp7y67lzxCBvnTueQ2Lw3I/a7x5y1hDdAkR7JbrACKKM4wauDeJMeyogkoY8m95WOgTIs21go83aU01pHkiXXdmQ8P1XPxaot6qeJdbKWqBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6269 Original-Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: c5e04f28-be69-456e-63c7-08d86eb8e0cc X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gkTubNQGnbBaZbWAg9Wlzt/F3tD3cg/Mttc68FEC4DUfKsSOBk2BuTy8Z5NHvAgdwv/Nqwg0luRmldNuGMWrDIvOJIMNVm3RlhZO524RlyfSQ9oMEpM+z01BKgjGBt0K6qErjM2oc5naB4ZAKNCf/K4/rZF8gcoBMs7gElursG/vjjpTyHn/D+9mYbAysYE4Jgeh6NOTYqIGnf6Xi+FlmZeby+LOpVl/EidsN+SmiImAr9u410JRGeXJLHjdC0OhMYsdfU6gWDnVIiaV5MChMzwF6XLg2FlBAr2436WKYxagCkXGYl3c10VpJZ+9+Df95GoPbVm1Sl5NomP4XeGj942YUHtKrW5QVsYhJ/c4oikFMBViwiqYXFcNTkS2UwGrGTffhSDwaOZpSTMC8tgYXQ== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(136003)(396003)(39860400002)(346002)(376002)(46966005)(6636002)(70206006)(26005)(2906002)(16526019)(86362001)(33656002)(8936002)(81166007)(83380400001)(82740400003)(5660300002)(70586007)(8676002)(4326008)(82310400003)(186003)(478600001)(44832011)(36756003)(8886007)(6862004)(55016002)(1076003)(356005)(316002)(336012)(37006003)(107886003)(956004)(2616005)(36906005)(7696005)(47076004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2020 14:13:18.8959 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed0b426c-8c9d-4710-0a79-08d86eb8f82b X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3705 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Szabolcs Nagy via Libc-alpha Reply-To: Szabolcs Nagy Cc: libc-alpha@sourceware.org, libc-coord@lists.openwall.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The 10/12/2020 12:04, Dave Martin wrote: > On Mon, Oct 12, 2020 at 08:53:32AM +0100, Szabolcs Nagy via Libc-alpha wrote: > > The 10/10/2020 05:19, H.J. Lu via Libc-alpha wrote: > > > Add _SC_MINSIGSTKSZ for the minimum signal stack size derived from > > > AT_MINSIGSTKSZ, which is the minimum number of bytes of free stack > > > space required in order to gurantee successful, non-nested handling > > > of a single signal whose handler is an empty function, and _SC_SIGSTKSZ > > > which is the suggested minimum number of bytes of stack space required > > > for a signal stack. > > > > > > If AT_MINSIGSTKSZ isn't available, sysconf (_SC_MINSIGSTKSZ) returns > > > MINSIGSTKSZ. On Linux/x86 with XSAVE, the signal frame used by kernel > > > is composed of the following areas and laid out as: > > > > > > ------------------------------ > > > | alignment padding | > > > ------------------------------ > > > | xsave buffer | > > > ------------------------------ > > > | fsave header (32-bit only) | > > > ------------------------------ > > > | siginfo + ucontext | > > > ------------------------------ > > > > > > Compute AT_MINSIGSTKSZ value as size of xsave buffer + size of fsave > > > header (32-bit only) + size of siginfo and ucontext + alignment padding. > > > > > > If _SC_SIGSTKSZ_SOURCE is defined, MINSIGSTKSZ and SIGSTKSZ are redefined > > > as > > > > > > /* Default stack size for a signal handler: sysconf (SC_SIGSTKSZ). */ > > > # undef SIGSTKSZ > > > # define SIGSTKSZ sysconf (_SC_SIGSTKSZ) > > > > > > /* Minimum stack size for a signal handler: SIGSTKSZ. */ > > > # undef MINSIGSTKSZ > > > # define MINSIGSTKSZ SIGSTKSZ > > > > > > Compilation will fail if the source assumes constant MINSIGSTKSZ or > > > SIGSTKSZ. > > > > > > The reason for not simply increasing the kernel's MINSIGSTKSZ #define > > > (apart from the fact that it is rarely used, due to glibc's shadowing > > > definitions) was that userspace binaries will have baked in the old > > > value of the constant and may be making assumptions about it. > > > > > > For example, the type (char [MINSIGSTKSZ]) changes if this #define > > > changes. This could be a problem if an newly built library tries to > > > memcpy() or dump such an object defined by and old binary. > > > Bounds-checking and the stack sizes passed to things like sigaltstack() > > > and makecontext() could similarly go wrong. > > > > > > this looks reasonable to me. > > > > i added libc-coord on cc as it seems to be > > a useful generic api across targets. > > > > > > /* Return MAX (MINSIGSTKSZ, sysconf (_SC_MINSIGSTKSZ)) * 4. */ > > this can be excessive for sigstksz, > > but reasonable on glibc given the > > overhead of libc internal signals > > and lazy binding. > > Interesting points. Can we put actual numbers on those? > > Code that tries to allocate correctly sized stacks would need this > information. that's not easy in general (and the user would also need to know the stack use of libc calls). i think libc internal sigframe and lazy binding are both roughly MINSIGSTKSZ (because they are dominated by the register state that has to be saved), i actually don't know if libc internal signals go to the user registered sigaltstack or not (if not then that's not an issue here, but still an issue for PTHREAD_STACK_MIN). (if libc internal signals could somehow always go to a libc internal sigaltstack that would be best probably, but there is no api for that) > > does this decrease the size on any > > existing target? > > To avoid unpleasant surprises, I think we should explicitly clamp both > parameters to be no less than the value of the legacy #define. Then > the answer becomes "no" by construction. Allowing them to be smaller > will likely save little memory, so it's probably not worth the risk it. > > (The same rule doesn't apply to AT_MINSIGSTKSZ though, since that's a > new invention, and purely a property of the kernel. We yield the "true" > kernel value there, which can be less then MINSIGSTKSZ.) note that there is a posix conformance requirement on sigaltstack: The sigaltstack() function shall fail if: [ENOMEM] The size of the alternate stack area is less than MINSIGSTKSZ. if there are multiple different views on what MINSIGSTKSZ is then it's not clear what this requirement is about. i think glibc does not do any checks and leaves it to the kernel, but that may not be right if there is different MINSIGSTKSZ in userspace. and if libc tries to enforce a larger MINSIGSTKSZ than linux then using AT_MINSIGSTKSZ may unexpectedly fail. it is probably best not to enforce the failure in userspace for now, but that does not seem conforming.