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 2F11CC433FE for ; Thu, 13 Oct 2022 07:14:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A06CD84E66; Thu, 13 Oct 2022 09:14:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="SPD+JLzE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A25F284E3F; Thu, 13 Oct 2022 09:14:49 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2124.outbound.protection.outlook.com [40.107.22.124]) (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 7A04784E3F for ; Thu, 13 Oct 2022 09:14:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nxTv2UlT5HrRkQwfAoSw5zgBwwYPyNprcgFsjcMK+/syGNwILDJIyUxbvN1Qi+CkSpZ5+AZATaw/lWm3wBCxlIx2VGe2P3LPaBd3AZ/fAGgtbUstva3k79dE8fqk458mSWq7RCXNVmo1mXDTIV8Hfvn6Lnr+5cIEOzXChUBSihXts0+JxSIKx+bfm3N8QSn38nFYL3FXZwllYKYFBX5FHeVrjK4nyMQ+kGUbuU7J1hLOp/bKaIeFDpb0Ia5pmaKSopKxRf+2ZY0TamB6JUETa+cqQV3gkAJ3TmhWxu0ptYurHI+h4T5HdeUohWyXOe4EEHGRZ3hFeUdvkH8lfZfelQ== 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=g4nKA4EAdKTzBz9O+YdUh4nhVVNZ00WL5pO3u4Xc0Cs=; b=ZxprWY1/J/dzkhJ/5jqCvb9ekDy6LbvjlHbY2anNowBbeRiWEVp9i3a7YarbGle1bgp0e6L4TjNfDTw5hfEHgZQLXeeJoyLrqP4n3V2QzXBtHuhTiCpzH+xSqnuabqxVKq6pCl6LP8DYIVY0cxeAaiSpPoHfvjByb15RtuKURLAIBU9kxHHo20lR+1ygKj7UQsS7722RNw2KbF0nXl1WUvw7ARZMYg/XoXPG8TlLJMUj2XiUBqdmMJ42cmqNLfcyRWHB/bCksZlv3V5GCrbMoxwR46TgnS7eHbgol4hhImGB//7AsQlsjwwZ7nUJMqE82dtlP1AKeUZDC2gdWI5X1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g4nKA4EAdKTzBz9O+YdUh4nhVVNZ00WL5pO3u4Xc0Cs=; b=SPD+JLzEhgeUHyzBqJMQftdqbx4kdV3EofY03b10LX64fwmYkWlNfC+s29BWnXZtkO0Y/6yfWJv1zVYsYwVT7zkonOA1ZAAJ+uWX9m60YhsFDGT7xL1t2QjqHEVFOag4Un8K1mvEOG9Cd+K0SC/qe0UB4fBFQIKN29LG6nHqGmk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=prevas.dk; Received: from DU0PR10MB5266.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:34a::22) by PAXPR10MB5520.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:102:23e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.19; Thu, 13 Oct 2022 07:14:44 +0000 Received: from DU0PR10MB5266.EURPRD10.PROD.OUTLOOK.COM ([fe80::dc91:193:719e:5fb0]) by DU0PR10MB5266.EURPRD10.PROD.OUTLOOK.COM ([fe80::dc91:193:719e:5fb0%8]) with mapi id 15.20.5676.044; Thu, 13 Oct 2022 07:14:44 +0000 Message-ID: <27d8b624-6115-d92f-3565-723ae7cdbfbf@prevas.dk> Date: Thu, 13 Oct 2022 09:14:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] image: fit: Fix not verifying data configuration Content-Language: en-US To: Sean Anderson , Simon Glass , Sean Anderson Cc: u-boot@lists.denx.de, Peng Fan References: <20221011232525.186166-1-sean.anderson@seco.com> <042dcb34-f85f-351e-1b0e-513f89005fdd@gmail.com> From: Rasmus Villemoes In-Reply-To: <042dcb34-f85f-351e-1b0e-513f89005fdd@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MM0P280CA0098.SWEP280.PROD.OUTLOOK.COM (2603:10a6:190:9::30) To DU0PR10MB5266.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:34a::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU0PR10MB5266:EE_|PAXPR10MB5520:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f77d490-c926-4d24-7589-08daacea9acb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4CJTaKur0i7lXPaIw/KD0W9O+AyxVls+CKECFbtH0Zw+gtslKhcbE9JOrQ48q8lT85HP8h/iYCuSUPq6h6KytFqx1DntAQphTFKaiWOSzQn4sqkUpAcbt81ObtR2F/5cAYfUMhRXUAAqqpQpW+mHpPtF+iX+zD+VPvkhksKEo69d/oCv/YK9KRaWfzs3a+jJzOIfDZew62d7E9G3PlmPtGcecRxtFcqMOsJHFotG3LMU5EJxCF2RKfzHnY8r3pxgaVsS/lDLybq65600XVbtfrxAAdJIdfyC+hmiZsk9trEGyhmPapI6mP9Z0RcmY0h9FwtnCbytadRTqZpcO4U07//3HKd+j7eUCFLJnoXi+vVOWPt5gsNhRSz+jdySRvV7c3cHlsdvrhpd6gVaQkt1B1WdbWRmf+iY7McnqYIntvCeTgZLa1luOMzOQtYC85e6Wtn13kVngtaadMQaCMISnAYNauv9+GCZyfI9aH/qV/IrzMg5Q3GtVTJAkyIFQhD/o3cDGdSNt/sfGkNPiD2txAmwnDrpmYv7tsgS1A1+AxJl4randJ08NDE3++Kll+xwar6ehHgqyh9CtW6sW+tJNbdHKEm73oehJA32Rur8HL0b3yi+5HyEcCjHhGASI2oZVeZpjOhpgbEFp9BAEt6ZKQk0xPU7CwyjCdGsA75EdR9T780c2NJNtQJScWa+mnre3ETQ+AnaYj/LJjkBFvCNrYxJ1m3rtHAH3/7isMwYOwqKeFihjYhvt5h1xRgWNVNUs43qeHP/d7e+79zSBfmr79lNRbDXW9M3m7aT+KnSAw+Prgd6xe++oB+xVdez72bvZ5DB0rPHTi0J/Hy9waVKWG0J0ypKLhpPn3+TghgDkDc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU0PR10MB5266.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230022)(346002)(136003)(376002)(396003)(366004)(39850400004)(451199015)(41300700001)(4326008)(66556008)(8676002)(66946007)(110136005)(66476007)(5660300002)(86362001)(478600001)(31696002)(186003)(316002)(36756003)(6506007)(53546011)(52116002)(15650500001)(966005)(6512007)(26005)(2616005)(83380400001)(2906002)(38350700002)(44832011)(38100700002)(31686004)(8976002)(8936002)(6486002)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RDNWdVFwYTV6NTZyRit0TGNISG9HKzRITEliWkQ5enU3WGF4dFBYREMwZWVZ?= =?utf-8?B?ajRaUENvai90K1dsWXg0NWxNOHBldTJ2RXdsdDlFWlhTMGhISkd3VEpoU2Vu?= =?utf-8?B?OVlVZ2lkSEQ0YngrN3RsVW93QnRId3NJWXRnN0NSL0FuWlREdGtHVzFpeXRN?= =?utf-8?B?S2s2VU4vMGZrNG50VXduaUxZakRSNTdwclU5L0cyT0hOSTJKV2piOFhUa09O?= =?utf-8?B?NStXWThwM2p3THFTZG1qL1VZV0NPbldnUW55Q0NNanBBbm1XR2dJL0doZjdM?= =?utf-8?B?TmYvTFNqN0VQY2ErdVI2K3FYQnBaZCtvZWRQbExJTGI2cjNnNG15UlZHM2pY?= =?utf-8?B?NEpGd1h4UjZZS0RzbCtmcnRUZ0YrVG5TQXVwVmtkaDZUTUpydlZtRUZ0YTZu?= =?utf-8?B?QVBtVzk2VHZKMkJqN1VLeEIxVkJrU2ZkZlJKNXpPK3hneWUrOXFQYXVjVEZt?= =?utf-8?B?UlFvVWxWcS9XL2lYQno2Y05SVEM3UDAwYkIxY1QyakgrdTJZRnVYbjNvbzdZ?= =?utf-8?B?VEpHanRxTXhaYzJJckhVSXJEcjhTNnBYd0xPakwxRlpRRzdzdW01VW42R21D?= =?utf-8?B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VmdOMW9YQ092d0tt?= =?utf-8?B?eXBXb1lmZTR0NUZEOXBKQ0JSNGhIV0pUbWNFNDA0Z1VXSjFsWFZ2b3hsSkhx?= =?utf-8?B?Qm9hOFhFTWhLUDBOZVNETjFZd0JCN1ZOcHozTUx3TWxiSjBTQnRiQ1kzdE5K?= =?utf-8?B?dFJWYndraW15ZmhQTkJIYUpqSUNlRTlyRk1jcFU5RDRjNlJKYkdEdDlocUtE?= =?utf-8?B?S0M1Q240R2kxbU5ZSWlmMjFLLzR6NVhHai9WOEdtWk5jS2U1cm5BRWJKai9V?= =?utf-8?B?VXhtK0JCb0g0K0c4cGRhR2FTZUp0cjhlZVIwK0RFWVZJc25IbFh4QVl4c3dP?= =?utf-8?B?WEorNWZUMlVYSTZNMnhRSGtBU0tVazkxN052NElGMlB0VW1BaXQ3bkhmSDhr?= =?utf-8?B?TEhTUGttdG0zY3pJQWlucEpNa2tGcnJzVlZRMk5yWlBPbFkwemhRdGdqZkU0?= =?utf-8?B?TmdTeUxKTWExcjJoWGRreWszRW50Mno1ZXdVYW1PYjNOQUUyZmhzcXRIdGpD?= =?utf-8?B?cUkxeHZJbUFEcWMzQWdialFmdHBMSWVGYWphN1VLR2VFK2grK0NwTTdjaVBs?= =?utf-8?B?bWdPTDg2K3dORXZoK2dqRzh6K0dGblRlU2tpZUNBUld6Q3JZaVd6V0M1Ym5W?= =?utf-8?B?SjZhblhpMkxuVkZZUXRSWC9UM0RxYUZKbzZINVRBT3d2ZXUvWnFhaWMwejJ6?= =?utf-8?B?dmc9PQ==?= X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 1f77d490-c926-4d24-7589-08daacea9acb X-MS-Exchange-CrossTenant-AuthSource: DU0PR10MB5266.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 07:14:44.7250 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VK4GHLtDLGFQAmsImhziXEaEjmmKBsnfIFmUjhYxtRl1zLDXOMqcZNGO9dq31OUtKnymyKilT7A0YK3maMORVcWnOR2yDgThvhM46pM3KfU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR10MB5520 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 12/10/2022 18.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. Yeah, so I've raised this problem with the "source" shell command previously, but never got a satisfactory answer: https://lore.kernel.org/u-boot/7d711133-d513-5bcb-52f2-a9dbaa9eeded@prevas.dk/ So does your patch now mean that it's possible to get a bootscript-wrapped-in-a-FIT-image verified, possibly by adding some dummy (or not so dummy?) "configurations" node? Can you give a complete .its showing how I can build a verifiable boot script? Rasmus