From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kmScG-0003T1-La for mharc-grub-devel@gnu.org; Mon, 07 Dec 2020 21:20:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmScE-0003St-QH for grub-devel@gnu.org; Mon, 07 Dec 2020 21:20:34 -0500 Received: from de-smtp-delivery-102.mimecast.com ([51.163.158.102]:56317) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kmSc5-0000ww-52 for grub-devel@gnu.org; Mon, 07 Dec 2020 21:20:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1607394017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+dH3AUV+Fi4W2tX5OCnCldhf75Tp67fPs9D4RdUeFHw=; b=GUYGDoZhWRnnKvc/wcEXJ14r+0oBc5mUABYxIwNLdG8LhORaFtMQ2hYAzFpbgED0+m+DsL v+S1TW5/6qWbN0aR/epP2hLgIxIzVzC/WWwOdEB3NJIeCmToZygB1lCXr15jElSpngNOwh c+Fgo4Fc7567Gsto7HTrtNMtqqUcy9M= Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2104.outbound.protection.outlook.com [104.47.18.104]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-29-AOmybvg1Mw6dsUccyZhOnA-1; Tue, 08 Dec 2020 03:20:16 +0100 X-MC-Unique: AOmybvg1Mw6dsUccyZhOnA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aiaK5HP8kTI8HsaNdRzNIr8usDkfdIE70bANiquRmUemz0i8sudT0GNz+sgYCqfpzohePzxk8npir8TMhx+tz5rkezyRVL34X7idWrC/jju6CZYv+H5cNqyQbEOY8J1iktib72UhHeypN0zzrw81708+sfX75eOYuzNIdnVwZZJoL3FEI6UdS8B0PFySw/ci1I3QGVLLI6N7L4PAo8J95fQv6DTH6aYztgZYOjes1M/EifJgQRD2VcR0B48RKwotWU/w6HMCMGWii1AyKw3IahnqaaIxdI49LebSpZbnyHcGrpY8PyWCkEzbzhDa/kWLMlN3tHEHDmuVBOy+bML2hw== 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=+dH3AUV+Fi4W2tX5OCnCldhf75Tp67fPs9D4RdUeFHw=; b=naM/4crm6/xioxfN6L15l4T6X+5q/9KoP9jeHXaE4xNXMOGk8O+AKW6lwMD2mGvbPb+5zn0jfo5iiKmA8Wf4+fxC4SfH3ePgn7lVZUiUvurFSBh1PIlhTog6cGJrrzNM4MZSydnE8hHQ6avsQHdRL+fJBuxmDsJ53s7wJuJ7sNFrDPMfzQAR4VLNf3KZJqzq2ejKi4Yj85RPXgYKOlXrm5f8pAmSwMETLKjBl4A4TWhzhpA260UZjEyIhwc83dh4fSWiGGRaFSvtLAo4acVQO67xNv+RvoGA9KMJW4Xv0/Uov44c4fnnn1UlZRIzd+C/MfWrotCyJQKZ+UE4jJ31mA== 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: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=suse.com; Received: from VI1PR04MB4991.eurprd04.prod.outlook.com (2603:10a6:803:57::28) by VI1PR0402MB3440.eurprd04.prod.outlook.com (2603:10a6:803:6::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.21; Tue, 8 Dec 2020 02:20:15 +0000 Received: from VI1PR04MB4991.eurprd04.prod.outlook.com ([fe80::3103:76b1:ed7f:8994]) by VI1PR04MB4991.eurprd04.prod.outlook.com ([fe80::3103:76b1:ed7f:8994%7]) with mapi id 15.20.3632.023; Tue, 8 Dec 2020 02:20:15 +0000 Date: Tue, 8 Dec 2020 10:20:03 +0800 From: Michael Chang To: Javier Martinez Canillas Cc: grub-devel@gnu.org, Ignat Korchagin , Peter Jones , Marco A Benatto , Leif Lindholm , Daniel Kiper Subject: Re: [PATCH 8/9] efi: Only register shim_lock verifier if shim_lock protocol is found and SB enabled Message-ID: <20201208022003.GA5427@mercury> References: <20201203150151.848077-1-javierm@redhat.com> <20201203150151.848077-9-javierm@redhat.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201203150151.848077-9-javierm@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Originating-IP: [2001:b011:30d0:3a16:e73d:ae23:13d6:2215] X-ClientProxiedBy: HK0PR03CA0120.apcprd03.prod.outlook.com (2603:1096:203:b0::36) To VI1PR04MB4991.eurprd04.prod.outlook.com (2603:10a6:803:57::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mercury (2001:b011:30d0:3a16:e73d:ae23:13d6:2215) by HK0PR03CA0120.apcprd03.prod.outlook.com (2603:1096:203:b0::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Tue, 8 Dec 2020 02:20:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 82d34589-e83d-447f-7976-08d89b1fcc4e X-MS-TrafficTypeDiagnostic: VI1PR0402MB3440: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uziWnsyoI4Wd+dDDL4fbRD6KwT6D0PLEPicRz/Ub3Ie/n7L4umRRb/gIdpW/iEPOul/Q7CP9UwmeJo4NTpaOWisPl34EpWqkLbLc5lvMkfgNBjM400TTNaxKIy2e4cQcNV9RAKmd+26Sf1WURQrTkaTeH7uF4LSyDIIWIt7fTm665+KObWBUgMFvwiFgh1f9BAUowFXU61CS6CgtkeAdvJ/+nQX3Y/Yn8Wv9vWOY4OGMck9+m304vG3lbCtOQiS/OBIFvigfEWNCWKvo8d9plUJxd6aHGiBg0F/i8LQUfNZ0PrsVfM+98rDv4cWO5gqAva+UHwYVeUSC06cp4p5crgQGuoUQrTo+ElbtbnL+aHleEI8MDLPZ5ZejoEimLr22yVnJCloQrpVQCSw3NbKdxQ== 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:(366004)(136003)(376002)(346002)(9686003)(5660300002)(6496006)(83380400001)(86362001)(33716001)(66946007)(8936002)(66556008)(508600001)(6666004)(66476007)(1076003)(55016002)(33656002)(4326008)(9576002)(16526019)(54906003)(6916009)(8676002)(52116002)(186003)(966005)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?+Ht22Jw1ujebE2HnFOg/pplGklGfQHqMIMkkXmwFLMnixH6gKhBOjp9Bo8+b?= =?us-ascii?Q?q5qfpZow3QMdWVac4cDYT+zkr8cKV4wyz/DzQZbQyi/0GsvMM889b5SH65C/?= =?us-ascii?Q?UCy+SSyCPrXz6EK/I0lonJPzPvG5X8XPjILRb+qMXhyV6/HLZz8xDRdSDIkJ?= =?us-ascii?Q?HI3rzynWUk3IGzJ5HUldPSo0vh58Ld345qRfi4efEuGckEdBAQl7TFmWrdDL?= =?us-ascii?Q?nfgKB88uTim/xTpsctARbfWg2MqbKsZiVWmZIG/xCnnULQiTf+bGvZRRnu8R?= =?us-ascii?Q?M/YSFvzbLGXhS/sbzVQDCXuYA0Sbiw78SN9Z2ep1gkCRW4nIHAcuTwUGuSGA?= =?us-ascii?Q?ZVKCIJ9X7FL3njll7DfU5MIpHmRMdetvpOAOFOIixiZIOrU/05G7CUHK1mH0?= =?us-ascii?Q?zIRY3DkANyr3X31NNwZdFtn2bCDwkrR8OwLp2CBXAmJPV+t898dVM3CqYUdx?= =?us-ascii?Q?Sz9qReb9v5kcCvfmfATzVkgqf4AEBxlRKvwDJ8ryavzKRP1a4dGr9eorhcKO?= =?us-ascii?Q?HU7Biu64azpFlkWUk9xJEnKQwrcYWgnBPaChXWZHdLTv0df5IMdWUVvYOERS?= =?us-ascii?Q?5iPZa+nSicelt4xD+ca1WoHUf9xOjlRP6QS2HSZNOWq2EQDTCnCpMEmadY9j?= =?us-ascii?Q?QooMdVPwbkLvj+M1bf53fCbrm5Gzn8PDo6YIWB66VoL18cObfsqDi3jVgmuA?= =?us-ascii?Q?qafuy8pKenRgh+jMd0LeMKIX9ZyeQMztCvjtgU7nKlkk6Kk5RLQsGQUsPcOL?= =?us-ascii?Q?xAMw06T4tBst1zOyNXx+3uWiLWqrxNkbGMlmvtzt+H2HSVOWKYqzsLTBDzNP?= =?us-ascii?Q?BZ6XBuOJKhBYnNJfjpY8FfKjOlIGk4PEM6G5tRhrRIdc5xpAZj953JT7b3yA?= =?us-ascii?Q?p36zOVQWeLgBISU9WFasWXkcpSqJiDvesW4Ue6eMSbS7TJzQrZppinbllhuD?= =?us-ascii?Q?rSGUwCyAU1P9fxf84PA7z1Y1sDPtlCVwnbENUMUDjYwEGjYm7/OlyybPnDab?= =?us-ascii?Q?droRSAAX2N0BPJw9MAqYeHDWkLUFLwN7boGosUik0LwmNXPHiIJq3UYbTrI0?= =?us-ascii?Q?M7BZn5+0?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 82d34589-e83d-447f-7976-08d89b1fcc4e X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB4991.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2020 02:20:15.1968 (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: b8yu5tVDOE7xYCL14RQub5C854ARiB/DQSinVYfmoGwka/vQ/c4WD9qOWKfYF1Qm X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3440 Received-SPF: pass client-ip=51.163.158.102; envelope-from=mchang@suse.com; helo=de-smtp-delivery-102.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: Tue, 08 Dec 2020 02:20:35 -0000 On Thu, Dec 03, 2020 at 04:01:49PM +0100, Javier Martinez Canillas wrote: > The shim_lock module registers a verifier to call shim's verify, but the > handler is registered even when the shim_lock protocol was not installed. > > This doesn't cause a NULL pointer dereference in shim_lock_write() because > the shim_lock_init() function just returns GRUB_ERR_NONE if sl isn't set. > > But in that case there's no point to even register the shim_lock verifier > since won't do anything. Additionally, it is only useful when Secure Boot > is enabled. > > Finally, don't assume that the shim_lock protocol will always be present > when the shim_lock_write() function is called, and check for it on every > call to this function. > > Reported-by: Michael Chang To complete the information here, this fixed the problem I tried to solve before, but in a more elegant way. :) https://www.mail-archive.com/grub-devel@gnu.org/msg30738.html Thank you to work on the patch. Regards, Michael > Reported-by: Peter Jones > Signed-off-by: Javier Martinez Canillas > --- > > grub-core/commands/efi/shim_lock.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) > > diff --git a/grub-core/commands/efi/shim_lock.c b/grub-core/commands/efi/shim_lock.c > index d8f52d721c3..5259b27e8fc 100644 > --- a/grub-core/commands/efi/shim_lock.c > +++ b/grub-core/commands/efi/shim_lock.c > @@ -28,7 +28,6 @@ > GRUB_MOD_LICENSE ("GPLv3+"); > > static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID; > -static grub_efi_shim_lock_protocol_t *sl; > > /* List of modules which cannot be loaded if UEFI secure boot mode is enabled. */ > static const char * const disabled_mods[] = {"iorw", "memrw", "wrmsr", NULL}; > @@ -43,9 +42,6 @@ shim_lock_init (grub_file_t io, enum grub_file_type type, > > *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION; > > - if (!sl) > - return GRUB_ERR_NONE; > - > switch (type & GRUB_FILE_TYPE_MASK) > { > case GRUB_FILE_TYPE_GRUB_MODULE: > @@ -100,6 +96,11 @@ shim_lock_init (grub_file_t io, enum grub_file_type type, > static grub_err_t > shim_lock_write (void *context __attribute__ ((unused)), void *buf, grub_size_t size) > { > + grub_efi_shim_lock_protocol_t *sl = grub_efi_locate_protocol (&shim_lock_guid, 0); > + > + if (sl == NULL) > + return grub_error (GRUB_ERR_ACCESS_DENIED, N_("shim_lock protocol not found")); > + > if (sl->verify (buf, size) != GRUB_EFI_SUCCESS) > return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad shim signature")); > > @@ -115,12 +116,13 @@ struct grub_file_verifier shim_lock = > > GRUB_MOD_INIT(shim_lock) > { > - sl = grub_efi_locate_protocol (&shim_lock_guid, 0); > - grub_verifier_register (&shim_lock); > + grub_efi_shim_lock_protocol_t *sl = grub_efi_locate_protocol (&shim_lock_guid, 0); > > - if (!sl) > + if (sl == NULL || grub_efi_get_secureboot () != GRUB_EFI_SECUREBOOT_MODE_ENABLED) > return; > > + grub_verifier_register (&shim_lock); > + > grub_dl_set_persistent (mod); > } > > -- > 2.28.0 >