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 7D4BFC4332F for ; Thu, 13 Oct 2022 15:41:30 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D117484D2B; Thu, 13 Oct 2022 17:41:27 +0200 (CEST) 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="XZ2an96R"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F383184DAD; Thu, 13 Oct 2022 17:41:25 +0200 (CEST) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70043.outbound.protection.outlook.com [40.107.7.43]) (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 DBF7884928 for ; Thu, 13 Oct 2022 17:41:22 +0200 (CEST) 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=VcfScNmVgRGTys8utuPtbG+Z3F0oi9ewPGEuCPWrmqlv3xZTLveFlWOSHTsvGyqm/Ip/XTFJyGIBsutdTpWmKtd6zvs+mo1siX/Jr5C6WOVGp5YADOTAwqYG3gc+7jtsDo0DsvJkElN2+kknR2o9ZuV+v+3jmSx+zIh0ThnF/yQu+T0znxnrbDhY0dYqigif+x3QcWWcSEoM9yVRipwG83UF/oyaHmvAFAGqj77o3WSNw6IwQepYtsNbuxPpFcU1OxjTG5kbaKsJEDuzPdA1AsZlUh+FzM6fu8okKELMRAFqrtpPdHfv8iW2B83pnH0yB6sXMsF6wwUD3bKAqEockQ== 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=z7STN0sujJ7W0rzkBiHCtv/q42aJrqbcJvFdWhhq7GI=; b=aRG75/yQ6Cpz/QswaiZrOInB/8CeF687oIQ2xc9NfiWicXHs+Se545QYTFldJgCl/MolvzFMNoiGmITaFprLOeD4GC0T+yNh/6gVFmeVzBUPc21MzMsDjr1gYHqsQb6oHzzVFY073kMZv7ImIMT24fdyo7KgTw9Opxc+xXaU2MdLbWqs4OaxgIU1zipvmdk28wD1cQrZsFDIUkzuwpeLRv9QdauGyEh0vC3wuAF0R4dfOpN+xn+GX1VZTzhwFuLnUOOgUHo6GLpgs5ps10FcLZgeVUxKoqfzZtwTdD+HzS40R7+Cw2TYB9vfFyrai4aJZ8gRVFHDWcV1UNhfD1iIfw== 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=z7STN0sujJ7W0rzkBiHCtv/q42aJrqbcJvFdWhhq7GI=; b=XZ2an96RO1DMzr2tkenS+CtxIQ25EvLVX2OzXBVqHC2fjVwO38ueeL+QdI3Av8dbnrrbtn+cllwiIz2u7jwGJQgnmNdlDqdd2HiZ4ZpbC1j0rMuknUa9jM5HAXbwtijybSCNLAiiJ/PmIuADEoZgPZaPr4+lEtKGVXsl+WRKXLKj6SmajwOI72dQpx2MUzquQrERl16TtfcEBFe8BrgeKJJvxWnCrB0eI8CVONbXW85qT/PDciu4mFp1BWo0sN/LDh4AWBMThuJBfTivgJQ8LnQhzb7mwoDhnMG0TSc97D976aIbRpc0XhQt/04lxZIWqQFEDntMjGRnRlufR4q0Vw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=seco.com; Received: from DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) by PAVPR03MB9089.eurprd03.prod.outlook.com (2603:10a6:102:328::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Thu, 13 Oct 2022 15:41:20 +0000 Received: from DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::204a:de22:b651:f86d]) by DB7PR03MB4972.eurprd03.prod.outlook.com ([fe80::204a:de22:b651:f86d%6]) with mapi id 15.20.5709.015; Thu, 13 Oct 2022 15:41:20 +0000 From: Sean Anderson Subject: Re: [PATCH] image: fit: Fix not verifying data configuration To: Rasmus Villemoes , Sean Anderson , Simon Glass Cc: 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> Message-ID: <8e2aadf0-643e-cd8f-5bcc-dfe9c761415d@seco.com> Date: Thu, 13 Oct 2022 11:41:15 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: <27d8b624-6115-d92f-3565-723ae7cdbfbf@prevas.dk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BL1PR13CA0126.namprd13.prod.outlook.com (2603:10b6:208:2bb::11) To DB7PR03MB4972.eurprd03.prod.outlook.com (2603:10a6:10:7d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR03MB4972:EE_|PAVPR03MB9089:EE_ X-MS-Office365-Filtering-Correlation-Id: 142f1719-47ac-4004-f9e3-08daad316000 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hw/Sc7tXuxS3RQ8z0lNtdcLrGhn5JcNzOnlwoFTaIS2aK81BzVEyM7V0YLiCraS2nm1IJQ4G+mPyelaZdf+tUoCiXShaP7zxcb3FZDNvV4kWlKoUcKNSejpGxCal0C7V5alNguSmKweAtZ2nXTeAEBtR8PLkkLoHG4yqzBNCq7D7g/PkOXDCuPLWC0K14IfEaf6GFiI7QOG7qkOWu5KmZpM41QcHCJjndCwKKYR0uRw6Iu6o8ysDi/zTlk4ZMo7MUwD+UqJwWxNepvKG6H3PYoeHWLIfmAeRfZylpumV56Yz2D0MIzwjgqrcDq3biddDBhx2cDrATq0lv1EknQ7SkdC38X1fc5S6joMVFUx4rKaKX1pm+t+7EbHtynDaf6KzX4xIn6EgcBUBGjaVwVJXIjLRnFlmE3h0oG+Q/DwU1R+ay7CiQQkGrZdUzeUbNppywW3P2PpmGeJ+zxl/OTt/m1JXxTIg7ooGNecAEdtdWZW7nrKgwlSk+giUxNk6o2WUfK1uhhwSitk+51UA4YEkP2gLi8xZbWnu/c2QNY5LrmR/FVBKQMCEepNNw1fPe73FZ50bpVbGPd7LxXuiarveYktz56W2iKAAzhp9mMJ6QYqt8PZlCaZh4vx4/+KlnnNGhlppAQHCd5zgNhlHsj5717Rom42fT6h6Jfi+DagUrssljULLG9hdnKmH74o67BJKqHxo4JGwFKtxnL7iJfnzwlc2EY9pI2ZOfOttycDy1bwN9pwVEDbzeRcwQDICSQpJtwXTaHnyyGQVojOgeckJiTIYyG0Q3zV0vsL7Fg8IWev9qcvy0y8LPvT/uKYUGym91k3zJWKpTn8ZIkBmneGN2Qc+3v7axkzqoZiQZmQcfWk= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR03MB4972.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(346002)(376002)(136003)(366004)(396003)(39840400004)(451199015)(110136005)(316002)(478600001)(6666004)(966005)(6486002)(31686004)(4326008)(8676002)(66476007)(66556008)(66946007)(53546011)(6512007)(8936002)(26005)(52116002)(41300700001)(186003)(15650500001)(44832011)(5660300002)(6506007)(2906002)(2616005)(83380400001)(36756003)(38350700002)(38100700002)(86362001)(31696002)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UjdSNmpuL21QNnd3a2FmSzVsRUJqUmlSN1RLQlN0UTBLOEZsS1dpZmRRc0tR?= =?utf-8?B?SjVRdkl3OTlTTXBCdW5OODRUbW40NkI1SERqb2xQdUdWTjA3b2lTMUNTRms1?= =?utf-8?B?K1FJVTFmQjhMVGZCSnBiZmhjOUdXSVd4RjNvQ2huV2ZGWTg4bjdvd1hqSFE2?= =?utf-8?B?Zm5nT0Y0MXlTUnFHb3dWaU1kWk9hWG1pQUdRWTdDdTUveEpveVZEK29VMGFN?= =?utf-8?B?UnFSZmZCSGdTaytyYjlzQVo0WFZab1RWdE84c2xrUlQ5WENscEV1V1g4dTVL?= =?utf-8?B?dDF0TVh3S3djYVJJVER2RzNaVU45S0piSmRTcjdtMFVLNFVtV09SOXpFOHND?= =?utf-8?B?blpVN0lnMUFrbDBSanh6aGh3MnBEWldxVXhyNVI5ck5XSWV1MXUwZkh4Vlh0?= =?utf-8?B?dWtvQjl4K2VEanFUdkZNa3BLNTlCVEdERGJyUjFKM1NoZ1M1ajFrdkFTYWRH?= =?utf-8?B?S09TMGZrZUQrR1BPW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VVpOTFZJQlNWNUp0RG5LZzQyVHMrNWtYenZEaDh4Q2ZoZzVOZnJyYVZh?= =?utf-8?B?VTZZMU1yaTY0dDV2VXRiSkt6bER6bk9EbGJoNWNLSnZrTU8yQW8xMUF1QTkx?= =?utf-8?B?QUFrcThwaWQ4eGVPWThYRU5VdThDS0tBcG40bEFzZnE5RjB1WFh1eFVEbVBF?= =?utf-8?B?OHFNcWxHQ2R2ckZpeWsrUmdad0pEb3pYNVJyOFl4OUNDdUJQcU5GeWhjRTBY?= =?utf-8?B?OUxYOVVhWnVNTVQraHA3TTY0U240OTArWUlpQmtkRjFKdHVCQ2lDdnN3Qjc3?= =?utf-8?B?cGZXcXRXYW16NUhYc0NhQjNGL3QwY2t0ZFdnOEE5ZXFZQ05ZLzlyLzRiSXQ2?= =?utf-8?B?U0hpL0FPanEra0s5Si9hRWgwRHcxako0OUVJa1diZjRaRkdpai91MytLamJR?= =?utf-8?B?TTVaT3RrUHRiK3RJaFd5Mlp4N2RCSTYyZnYzTUM4UHQ3RWgyK29Nc2l2L2JR?= =?utf-8?B?TEtiNlB5MjQxc1lKSnZFQWR5TDlkTEM5NTBlYW45NWVjaEFrSG9oaEl4M2VW?= =?utf-8?B?WTNzNkVzb0xHWTNRVFp1bUZqZTRWK2htRUFxRnJjTUR1VEZLNkh0VnB2eFFt?= =?utf-8?B?Vlc2dDFpV3g5RWcyRlRqbFhrMENBUGFnYWRSczJTdXJXaEZTQW0xb2s2bGZr?= =?utf-8?B?VXROTWM1MFRHOWVwUnRDd3lDUklMdG5PNnlLNjh2OHVVK25jRis2bTNoSlhT?= =?utf-8?B?ZUJiYW95dVA5ZWxJYXZDaEwxc1d5bkhlb2U4V1JpV0ppdkNYWVZ5c0tKaTlh?= =?utf-8?B?T1E9PQ==?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 142f1719-47ac-4004-f9e3-08daad316000 X-MS-Exchange-CrossTenant-AuthSource: DB7PR03MB4972.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 15:41:20.7181 (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: PNrMM+9vUE96QwGHlEyVxAuLcihIZ1xD2ijzZk5XWQjfEWIWxJFYNUhBIfACU9no1PGRKEOTSwX/GEfkfA8LTg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR03MB9089 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/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). - 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. That said, if we do determine the image based on a config, we should definitely verify it. --Sean