Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pUj8Q-0006sD-Q4 for mharc-grub-devel@gnu.org; Wed, 22 Feb 2023 02:01:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUj8E-0006rZ-MT for grub-devel@gnu.org; Wed, 22 Feb 2023 02:01:40 -0500 Received: from mail-am6eur05on2057.outbound.protection.outlook.com ([40.107.22.57] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUj8C-0006lx-4k for grub-devel@gnu.org; Wed, 22 Feb 2023 02:01:38 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SCneJaCFBFFljikjBNuVUsKgVqiynwz3tUOkDoccrIppb15nOjviQJv6pXsQDW+VL01oJ9niHdu0AkeiouhDsQCBzh5cUzHwESlAaWL/czqItIcuu+F3P+lVuUozawA2JBLy0getv6XV9GSKEXARPfMpuYXBw+MzJd0Vb95o+yUgmJxMu+G9SIz6Fe8wA6O9JWQgcmYcHMN+BS73rD/51ZYU+6BrGxJ3/DfE6k/E8vvCfZD7ICWe0rkXzSCBiaQWlzZC1cLqHVLuvOWtkYSRHJKgg9hOcW/4CTvEnn/DkBueIwmsvB08ITEDTe+r8UZY7jAVvZXckAZl+1XCcYWCEQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=M+jCU1JFUwQs/jIM2YRBc9Q+ccn8EI/NuHN8dZ2C3Qc=; b=XLJNczJKJOCFBQnJewMA53NbUYDsugvG09Jj1y/EfD2W8osRY5ABtd9phcDcjqXNr6nTST/hRCFSGhdkMrQBU2Pt3qxQDjL9VLyoa7FouGWa/cX1h6OlJOIaEGmnPquXPLsToccjmADuNayWWFgokwa4WHCaXbUY398MToEG16Ojk69f5m9En+fpg2faWQ7Mb11Ay/t7q+jEA58ZyQeCMzd4Nm1pmOAxoiEhHG2zoctreiT0t+RJCZsBwDkqZFp1o995ti/Zv/Ts84Tfi5Dwj4dPVN6/CKutIKfux5HM/SHOxXLSqFZ8WFe/Eu5piBrn2Ze4SV72JhX1404KQZxXlA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M+jCU1JFUwQs/jIM2YRBc9Q+ccn8EI/NuHN8dZ2C3Qc=; b=qKCghk7BzlgaMNYku7aIyMCxXeaeX1BOdvPWgQYyltEKVkX8DHwBiRFFh1v1DtT2ciRJkxM84AcTDmIjuIrjOetmmSU2RUcogS/uIZw0mj9/rn/S5NNE0yqd/gXppSlM3ngkM+EIGFB9O8zCF41kHRS7rfcu5vSgoNLJMtP7wAAoMbEQyXZPdwXDc7cz0SvS4OToV8gHQRBxskmEq4YX3NizMo9mQ+VwYYX1HjOcUwsd5OpZTtSN4SVuCADWVM6Yb4qaOFWqeZWlJnESPtTN9feD+TwhuFy53UQGU8aAzTWN940fzSD05mQnH8ZmFh60uRPZ597jI8WNXGurkh3Tbw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from DBBPR04MB6140.eurprd04.prod.outlook.com (2603:10a6:10:c7::18) by DBBPR04MB7980.eurprd04.prod.outlook.com (2603:10a6:10:1f0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.19; Wed, 22 Feb 2023 07:01:05 +0000 Received: from DBBPR04MB6140.eurprd04.prod.outlook.com ([fe80::688f:bc10:59e2:772a]) by DBBPR04MB6140.eurprd04.prod.outlook.com ([fe80::688f:bc10:59e2:772a%6]) with mapi id 15.20.6111.021; Wed, 22 Feb 2023 07:01:05 +0000 From: Gary Lin To: grub-devel@gnu.org Cc: 'Hernan Gatta ' , 'Daniel Kiper ' , shkhisti@microsoft.com, jaskaran.khurana@microsoft.com, christopher.co@microsoft.com, daniel.mihai@microsoft.com, rharwood@redhat.com, jaredz@redhat.com, development@efficientek.com, jejb@linux.ibm.com, mchang@suse.com Subject: [PATCH 01/14] protectors: Add key protectors framework Date: Wed, 22 Feb 2023 15:00:41 +0800 Message-Id: <20230222070054.5122-2-glin@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230222070054.5122-1-glin@suse.com> References: <20230222070054.5122-1-glin@suse.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: FR3P281CA0137.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:95::11) To DBBPR04MB6140.eurprd04.prod.outlook.com (2603:10a6:10:c7::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DBBPR04MB6140:EE_|DBBPR04MB7980:EE_ X-MS-Office365-Filtering-Correlation-Id: 14d14ccc-5010-4926-3324-08db14a290f4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H8ltZj9avwyf+ljGjp9njVdsymgPqs362J1UHIRbO8A4NWmhULqGly+dVCEpkk1a3gxPZBYWENYnLAGHWpikN1WcihojQHV/WBzH1QZmxfU/hU15eb25qfXbrSALjiemtW3sqpddOCbGwmfqQEiEQSeGaTC2qrXs669+0pEAKu4o6xpnewaNqlaIf3ddDjBBdw51fiIhwX3MWVBfOVxp3AOG0VXvQK/9FitM+cXpNqjYNiaEn2XwTESfsKrUl9rRsmDzzKkd3kIDsAdAkuKFRDcoYoTeCN0AbvbY4l8zYZwDmjaKtoRZEQ/fZ8m3+4/uyZOX7QN8Ggj2nRZNeKLbb9lM7TIR6enroSEsFr4M73VT1FKpMTBqAirEwsEPSq0lQM+sGyYHLtSrx17kTpW8k2KElBS5YOV1CxDYS49OXWEjFmOK2FqRA3EWYI2ZgepXDIHTa0UBi4SKqi0ODXEZYyyLh0EfvYLDxC2Z+iVLDtMffcbJfbytZLcqOnEK1E4rn2+4HCPEjzvC/faGAkvsotEwd3aAMp4MGF0EhTSLGSVUkRcVqRVmz7txMjhQPFNHJlTezBf/lxYlvxH6ejq96cMQEDZfzDHtRXF42uu5yEoTatrnRG8vfeInytsnC03+Nno6brBrICC7rlMxq/vEhhPnuMec8ugPxpKN6xIe9nrlCkFd185+t+33xqKcpbyx X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DBBPR04MB6140.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(376002)(396003)(346002)(366004)(39860400002)(136003)(451199018)(316002)(45080400002)(83380400001)(54906003)(478600001)(38100700002)(36756003)(2906002)(86362001)(66946007)(66556008)(66476007)(6916009)(4326008)(8676002)(41300700001)(8936002)(5660300002)(7416002)(2616005)(6486002)(26005)(186003)(66899018)(6512007)(6506007)(1076003)(107886003)(6666004)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?yWcgFwjcjXi7UPJYce7tqN/f8H6kqvfI0FUS5LlZmRwSo+CzRdgCxn43ufxA?= =?us-ascii?Q?2iw+qAZ3Woa0Qqbt9sGoQk6BVvcWdBeoShRefLWToXT4ePWwjGvGcEiZT09k?= =?us-ascii?Q?MopsF2VUh5o0G/qJfU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YdBOfJ5jHXF?= =?us-ascii?Q?Z8NUB67kKJiLuVMgtagFeFp1M8cCs/QOeM/rN4c9vDdwx1Pq/S7/PYcAUBC2?= =?us-ascii?Q?9CzDAjJfny6jdZAS+Sf9NflIsFG02NRS954BrgJeGIWMoNO5KHhmPJ9kw75t?= =?us-ascii?Q?n6afg1Y3S0oWPoK1VX/mVzZYEW/sWLrz7xaxQLkr8IEcqxGP6kKlGcYitruw?= =?us-ascii?Q?UUuy2bXVyE5O2I5uqwNUmzfB0XDhhhC2cvkHVXOv5CrkhI1JigXXeAI2wg6p?= =?us-ascii?Q?YqxUWJ8lxlidxd3AI+4gygQARcgavX4xOcu1RayEcHh0iN9xTtq+rI+YhoAf?= =?us-ascii?Q?QYFEuOTgTBl+3V4CdEW1iKIwVeVQplKoJtPlgHyVAA1HZbrWZ/QRPkPexi/Q?= =?us-ascii?Q?g9sO6dTJcrhk8V6z3Gd1LK2hZiSD347AIJQeLtYPuVQG43l7auHAX0e1ywNk?= =?us-ascii?Q?+bJ8Ixh6q23C370gMe7P9jBhmGUdDzWZEdcsnwQqHn9j7b/8qUzO9xRz/vQx?= =?us-ascii?Q?HMYCcNmi9mNrMmX+Rvyy50j39fAazOqn907SSQfdUtZ50vsiA4A1JqPRkD0s?= =?us-ascii?Q?QB+L7QsriHPtmdyLfPq1ikoPrQ822QuWS4Gv6LK1?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 14d14ccc-5010-4926-3324-08db14a290f4 X-MS-Exchange-CrossTenant-AuthSource: DBBPR04MB6140.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2023 07:01:05.5987 (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: SaGQk55FJUdLbppt4D/bKqN5+lZeXg3D8QfxhNm7K25gZiZmHOcF57yFFrzpQ1p+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7980 Received-SPF: pass client-ip=40.107.22.57; envelope-from=GLin@suse.com; helo=EUR05-AM6-obe.outbound.protection.outlook.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Feb 2023 07:01:40 -0000 From: Hernan Gatta A key protector encapsulates functionality to retrieve an unlocking key for a fully-encrypted disk from a specific source. A key protector module registers itself with the key protectors framework when it is loaded and unregisters when unloaded. Additionally, a key protector may accept parameters that describe how it should operate. The key protectors framework, besides offering registration and unregistration functions, also offers a one-stop routine for finding and invoking a key protector by name. If a key protector with the specified name exists and if an unlocking key is successfully retrieved by it, the function returns to the caller the retrieved key and its length. Signed-off-by: Hernan Gatta Signed-off-by: Gary Lin --- grub-core/Makefile.am | 1 + grub-core/Makefile.core.def | 1 + grub-core/kern/protectors.c | 75 +++++++++++++++++++++++++++++++++++++ include/grub/protector.h | 48 ++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 grub-core/kern/protectors.c create mode 100644 include/grub/protector.h diff --git a/grub-core/Makefile.am b/grub-core/Makefile.am index 80e7a83ed..79d17a3d2 100644 --- a/grub-core/Makefile.am +++ b/grub-core/Makefile.am @@ -90,6 +90,7 @@ endif KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h +KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/protector.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/stack_protector.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 71093a100..f301b4617 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -144,6 +144,7 @@ kernel = { common = kern/misc.c; common = kern/parser.c; common = kern/partition.c; + common = kern/protectors.c; common = kern/rescue_parser.c; common = kern/rescue_reader.c; common = kern/term.c; diff --git a/grub-core/kern/protectors.c b/grub-core/kern/protectors.c new file mode 100644 index 000000000..934f831cd --- /dev/null +++ b/grub-core/kern/protectors.c @@ -0,0 +1,75 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2022 Microsoft Corporation + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include +#include +#include + +struct grub_key_protector *grub_key_protectors = NULL; + +grub_err_t +grub_key_protector_register (struct grub_key_protector *protector) +{ + if (!protector || !protector->name || !grub_strlen(protector->name)) + return GRUB_ERR_BAD_ARGUMENT; + + if (grub_key_protectors && + grub_named_list_find (GRUB_AS_NAMED_LIST (grub_key_protectors), + protector->name)) + return GRUB_ERR_BAD_ARGUMENT; + + grub_list_push (GRUB_AS_LIST_P (&grub_key_protectors), + GRUB_AS_LIST (protector)); + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_key_protector_unregister (struct grub_key_protector *protector) +{ + if (!protector) + return GRUB_ERR_BAD_ARGUMENT; + + grub_list_remove (GRUB_AS_LIST (protector)); + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_key_protector_recover_key (const char *protector, grub_uint8_t **key, + grub_size_t *key_size) +{ + struct grub_key_protector *kp = NULL; + + if (!grub_key_protectors) + return GRUB_ERR_OUT_OF_RANGE; + + if (!protector || !grub_strlen (protector)) + return GRUB_ERR_BAD_ARGUMENT; + + kp = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_key_protectors), + protector); + if (!kp) + return grub_error (GRUB_ERR_OUT_OF_RANGE, + N_("A key protector with name '%s' could not be found. " + "Is the name spelled correctly and is the " + "corresponding module loaded?"), protector); + + return kp->recover_key (key, key_size); +} diff --git a/include/grub/protector.h b/include/grub/protector.h new file mode 100644 index 000000000..3d9f69bce --- /dev/null +++ b/include/grub/protector.h @@ -0,0 +1,48 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2022 Microsoft Corporation + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_PROTECTOR_HEADER +#define GRUB_PROTECTOR_HEADER 1 + +#include +#include + +struct grub_key_protector +{ + struct grub_key_protector *next; + struct grub_key_protector **prev; + + const char *name; + + grub_err_t (*recover_key) (grub_uint8_t **key, grub_size_t *key_size); +}; + +extern struct grub_key_protector *EXPORT_VAR (grub_key_protectors); + +grub_err_t +EXPORT_FUNC (grub_key_protector_register) (struct grub_key_protector *protector); + +grub_err_t +EXPORT_FUNC (grub_key_protector_unregister) (struct grub_key_protector *protector); + +grub_err_t +EXPORT_FUNC (grub_key_protector_recover_key) (const char *protector, + grub_uint8_t **key, + grub_size_t *key_size); + +#endif /* ! GRUB_PROTECTOR_HEADER */ -- 2.35.3