From patchwork Mon Jan 18 16:25:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1428236 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=NiUMDnuW; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 ozlabs.org (Postfix) with ESMTPS id 4DKHGM6wvTz9sSs for ; Tue, 19 Jan 2021 03:26:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1183388C013; Mon, 18 Jan 2021 16:26:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1183388C013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610987161; bh=UN454289J4yQ4WzBXRgiF4A340sy66+FfJ+Fy2OYPbM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NiUMDnuWapIXc6SxV26UOs0xr8ihGrgP0L0EMk0WJTO32hu1dpW5Q5jIGrFPM0YCJ GbmYeAQ9DuNKDerdWOpufEiwQ4E9ayKOjWLbTBOvAwGKIxuzfk3tCGD8xVF15jQ77J IUE+hHOY2vA0AmOslYAuflXciD8P2Cvoq52EtkNk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04hn0222.outbound.protection.outlook.com [52.100.17.222]) by sourceware.org (Postfix) with ESMTPS id DDD3C3834417 for ; Mon, 18 Jan 2021 16:25:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DDD3C3834417 Received: from AM5PR0202CA0002.eurprd02.prod.outlook.com (2603:10a6:203:69::12) by AS8PR08MB6550.eurprd08.prod.outlook.com (2603:10a6:20b:31b::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10; Mon, 18 Jan 2021 16:25:57 +0000 Received: from AM5EUR03FT019.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:69:cafe::24) by AM5PR0202CA0002.outlook.office365.com (2603:10a6:203:69::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9 via Frontend Transport; Mon, 18 Jan 2021 16:25:57 +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 AM5EUR03FT019.mail.protection.outlook.com (10.152.16.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.12 via Frontend Transport; Mon, 18 Jan 2021 16:25:56 +0000 Received: ("Tessian outbound 8418c949a3fa:v71"); Mon, 18 Jan 2021 16:25:56 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c96b1b69635cbe37 X-CR-MTA-TID: 64aa7808 Received: from 0a1eb37e297c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 50B0AFEB-1594-4F72-83EF-0804AA5F5115.1; Mon, 18 Jan 2021 16:25:18 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 0a1eb37e297c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Jan 2021 16:25:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=efL9e1QHKjKO9qnwqHWuWHN6fnPyuCk5Om5Mw6x1FU5dmEQ4olh8HA87nSaD7uMeWT6vTZXcOuNZ7AfBo3ZfjUdwbcP+0yL4Hr8AvvwCy3PM1h1VM6rYO1vAcWWnJdKEmEtiByN+YdvG+BlpLI8sJWWCdAuNcaxaoMFvNkYsnBPhi4p/owU6Vc5ceOsxokx82muu5PKKmBdGjUN+ZqbpMLMmLihwxbdFgYWXFfMVDx87OCeeHbp6Sm7RB6G2juzmK22F/sKErzrX3eQwN5dLPT94fMffh8VdlCKrWWHvkL8fBvQTJINAgQJAvoFKiVELLYkiuKLLieIUmefa61RXkw== 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=UN454289J4yQ4WzBXRgiF4A340sy66+FfJ+Fy2OYPbM=; b=eS2js+2Z7bgVT1TfTbdBUJeT0Sy2Yx+EuKXojgSWRDQ+2aVvz5ZovEZzkvfA1HgNSoznNf2XwZT4F6MSdYUct+imcc/NQOdqiPGHMKCfAuXWPx/8dCcaLa+m0LmZ0as5cHiuPUZhxE0306QzB0LFQVfFRWJklPnXW8mgZTWeD72Lteq6GpSYkfoByGD2+baCz7gF+LYcUY2YUK+bQHfHDPyLmSJQxgAoudenKErAM5nv+McT3gYNREytp5Rg3rJ9twEYuDmgmP1PoOEd4RQYYMqzZUak9wnNELoTCV/YNVhl58KV4UhZBbs6UyvZ4UpPgb8C03n862QkeGWO7u98/A== 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: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PA4PR08MB6238.eurprd08.prod.outlook.com (2603:10a6:102:e8::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.11; Mon, 18 Jan 2021 16:25:17 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f%7]) with mapi id 15.20.3763.014; Mon, 18 Jan 2021 16:25:17 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v4 07/10] Use in __libc_init_secure Date: Mon, 18 Jan 2021 16:25:05 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: SN4PR0501CA0002.namprd05.prod.outlook.com (2603:10b6:803:40::15) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.54) by SN4PR0501CA0002.namprd05.prod.outlook.com (2603:10b6:803:40::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.4 via Frontend Transport; Mon, 18 Jan 2021 16:25:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cd3668bc-eb0f-41b7-fc70-08d8bbcdbbd2 X-MS-TrafficTypeDiagnostic: PA4PR08MB6238:|AS8PR08MB6550: 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: mX2ql/XWzmV7rplgFYqDXW9l3jPv/nNA3xOlJ3+CvsgiSToVnnRgjo5Vvk1S+xbLkF9iNcBEGBUjqexpvTNUWLVvjT7iXZFl+lA1lk3rJAtXP7rnL8vjx28w+Z2Zy99OysGCW4UhxN75wMsaJJIlYe0xS3FPc/vnJ4mI099Hqn/ydlf9aMymGjQ2fBHZLWE5HwRbhAwdt2ftUsuk2wBHJqbjYXX1VSLIQdYNJcYO/gcdkvFepEYusSaaGbc9ZraneUYvnp4szbBDlWZ77xIW9LjtVV3LsnpAPDZClSzNusNNRM0tsDXxvfRTWE9d9609z5CFOKwScmbo9WU9mXq3J/xRWQJmikkhmp8YJLfmbQ/X3LL2QvNX2C7DVTaaSPMAN3E1AYh9HrafjTYLbEFrncgMOO+rB6EnMyo7f3rAO04CfUUq/yphNocX4Wq8Wp3XrPuq5Rbeqi2CUoIvq9gH4Whn/ehIfqjZMyn1MQYkSb2+0mvjyXhpDBZBG62yHhTsFGVUMnrUGVUsbdj1vReJn0VeOZHjPbppdWqN1bq82hOOzVpiCsIHMblLiPaKBM8RPmAk9dLf88B8uvBe7C+4Q/glDI1PrBnwV1YQ3sO6YRvXWxeACGBlXFUN+V83vzcvgy1vZd+SLDaStymIa+EF6Q== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(39850400004)(376002)(396003)(136003)(346002)(83380400001)(6486002)(8676002)(4326008)(69590400011)(478600001)(6666004)(52116002)(6916009)(316002)(8936002)(66476007)(66556008)(66946007)(5660300002)(86362001)(16526019)(26005)(6512007)(2906002)(186003)(6506007)(956004)(2616005)(36756003)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6v/rBo5Vp5dpp92LXx1VY3BpQtTMHcYfQPhmni26EfCPSbDO8I0nlgALJEpJsKU9Qvog63Nf/Iye0qAP55S29ttLWsrek3aet5aHvQtmoz8IjYcKDplSJS6uJoyp2iFHBM0oMAhadk3XyXCB2Z8OCHTCz4r/LrQXiulETxZ1iS38hQZ5BvCeVEJlQHRKCtkueCTSDzMDO9ySZDUgLZhWW514NCjYI+vnDWMqETMvESi0z/qcEhRcs3yUuEMCthzj/S0jq19cGVj9bFLXAnwmY845wXhO3jEValDVA2TEZmXVUJMDqCtdOxjTOi6X2d2tzcnNbENyXKJYOw5i71jKKy2/JKu3SgQiErGtXqbHF1hfrpaEvzMnaFjdsgFM/dBd/1KdBfOmQRYLOZ3aJHeNh8xsi/3omqebZBTl+RzpKVJBnlEEFCQpONVnngqY6Sp3ql+yMgCZ0b0N6EiqhpK23Eqmd4B/J2qpIEAUYKLHdCBBqSAhKDGFUrAFyWRgzkDf5ECmWdbqilIpQbLoyc/7ksazzK04HJjAFIu0jZ+OIgN6C/ml3GJI8nepDnYLkcSY3RqMb15F/AKAIoRdnxlqN199maUMjVu5RUWEigOvuPY/szXXlml0hy+dc16cmhnDk1iW41kvc9N+R/Owh8930KIOv0xghvqXB8PlkdQ2hNwmTYmdBj2tSRe/iHg8wbxTxltBx6przloRA2+yhQXKt7qet6ev13knUV5NAUSYkdZAg0BM8IOSWU14ZipD192NvqIFiOZ41P3d0z0IJRAdl1ce3c14/8IUN0Bu0tM1+IKkCZ+uGDMo7HpG/19S4Gm2xe3JU89iB+3IfryOiAU59dD5D5uarElOmXalEJSMbzEh7WZ8urQPXYuG+uopOmRFfquZ9N2Tb2Z5TVFHVYpAwUCvUTNKMXM3vlFZLONu20thxCmeg7Jym10ypJGspiDHOvEvZbPB4qp08cAtRVpVXUjuJMnd+fvIrJedmpUqDDN+TN9twX9CR5TF7zTnikpd X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6238 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 19fefb60-89db-4d42-da7a-08d8bbcda42c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rUAL0AGguqnFLzeBJj82SohZdAr2wt3NVkciAwM+i+UbzGltlIn+J+GKMAQwc5xhNGTg/gmCi887WO2YiMT8pylUxldaoLAassVvMrl0d/Cag/RzBmzGhbwx/aEmnKHQZoB2RXXEdlz1pP4R6E9typGmX3nv7wz+TM9uKy8ckdH0ayHvNbI/XEwRaKCVpHcSzWIsbkNNX5kyCJ8/mdISIFEth+NrmLYUueIggXHEvOJ1A4zlKFtG4VKNzQRz+CSZ7jhWvUDONq0R6WnQ81eRZBxn7gvQH1egu0pTHclme/g9r0WFDWzT1p0XpFqrwDyIccMe10HiHswRDJzRvOfxbrBgEIZoNdKrOWmQbZuhx7UMWSMHmjq4zZNtqQ2xQKsE+A+Sa14mJalqkAQA2aOm6Eq17OS8DEXzwfK7dWoFnsaljWjtv2Zi0I/Exv/1i4b05lKB8TwOvf7WwuJdTme5ejHHs9N3GLLRGUj5romPZNeiSteItdsxcWU3byIq7hE0kXBjNacthsXp/Fso8ReMlMn/eLk+JVXNDFyMzrMWWwiJMkvYAPAbYf4oS+fdiFZe 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)(396003)(346002)(39850400004)(376002)(136003)(46966006)(5660300002)(81166007)(8676002)(478600001)(82310400003)(6916009)(6512007)(69590400011)(2906002)(47076005)(26005)(316002)(16526019)(70586007)(36756003)(336012)(70206006)(6666004)(2616005)(8936002)(356005)(186003)(6486002)(82740400003)(44832011)(4326008)(86362001)(83380400001)(6506007)(107886003)(34010700045)(956004); DIR:OUT; SFP:1501; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2021 16:25:56.6251 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cd3668bc-eb0f-41b7-fc70-08d8bbcdbbd2 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: AM5EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6550 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: "H.J. Lu" Since __libc_init_secure is called before ARCH_SETUP_TLS, it must use "int $0x80" for system calls in i386 static PIE. Add startup_getuid, startup_geteuid, startup_getgid and startup_getegid to . Update __libc_init_secure to use them. Reviewed-by: Adhemerval Zanella --- elf/enbl-secure.c | 6 +++--- sysdeps/generic/startup.h | 26 +++++++++++++++++++++++ sysdeps/unix/sysv/linux/i386/startup.h | 29 ++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/elf/enbl-secure.c b/elf/enbl-secure.c index ffd7938605..9e47526bd3 100644 --- a/elf/enbl-secure.c +++ b/elf/enbl-secure.c @@ -23,7 +23,7 @@ #if BUILD_PIE_DEFAULT # pragma GCC visibility push(hidden) #endif -#include +#include #include /* If nonzero __libc_enable_secure is already set. */ @@ -35,6 +35,6 @@ void __libc_init_secure (void) { if (__libc_enable_secure_decided == 0) - __libc_enable_secure = (__geteuid () != __getuid () - || __getegid () != __getgid ()); + __libc_enable_secure = (startup_geteuid () != startup_getuid () + || startup_getegid () != startup_getgid ()); } diff --git a/sysdeps/generic/startup.h b/sysdeps/generic/startup.h index 56c899a65e..04f20cde47 100644 --- a/sysdeps/generic/startup.h +++ b/sysdeps/generic/startup.h @@ -19,5 +19,31 @@ /* Targets should override this file if the default definitions below will not work correctly very early before TLS is initialized. */ +#include + /* Use macro instead of inline function to avoid including . */ #define _startup_fatal(message) __libc_fatal ((message)) + +static inline uid_t +startup_getuid (void) +{ + return __getuid (); +} + +static inline uid_t +startup_geteuid (void) +{ + return __geteuid (); +} + +static inline gid_t +startup_getgid (void) +{ + return __getgid (); +} + +static inline gid_t +startup_getegid (void) +{ + return __getegid (); +} diff --git a/sysdeps/unix/sysv/linux/i386/startup.h b/sysdeps/unix/sysv/linux/i386/startup.h index 3eb4cc43a2..dee7a4f1d3 100644 --- a/sysdeps/unix/sysv/linux/i386/startup.h +++ b/sysdeps/unix/sysv/linux/i386/startup.h @@ -17,11 +17,12 @@ . */ #if BUILD_PIE_DEFAULT -# include - /* Can't use "call *%gs:SYSINFO_OFFSET" during statup in static PIE. */ # define I386_USE_SYSENTER 0 +# include +# include + __attribute__ ((__noreturn__)) static inline void _startup_fatal (const char *message __attribute__ ((unused))) @@ -31,6 +32,30 @@ _startup_fatal (const char *message __attribute__ ((unused))) ABORT_INSTRUCTION; __builtin_unreachable (); } + +static inline uid_t +startup_getuid (void) +{ + return (uid_t) INTERNAL_SYSCALL_CALL (getuid32); +} + +static inline uid_t +startup_geteuid (void) +{ + return (uid_t) INTERNAL_SYSCALL_CALL (geteuid32); +} + +static inline gid_t +startup_getgid (void) +{ + return (gid_t) INTERNAL_SYSCALL_CALL (getgid32); +} + +static inline gid_t +startup_getegid (void) +{ + return (gid_t) INTERNAL_SYSCALL_CALL (getegid32); +} #else # include_next #endif