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 2392CC4332F for ; Thu, 22 Dec 2022 23:06:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C4218542F; Fri, 23 Dec 2022 00:06:32 +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="h4XvQT6t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1398D8540D; Fri, 23 Dec 2022 00:06:31 +0100 (CET) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2085.outbound.protection.outlook.com [40.107.7.85]) (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 185E285362 for ; Fri, 23 Dec 2022 00:06:28 +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=O+6YLjYaRz5BTNQEaDJqWLU7vJAQj5bDmY7/I4ackZVQLmRhLM4AHYVVEa7BqE3HpUxlBGKOrnvjKVZQpYKV5qVJVL1l2rkDffp+fWJPLdvAy+AQ0Eg/wDWJk5l4qLDDssWhl//6g+Hfp8yMFJ73/qSgeXZcqWsi0u38BQisBjuP48WNviv0VRL89aNwO0Acl8Sg5AWPBBY7YEvHebfxIti02WpSK48iY59LGj1Rsn0Ymf1aFSLQ+z6PvbvGHUGVFxpjm7+/v91tRZ3ijNhioPAx+/5EpOfCtIfagjGt8RaQsJpc++ude3oaikvOs+L22M4qXsy/rwahXNw0iPfTxA== 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=M49LOc7egO81MmVZj2hGwSt8e9QKT1cvHtSdghgBiUk=; b=A6Z8QfYUop4jVaJMTIvRCC/EmstAPyBhO5vtof9OUtEYMpy3hCogP3s5EK9ncgGpBzl2DDI1MIFtzIOAho8B42bAZW+j94Pnyz2m9mDt7GRpXAL1LHJxxEPPPr59BJ3MbbYhsdGrPh9hQZufsfF9+5Oy0iXwuCn6tPcBim7Tvm0/Rplg3d760p3x8fq9Ywvc0B6UQJGQiZOf0yfNorJPgJV1Uj1GMldkOgl3bFqK51C9Wmtx9SQmXuvGubBbUm4rAH9u5k58z9s+Cas6UJdDgWcjU9cR0SWTkQ5Gsck9wF6aTFu+hTbhuwixpG3wsImyVyOPO8ZKULGSdfDfqeDJxQ== 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=M49LOc7egO81MmVZj2hGwSt8e9QKT1cvHtSdghgBiUk=; b=h4XvQT6txmu9K7c0zT0yVJ0bsRacCJdD0gRGz2JHinNnu7cbhO+bk7me9M0KNTp8mRhkKOwls95LT39SzaKvGZMx6kuZma9kZNlRRUT8hQvAmCMGnhz3FSWBlFFAW7KiGlUCGfzyOaEFw1So0dRvL7xrChcQuqdIrUbCw6kP+Peobx5uSIUbKsIbgi+M00mhafagP7LkmGcWzy3b4Mmv94KBd3BfmufTKJNo43WHbQwXmPje5CucQw0jq5/4d2lH0vm8QQRoy2pOO2HslywoBKOuIyjUyzwKjycvzoIis+aYReeZN8JJGnYUVTE+omMHEPgdXQLjjjTpDl2+SqySKw== 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 AS8PR03MB6904.eurprd03.prod.outlook.com (2603:10a6:20b:29c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Thu, 22 Dec 2022 23:06:25 +0000 Received: from DB9PR03MB8847.eurprd03.prod.outlook.com ([fe80::2b95:1fe4:5d8f:22fb]) by DB9PR03MB8847.eurprd03.prod.outlook.com ([fe80::2b95:1fe4:5d8f:22fb%7]) with mapi id 15.20.5944.013; Thu, 22 Dec 2022 23:06:25 +0000 Message-ID: <1624606f-dbb8-735e-2185-404cc32225bb@seco.com> Date: Thu, 22 Dec 2022 18:06:19 -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: Rasmus Villemoes , Sean Anderson , u-boot@lists.denx.de, Peng Fan References: <20221011232525.186166-1-sean.anderson@seco.com> <042dcb34-f85f-351e-1b0e-513f89005fdd@gmail.com> <27d8b624-6115-d92f-3565-723ae7cdbfbf@prevas.dk> <8e2aadf0-643e-cd8f-5bcc-dfe9c761415d@seco.com> From: Sean Anderson In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MN2PR20CA0002.namprd20.prod.outlook.com (2603:10b6:208:e8::15) To DB9PR03MB8847.eurprd03.prod.outlook.com (2603:10a6:10:3dd::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR03MB8847:EE_|AS8PR03MB6904:EE_ X-MS-Office365-Filtering-Correlation-Id: e023bba3-5f88-4c0c-8501-08dae47125f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wQU88e9+AVkkNziWCA2GFnI8c4Us3pqVw1VKv6T8Nv9XcruE2Fh12MfLXpRxJ+e3yur0P22sJO+C2FSoRX0/Lnb3Y/IVEbuCmm81sv9Ykp2Op/+dOXKMr3aeLDp7zwuQg0FDcjjdZLM1CyFObLO2IOu4g8B3nuwVa62I5zE1Sga7mmJEAWn+tQ/Rfr8k9gwVORuWzyy2DGbYXmQW6mrmCkkpnyn8/R4T4UKTPJkV/B35DR1GvyxGzI6pcZneLc+0zP5h4z+4/I7xyBsbUDBRAfn0oI+mJyGL9KTOtQQCCQ0N1aDqrAyzk8Qh7jS8Xiqr/7YdNtg0yuYfCN7RdQ+C5zWTHa8m9LXbxQPb73lVMlIMK5XlGuDnLi0meI8dM1PPA+4lS+HJCCxHq+OT8mlrSi/An+Q9XAJsMcgoRqUzdMT9twQAYQEMXsCpQUdgPBE5reOoRKBGrbU7OudwoOhyiMliLzDeXX++NTs2vRNeiZHjVDMqiWXI6rSQzeiJgtdOZc2rroySk0EslB11J9mOKc45IZ0uRvgPgGfh/ilcPgp7inRrORzwhIH7SpOxnQTNZG9XijG6m7pWJbwPsBmzx8cjcO7iiGMTHcG0CmoNXzFtCLCr7KV45zb8t9rZjr6JuCFAkJSoNzVuZ2FNCVKjeITPfzKTNs3N5VR43gxwQH79G++DVpwneKJTxFHWDXao83HV6q0P7FAZHT6UdJ2YQcTnggfFgRxBiqQ/GTunYjpzAYpwPVNFkdL6UC9kc+WUS5AQvcsrY9Cl8iTqM9zVod1eJvK/dFKWKNegnno6Uww= 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)(366004)(39850400004)(376002)(346002)(136003)(396003)(451199015)(6486002)(478600001)(36756003)(5660300002)(53546011)(31696002)(6506007)(86362001)(26005)(316002)(6916009)(6512007)(83380400001)(54906003)(186003)(966005)(44832011)(52116002)(31686004)(66476007)(2906002)(66556008)(6666004)(4326008)(15650500001)(8676002)(41300700001)(2616005)(66946007)(38100700002)(8936002)(38350700002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ZlFKVVd5UHV1OEViTTRMQ2p4YlNjZXJjU01ZQjF1MEFHMkFKdjZRYU84M0ZS?= =?utf-8?B?VFJTR3RnVytGR1JLVTBzWTlkV3dJN29XTlE2Z3hVN2s1SDhrbzlkSmtaQnFX?= =?utf-8?B?a3VXUnFlTHh5TjNka0lFRDJKZGhKZ2lhU1kySUNyY0duVmZhTzFTczVPWGVl?= =?utf-8?B?SnZleVpTT1ZwcWtNTUFPdjFaTlJJNWxYblJHSmhIWEpKK2laejZyWTBJY2RE?= =?utf-8?B?bGh2NldZbTMvMmIvWWxCdW5kNGJPcmxERUZaWE5HUE9xb0h3eVEyTkpudkp3?= =?utf-8?B?Nm80ZXJiSzFXNC92N2VPemhCT1d5cXZIUjFTV3JQdG9ROFhuVm5MaDhlQSt5?= =?utf-8?B?Rk14TzFPTnR6bUlDb3dkWnZnSmRYczJqNFV4WXVSbFZDWkgxVStzazFBb0ph?= =?utf-8?B?eUdEY2kwMTZpU0dGRHlLaFY3VGg1WlVBV3pBMUl6OCtNbUVzZDNiUEU3U3Bh?= =?utf-8?B?dkxwRUxLOGZJRmNaTUEyVlBWR2gxR0l4cmcrVGlVdHpwN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TlRU3daanhSVDBYQS9MY1ArVXlxS3Bn?= =?utf-8?B?R0F3ak5TMjlNWG53akVHQit5K1BSdHhTN0JMZm94OFp6d2VGV0xnZ3lPaGNZ?= =?utf-8?B?ZXhlZkxhckpRSWoyVlZCVWk5bmdyR29KR0JRSFh6VnRYanY5UE1lcXgyVi9Y?= =?utf-8?B?c29UT3MxRHVvRGVpYmxEamRrTmpSSjhBVExBdHhxQms4dVhtR0tlUzlPd1Rx?= =?utf-8?B?WmFIS1VGU1VWcG9EMUlWRXNzKzh6UzUrakdLNUFmYzA3cDVwMDdjMFc5VjlV?= =?utf-8?B?M05ucHgvSEVwTkF1N3lic3Z6MC9NSFhEZVBsK0w0UTVXQkpVY2d4OU5ad0Fp?= =?utf-8?B?TWpaQ1lYSzQ1c3B3NkFDcnN3ay9uM0FvUy9sZWlZaFFzRTBDR2dnYjF6VlJl?= =?utf-8?B?T052ZUZhREJkUzR5VjNUZ09nS1NBcm8yZXMySHY1d1QrVHNqTERsOW5RN3ZQ?= =?utf-8?B?bkhLUVptcHAzMUd3VzljYjEyajJ0ZmhpYmxkaWxnamtxNkdPU3l5QXU2SENF?= =?utf-8?B?dDhva1g4RllKdzAyWjlMMXBpYVNqR25mc2U3aitLWFplc0hqY01wNHpVNGYw?= =?utf-8?B?b0NGTklJMU1FZmhZYVI3QWVuOWcwcWw1K3NuWmRRa1JRZ1lZbGZiN3ZtSnk3?= =?utf-8?B?UFBvR0w5ZW0yTWk3ZXhZbTZocVJWcU5MYUFQanJUMjlQVXVCT2g0RmZoQ2hD?= =?utf-8?B?OW1ZalNvTnQ3M3RCSVFBbWZkc042aG5ib2FlY1RjYkZ1TDQ2dkpMWHducW9u?= =?utf-8?B?ZkE9PQ==?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: e023bba3-5f88-4c0c-8501-08dae47125f2 X-MS-Exchange-CrossTenant-AuthSource: DB9PR03MB8847.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Dec 2022 23:06:25.5311 (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: u+xAAia3asph5Amn7wo8ywjaJTORnQySZOHxX9bc3uF2ujwGa31tvwYjpP+ED9I55NmosdNf5mYboB9amkXETw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB6904 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 11/18/22 15:50, Simon Glass wrote: > Hi Sean, > > On Thu, 13 Oct 2022 at 09:41, Sean Anderson wrote: >> >> >> >> On 10/13/22 3:14 AM, Rasmus Villemoes wrote: >> > 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? >> >> No. I didn't convert source because it also checks to ensure that the >> image type is correct, which fit_get_data_node doesn't check. However, >> it still uses the image name to determine the data to source, which has >> all the problems as discussed above. >> >> I think to do this right we would need either >> >> - A version of fit_image_verify which treats required = "config" as >> required = "image". This could be used for cases where the caller >> doesn't verify a config (such as in cases when the user specifies an >> image directly). > > Without config verification we are subject to mix-and-match attacks. We already have several functions which just load data from one image (e.g. firmware). There is nothing to mix or match. The load address/entry point are not used, so they do not need to be protected. These functions are great candidates for forcing image verification, no config needed. --Sean >> - Add support for specifying a config node. This would be something like >> the addr#config syntax used by bootm. Of course, this doesn't address >> existing users of fit_get_data_node. > > Yes, let's do this one. > >> >> That said, if we do determine the image based on a config, we should >> definitely verify it. > > Yes > > Regards, > Simon