From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1l7HpJ-00071Y-Av for mharc-grub-devel@gnu.org; Wed, 03 Feb 2021 08:04:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7HpH-0006zO-Ez for grub-devel@gnu.org; Wed, 03 Feb 2021 08:04:07 -0500 Received: from de-smtp-delivery-102.mimecast.com ([62.140.7.102]:48924) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7HpE-0005ro-On for grub-devel@gnu.org; Wed, 03 Feb 2021 08:04:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1612357441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oQV3BSyj+wjAnUwH0Z/LrRMftgglJjPfSt3Z8GU4cK0=; b=Qolk8kDFmAfR9XXlFEG1DmwED0CqlrNbY+P1pvVMUM3xYz44hbDxRUWXbRFI2GhPsvRKTU ge20AKGNOXlWhL5C+Pba+7yQ1NUCVrc9tcbB4j2+2wQyIjHUyUzz4M5YfLf4IOLaPoMVfH ww7Ynw9Cuw9sKjUic8HKD+eaxsB6C7Q= Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03lp2053.outbound.protection.outlook.com [104.47.10.53]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-38-mfCRJpOvM2m1x_DGtyIrFg-1; Wed, 03 Feb 2021 14:03:59 +0100 X-MC-Unique: mfCRJpOvM2m1x_DGtyIrFg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y5Y0cqDSxfyqTijTblPSFwmwtNmV2yT0QbQnMdxP113IHTg3PAkS6oElVbVws0wrLdBVAk0obEourFYFN/Hkzqwu6YxXrRM0dfY3xJORmZw9m6JwBj3omdDiSD7AVIrSij3xaLZIaHqs/KYXYZE6cq0NPmHagnY3w/aXeMPDmRxdMDLoHWek/iBtmxBiL7szDsBi8hIXyXLwI8MHouqUwPKZ/cckS6jgd4GLqB7KZiRbYf5xqnO2gXiDgnbvdd567HG8HD2sS4atFDjX98HiHALbpJJ4XUAlIMrhHGVW4lrs+vwX2Pcf8fXFaz0oYMG4NJx1MXTt2QDuNKdJ5mr+UQ== 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=G1/0f/K3wVeam0dPnP3qrdvgj7mIFB7hEjrtvwmbw2w=; b=GZhTtiaDz+/f+2andWwsTHR3m+d5Tg0eBXo5MHxQSlZ/Hhq0P2RHIzF6xvR6dx3lga+IPrOJH9euPx0BwBR6Qt2Jvb65xM85y+pW3v9qCTjCWqBo1tjJ/sccq87CyEHXl3A0kxiA28e1KD8CkTKYkmkiQPoYSsJJFLbIkzxWA/tYu9JrWLyb2tY7o/xjaiEMQ5QWF0915zg0/UL1HMBF/V1djk9LuayC+8hYY6j2VkFOeEbzfcKOp3mA/SQh4evSmHfOgjX5oKD7910srm9k/P4Ufp3a9wgSqNdCIA3K3BU/ABH8jHCudKvmyQwHLb6mc086k3ZtQKHy/gxLcil48Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: gnu.org; dkim=none (message not signed) header.d=none;gnu.org; dmarc=none action=none header.from=suse.com; Received: from VI1PR04MB4991.eurprd04.prod.outlook.com (2603:10a6:803:57::28) by VI1PR04MB4400.eurprd04.prod.outlook.com (2603:10a6:803:67::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 13:03:58 +0000 Received: from VI1PR04MB4991.eurprd04.prod.outlook.com ([fe80::28b7:e423:c3d7:7ccf]) by VI1PR04MB4991.eurprd04.prod.outlook.com ([fe80::28b7:e423:c3d7:7ccf%6]) with mapi id 15.20.3805.019; Wed, 3 Feb 2021 13:03:58 +0000 From: Michael Chang To: grub-devel@gnu.org Subject: [PATCH] emu: fix executable stack marking Date: Wed, 3 Feb 2021 21:03:44 +0800 Message-ID: <20210203130344.14720-1-mchang@suse.com> X-Mailer: git-send-email 2.26.2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-Originating-IP: [2001:b011:30d0:3ce5:39da:cdee:51c2:926] X-ClientProxiedBy: HK2P15301CA0017.APCP153.PROD.OUTLOOK.COM (2603:1096:202:1::27) To VI1PR04MB4991.eurprd04.prod.outlook.com (2603:10a6:803:57::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mercury.nue.suse.com (2001:b011:30d0:3ce5:39da:cdee:51c2:926) by HK2P15301CA0017.APCP153.PROD.OUTLOOK.COM (2603:1096:202:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.0 via Frontend Transport; Wed, 3 Feb 2021 13:03:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 262b2b97-4dd3-4b7a-4e36-08d8c8442b14 X-MS-TrafficTypeDiagnostic: VI1PR04MB4400: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2657; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k4Fp3mrqxLQ5JpQs1abq8efX4XpppWGtEocgzWXHwnf89tsfxS3XxokQO8kz0mImYyy/DFdP75P8T4hZTJT1kbGt59Ou6it1/P0s2H+in/Gt9BWZSxbwll8A7lO9PUTutFFbvbQte2IScvs4k7NVHFLy1FtV6NgXCVSirtKOwzx1yQxZNDTmwbj86MWpFGVsXi1g12yUW4236+8i4PHxMWX9M7zrCkP26RSYDLIemMqpz5z1UetnxjzgcsCzb/extqX2um/xMyhx0b1ZO3lZNGynpJJhkJc6JSIMZtU+r9o8pWdztRTiv+1yvk7eFgKMRxO2DxDRUZghH1CFfxVfDaxhr0eQk6meRRAJ5nR1N6QNHNLre6S/gHvC0j0kiEccdPrNSvGtDVMjp/jDrraWr2l472zfZtdqHBUYPOKUQm4eJ8JP21LmnuJZjquNTMnzKcJ4/+JsaUB23Kn6F2AFbdz7IAwvHhlKzige8O7HG07twImdNJIWKloLtwsuPaHnlBSLHqIr0D/l3yRkR0OGKA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB4991.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(346002)(396003)(39860400002)(366004)(376002)(316002)(7696005)(66476007)(66556008)(6486002)(83380400001)(5660300002)(2906002)(86362001)(8676002)(2616005)(52116002)(36756003)(6916009)(8936002)(1076003)(478600001)(16526019)(186003)(6666004)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?U1Z+gvtM68uQT3ON2MFx3y+jTq0GAtazZJPfS2l9tPWEgAO0wXXODuFoE6/0?= =?us-ascii?Q?BgPTCELZXUbpupKVwYs8td/ZnMeuVeSCVK0am95DPst0/irW1m0TMytycaE0?= =?us-ascii?Q?267aubyeLw8Xe15QFELd9sZH2GGpdMVfLojjDS/jhJbXyH/mEcFwuhGBNIeL?= =?us-ascii?Q?VnHVPFR7HD9nlisooTMIhGy5E1tkDKjm52cBbGDfIKK8Iv81vk0hyzbiJeoV?= =?us-ascii?Q?6dEfQa8Uo1JeQWj1x3osai71OtUQ72x0DnLpMOOOCpKoci7TuuFSFM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MwaCfJKVMpw0JpPqxI7e0mBul+?= =?us-ascii?Q?/QoppULJYScjnRr9mWxtoxZ27BHyO8XTz1k3fvjU4qHT7vhbKoIJDRyBYzW1?= =?us-ascii?Q?XCGBr5E31nhz1lx0y5e1MAiRDYB4TsWUU+hSeflvjvcuBJQkaiVMUDeB2fjt?= =?us-ascii?Q?Iw0mOqEI3aPYgaHCe0ap03KCWif6hKDcXx++WI9G1pV2gqRGrJMlHv7AHSIl?= =?us-ascii?Q?d5oEBB04yBtQwX8psS+EHTKqDWfi?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 262b2b97-4dd3-4b7a-4e36-08d8c8442b14 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB4991.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 13:03:58.0829 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: v+S82OBDTYQqCu8HUEcPtPws6xZl/C9ZXs3dOS7EjIWe4o1dNyQZ8cs482fV91BA X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4400 Received-SPF: pass client-ip=62.140.7.102; envelope-from=mchang@suse.com; helo=de-smtp-delivery-102.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2021 13:04:07 -0000 The gcc by default assumes executable stack is required if the source object file doesn't have .note.GNU-stack section in place. If any of the source objects doesn't incorporate the GNU-stack note, the resulting program will have executable stack flag set in PT_GNU_STACK program header to instruct program loader or kernel to set up the exeutable stack when program loads to memory. Usually the .note.GNU-stack section will be generated by gcc automatically if it finds that executable stack is not required. However it doesn't take care of generating .note.GNU-stack section for those object files built from assembler sources. This leads to unnecessary risk of security of exploiting the executable stack because those assembler sources don't actually require stack to be executable to work. The grub-emu and grub-emu-lite are found to flag stack as executable revealed by execstack tool. $ mkdir -p build-emu && cd build-emu $ ../configure --with-platform=3Demu && make $ execstack -q grub-core/grub-emu grub-core/grub-emu-lite X grub-core/grub-emu X grub-core/grub-emu-lite This patch will add the missing GNU-stack note to the assembler source used by both utilities, therefore the result doesn't count on gcc default behavior and the executable stack is disabled. $ execstack -q grub-core/grub-emu grub-core/grub-emu-lite - grub-core/grub-emu - grub-core/grub-emu-lite Signed-off-by: Michael Chang --- grub-core/kern/emu/cache_s.S | 5 +++++ grub-core/lib/setjmp.S | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/grub-core/kern/emu/cache_s.S b/grub-core/kern/emu/cache_s.S index 2245cddc3..99d901ae0 100644 --- a/grub-core/kern/emu/cache_s.S +++ b/grub-core/kern/emu/cache_s.S @@ -2,6 +2,11 @@ #error "This source is only meant for grub-emu platform" #endif =20 +/* An executable stack is not required for these functions */ +#if defined (__linux__) && defined (__ELF__) +.section .note.GNU-stack,"",@progbits +#endif + #if defined(__i386__) || defined(__x86_64__) /* Nothing is necessary. */ #elif defined(__sparc__) diff --git a/grub-core/lib/setjmp.S b/grub-core/lib/setjmp.S index aa297ab0a..6128f0a9d 100644 --- a/grub-core/lib/setjmp.S +++ b/grub-core/lib/setjmp.S @@ -1,3 +1,7 @@ +/* An executable stack is not required for these functions */ +#if defined (__linux__) && defined (__ELF__) +.section .note.GNU-stack,"",@progbits +#endif #if defined(__i386__) #include "./i386/setjmp.S" #elif defined(__x86_64__) --=20 2.26.2