Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1FBBC433FE for ; Thu, 17 Nov 2022 21:22:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5C87F851D2; Thu, 17 Nov 2022 22:22:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=seco.com header.i=@seco.com header.b="vQEkPet8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6D5DD8514D; Thu, 17 Nov 2022 22:22:41 +0100 (CET) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on20615.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1a::615]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D8DBA85135 for ; Thu, 17 Nov 2022 22:22:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=seco.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sean.anderson@seco.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fT+HVUD8LJyKiepKee1tbd0k9hmxko6VUJd7jXkyWRw7Ps7eYn4llnK6gGZNP2iXaSkxvPCsdcWkv+pvo4vqsDD4DtYogtYbmHfnQ8pOjpH7txAPFFyrNd6BfZOgWSkhIJGj5Z2cLFnFKbljRbM8YfAf6oM5tZm0M9tIloEiCnE4q9vt1hcyHdzICdN/1t20aiA5vp8c8apacEh7lsKs1x7FD9PzKUq+Jqh+W2eJ2yVUn5wXCDkhYFoftq04QHeTNweidQA8bAFaGIKIZNcSAgPiLfhu0ZWabuoozH/DW9Zva7RwbScs5eaDQaYQi81z3f8lsGwluKfkEHwGtsPH+w== 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=SkoTTMOXD+szwtSOnwH0gt+sgtELj0JjBoxIMrlSk9w=; b=ksjxnPzl3goynpgTFt0d+bTqcayh68OgLLTaZv05U+R9cjjybVw03ckNi6iTQvSBb3FEdfeiZK1x0rD9jaD+IOGsLun0jUwE0oo+ccuPOJfHEsb67klK3ZmY9dwX/djZwxYd2jFoWbMJdIdGz7F85z+xVwc+7RfhXG62VlvPioOnjy5LyKU4YUHkdUZEU9PNRwoUrPEi9rw66dDHbRMOvsUFRRt0oCqVOYzIave5Cu8BNM8piR8C4rGsUmDiwqS4h4TGewrbIOPa0gBgtI0Gpfw/APk2W5uQDJ0wUuBlVjigUxxC4llLdUsl6mO4u3VOf5itz5WMJgT3H9GVqLI7Yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=seco.com; dmarc=pass action=none header.from=seco.com; dkim=pass header.d=seco.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seco.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SkoTTMOXD+szwtSOnwH0gt+sgtELj0JjBoxIMrlSk9w=; b=vQEkPet8FjWx6QyCrQeRUekDprgFD0VhUoGpKcCyvaQlXqeG5udPbZJlZTaAHevjMphcKFdhA/HXCIe6o2YGxJPhl1cGF5CFIP1nGjzEBhbejm9YB1/bYrq5VCzUpMZ3Q1sjmxcrOX32JeBSTe3EZa1tMSEG+5KiQLrhX2PtPS7tHQ8aX7HRu+KKmK4TvN6gvXNGKydjLQJmCF7oC2dsehHXGsLM++en+YJJOG5dxyv8NDwR9agxGmJSfh8PpwTup6Mz0gBdoFhDkX67DKxyG//Ynv4wipoL77uxqFxdWOXSmNiOUL0bTP+9TaX0RwXrqXAgDijhc6+m95a8O8lmMg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB9PR03MB8847.eurprd03.prod.outlook.com (2603:10a6:10:3dd::13) by AM9PR03MB7712.eurprd03.prod.outlook.com (2603:10a6:20b:3dd::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Thu, 17 Nov 2022 21:22:37 +0000 Received: from DB9PR03MB8847.eurprd03.prod.outlook.com ([fe80::2b95:1fe4:5d8f:22fb]) by DB9PR03MB8847.eurprd03.prod.outlook.com ([fe80::2b95:1fe4:5d8f:22fb%6]) with mapi id 15.20.5813.019; Thu, 17 Nov 2022 21:22:37 +0000 Message-ID: Date: Thu, 17 Nov 2022 16:22:25 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH] image: fit: Fix not verifying data configuration Content-Language: en-US To: Simon Glass Cc: u-boot@lists.denx.de, Peng Fan References: <20221011232525.186166-1-sean.anderson@seco.com> <5f28f65f-d6b8-c85c-cef8-fca7bbf205b0@seco.com> From: Sean Anderson In-Reply-To: <5f28f65f-d6b8-c85c-cef8-fca7bbf205b0@seco.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: BY3PR05CA0036.namprd05.prod.outlook.com (2603:10b6:a03:39b::11) To DB9PR03MB8847.eurprd03.prod.outlook.com (2603:10a6:10:3dd::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR03MB8847:EE_|AM9PR03MB7712:EE_ X-MS-Office365-Filtering-Correlation-Id: 0ad1d30e-3b1a-48df-0b0d-08dac8e1d9ca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YJszdPGySY6qLOoq5EH1CgtYJt5XbmrUPAZUq81Ex0ex2rxeo+9FSkjMyoHG9e1xBVjUMVqWRGkNKaEWtrH4bE65wUPXygZNxzviN4sZ5R97pIAc8trcEX9V0Ovv5szpk2XAmfe+NiwKjVlOku8f1JZthVy6VVn49Vb07Oe+YtkIDJBGfMtyJNCgSkvIjcYk6qxcxqCyxDzV5VXOtxZmFdoaoIgHQM5U4sjhI+73vrChh8NFWMZ1z0V0xBpuVuvVDmlMoSogcZOXutS3gAuhaK8GM1tQEY8DdvMDKvjoHCOtkHSaVbRRxOF7uB4P5vYamQzZPCucofPXxxKJlDzxRa1TA5Yci3wecuQswbhoAblUMBfZdOyKYXcvSaIiIT/4gMtQIt2DPTD+5nPY/C4+0yVcAodxbZlwt80gxCa/Yc3e7XNO/rIKP/Bu24blYNJfPRZ0j+gmcH963LmhQ+RMlWwJ0vRxhCnYNcPlGvXIhUu6WAshPF8LFWw4vSEya1dbDs/skG9gL5yZCL3tYolEPE92vQLAPrn2/Xoo4ShX1KH9jy5/QnNEs+9bgmZDeaRvXfsq5dIB37/F40U6M67f6hZE5fdSksQblYjlQoIs4vyRF4SaotVy+mXFo3MtInO7pYmpTGpGI67Z7+bbAbiUWVP//QADDSsaqyJLdixa+DlpbRT0aBiMPnWlu6uLzS9RvFx3YzzA0vtaYcDvLXJ9vZYa0+dBzqAMgL+H0Wdgti/Mi8gnT6JUVRCMStg+RVcsW4IVEc6VofyqdqgcwmrrFA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR03MB8847.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(396003)(376002)(366004)(39850400004)(346002)(136003)(451199015)(478600001)(31686004)(6666004)(6486002)(41300700001)(8936002)(2616005)(66946007)(66556008)(66476007)(36756003)(8676002)(4326008)(26005)(6512007)(44832011)(5660300002)(186003)(316002)(6506007)(52116002)(6916009)(53546011)(83380400001)(2906002)(15650500001)(31696002)(86362001)(38350700002)(38100700002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?THoxdG0ybVhvR1Yzb045SFZlK0l4eHpaNFQ0TEx2dHEwSFoxSmhuYjNOYUpl?= =?utf-8?B?ZmgrMTYrSm12ZVdWRTJXVERQbDJsVFJtUGVva2xlS09IUXNnRlFMYXM2YjZH?= =?utf-8?B?UEMzMG5mR0doYmJxZkZtTUoyMnNBQWFScmVzZmdxeTc4bjFZMFdQaUYzMkpj?= =?utf-8?B?eXRWSStHZjJsYkVYNlVITk5rWWJOUFI3TUxBbXNyYUNqWnpOdExhMzBSbEpH?= =?utf-8?B?REVSeTZpcEQrK3ZGZWRCTWxmN3V3T1lvTTBvdjlDcTNxZ2VIdXJCSmJETTBU?= =?utf-8?B?eDhqYnBMSDBLSWk0SnNMWDU3M3NZRnpVemZsVEhJMW1lZXpqa1Y0NjNmVHh5?= =?utf-8?B?dFdBTXluNk1uTVc5aHFMU1RSTVkvWW9YWWhmdmZVOGRneW1MN09qVmpERFJH?= =?utf-8?B?Q3kvNmtWU0drTUs3QVVQTWlHcCtraktUemh2T0ZEdDY4NUVISkVURVAzMnVx?= =?utf-8?B?aUJKUWtOQW9nb01YU3R3Yk5BUDRjVFlGcGN0LzRBQ0FuVk9pYndmVWdMV3VO?= =?utf-8?B?YVU2aENoeG51UWE2Ny9JTEVEbk9nNmNocmhkZUZnNisxS3RGUlZNakR2b0JX?= =?utf-8?B?Y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vdnF6SU91dUFK?= =?utf-8?B?S3BvcHNqN1NmK1ZrQWJ4cGd5MWZXdStUNHRiczhTSWtlZXdySTVKakNOS1pN?= =?utf-8?B?VlRibHdjeHY1Nkd6aEpxRGxSMTJENHdQQStubjdacUtPc2FwR0V6OGZtTm1v?= =?utf-8?B?ZzJia01CRVI0TTlxdGorQThldGlkVnVQTndMRFlXc1AyNENHZm5aWXRreXRD?= =?utf-8?B?YlhKK1VBLzBYSjZDT1Raamg3WDc1Nko5WkxxTTd5dGt6U21tNjZIQTRvb21o?= =?utf-8?B?OVYvQkJ2RGtoYnNXQWNQSW16aDV6dGtYc1U3LzZiNWdLOG9CbUFpdXJKeWVY?= =?utf-8?B?TVJNYXZiYUJKbHcwRDBYRmkyd0tOdnkwYWJPeTB2OU91ak5TQ1RhUnI5QVNS?= =?utf-8?B?WjhPL2NsVjJVRXhYMmlET3RBVTBUNDJhR0U1Q1d2aUFiMUN2VUdVQWp3ajVi?= =?utf-8?B?MnJXclhSTEpoaE5pWHNmakhBUDNxdUxQQ0RvTk8wQkZZSldrRDN6U2JuQ21m?= =?utf-8?B?OUd0OTBPYW54ZGM1ZjBDblprTGw3d20ra1hXc3UySCtsRFNpZ0RZUUQrbHZS?= =?utf-8?B?YmUrK05vVXVxOXVpT3FwZXJuYWVQMjJzaktNQy9nRjkwT3NPV3JwT1YwR1pu?= =?utf-8?B?eW5McGVTZDdLbXdjQmRWU0UzRm9Cc1YyWFBta2IwOWpxM05LZEswRy9LUkhp?= =?utf-8?B?SHc9PQ==?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ad1d30e-3b1a-48df-0b0d-08dac8e1d9ca X-MS-Exchange-CrossTenant-AuthSource: DB9PR03MB8847.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2022 21:22:37.5626 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bebe97c3-6438-442e-ade3-ff17aa50e733 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fNIzOJfpKfH7zU+YIZ5JcIz1rc2M95JXTS+WFczRoDZZklYLghoYzyn6Sp5YpqC0zCkTurEsHTUL5UPZyzJe5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7712 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 10/12/22 12:28, Sean Anderson wrote: > On 10/12/22 08:59, Simon Glass wrote: >> Hi Sean, >> >> On Tue, 11 Oct 2022 at 17:25, Sean Anderson wrote: >>> >>> When reading data from a FIT image, we must verify the configuration we >>> get it from. This is because when we have a key with required = "conf", >>> the image does not need any particular signature or hash. The >>> configuration is the only required verification, so we must verify it. >>> >>> Users of fit_get_data_node are liable to load unsigned data unless the >>> user has set required = "image". Even then, they are vulnerable to >>> mix-and-match attacks. This also affects other callers of >>> fit_image_verify which don't first call fit_config_verify, such as >>> source and imxtract. I don't think there is a backwards-compatible way >>> to fix these interfaces. Fundamentally, selecting data by image when >>> images are not required to be verified is unsafe. >>> >>> Fixes: 37feaf2f727 ("image: fit: Add some helpers for getting data") >>> Signed-off-by: Sean Anderson >>> --- >>> >>>   boot/image-fit.c | 9 ++++++++- >>>   1 file changed, 8 insertions(+), 1 deletion(-) >>> >>> diff --git a/boot/image-fit.c b/boot/image-fit.c >>> index 9c04ff78a15..632fd405e29 100644 >>> --- a/boot/image-fit.c >>> +++ b/boot/image-fit.c >>> @@ -1948,7 +1948,14 @@ int fit_get_data_node(const void *fit, const char *image_uname, >>>   int fit_get_data_conf_prop(const void *fit, const char *prop_name, >>>                             const void **data, size_t *size) >>>   { >>> -       int noffset = fit_conf_get_node(fit, NULL); >>> +       int ret, noffset = fit_conf_get_node(fit, NULL); >>> + >>> +       if (noffset < 0) >>> +               return noffset; >>> + >>> +       ret = fit_config_verify(fit, noffset); >>> +       if (ret) >>> +               return ret; >>> >>>          noffset = fit_conf_get_prop_node(fit, noffset, prop_name); >>>          return fit_get_data_tail(fit, noffset, data, size); >>> -- >>> 2.35.1.1320.gc452695387.dirty >>> >> >> This is supposed to work by first verifying the configuration with >> fit_config_verify(). After that, images in that configuration can be >> freely loaded, verified by the hash that each image has. > > Well, this function was made to replaces several cases where code loaded > a FIT image from somewhere, and then wanted to get data from an image > based on the configuration. Typically they only want to extract one > image, which is the common case for e.g. loading firmware. This idea of > this function is to make the common case of "find me the image data from > the default config and verify it" easier. If you look at the existing > code which uses this function, they do not verify the configuration > first. This is mainly because the original versions of this code which I > replaced with this function did not verify the configuration either. > > So while the above process works for an integrated verification process, > like what is done by bootm, it doesn't really work for one-off loading > of image data. In particular, the requirements to make this secure > (using required = "image" for your key), are not default. When I was > trying to determine whether the source command would be OK to use to > load some configuration, I looked at it and saw that it did > fit_image_verify. I thought that was fine, but if you use required = > "config", then all that does is verify the hash. Same thing for > imxtract. Almost every instance of FIT loading outside of bootm has this > issue, which you can easily see when grepping for fit_config_verify. The > only other users are the SPL boot process, and fdt checksign. The latter > isn't even that useful, since you then need to re-parse the fit in hush > to determine the default configuration and determine the image names to > use. > > Unfortunately, it's not trivial to determine whether any existing > systems are vulnerable to this issue. If they set required = "image", > then they can use source and imxtract (and any of the firmware loading > methods) however they want. But if they don't (and there is no option to > mkimage to do this, you have to use fdtset or something), then there is > a problem. > >> So we need to make sure that first step is taken in all code paths, >> rather than adding it willy nilly. >> >> If people don't add hashes (or perhaps signature if they want to use >> more CPU time) for the images, then there is no protection. We could >> add warnings or errors to mkimage for this case? > > Yes, there probably should be a warning if you skip cryptographic hashes > on images with signed configs. But this is not really the root of the > issue. > > --Sean ping? --Sean