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 EED3FC54EBD for ; Thu, 12 Jan 2023 16:03:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DAE928514E; Thu, 12 Jan 2023 17:03:55 +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="auTXz6rg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DA2EE85023; Thu, 12 Jan 2023 17:03:53 +0100 (CET) Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2069.outbound.protection.outlook.com [40.107.103.69]) (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 1B8758514E for ; Thu, 12 Jan 2023 17:03:51 +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=C6KibhS2W9+UHowjd65/karwlLCMblEnIsOEr0HaPjzIUEa/sF9K71lv5BYCdSWj0hNU29bYPfuSLWq8a2rT19jm9129zCjiUv4j8O5Fy3Q8MfORw0jFaiiuHNNz3nXU+cH3CO0PFgu8QD3xwwCK6f2KBKy7BIBm+BTMMX6YflzrmRTv7PuSAfwDuH54eUfayBvg87sitc/fCzVqXVgQutGNuPuu19UL7rr+giqUXws9XKOmBDWaSPlBVoVEyrGot7cFxt/I04d6gLnwNnETlnAvhxogWB0JMq4Xc6Y1KmoSnTf+02HQkFUBAVC6hNbeEpF2AxTzo3/cEJ9ecEtnQw== 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=eCOh3NYL59FPE6GKfxpJAuoYND1Uh3Pr2INWJRGl02E=; b=PW2LMyk0J6afmJPeIYLBb53QBleEXEPFxQ4EDSoOdjTYFEHlIHhngYU65gmVIxT38EwArxR8RcGLW1pRJGND3LcP67WT24pwyi/s8YqZ/kcSwkS9tUtPsihMB2expHmYiyItooTlILjsQXD6yl4vXqN/3ljWlZAhqxbedQLjo0fL/wSBq3c0ZbTEf/XreUoaqOkodH70qt3v0QBJzvLwsTMU7g6nAGppkLUQGr+aZ0nf9OJ7bVtKCcpmwdHgA0pHt/A5tMvnWgoKOO7JgSM0hoOAuRwKlB5R2Z/QDCiMkxN5jvuZ0fFZ1PTTaUksPi9gsGl3Nkps6Rw0d4YxKONCcg== 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=eCOh3NYL59FPE6GKfxpJAuoYND1Uh3Pr2INWJRGl02E=; b=auTXz6rgRgjDHFE0GQlgI5xNJV1wkDyDVepxc4IvB1v4oq/yDC0F5g1CYY2gHoB0cAUgME5IRXH/6ptIq6Usf1i7ulSstlxA1FUsqzxlSQ5y1ohpGdtwihrP5S7nI7wJc7Jza6T59RuXQ5XZYPuKn1AMd0SiHWYl6gv1wc8d2k/zDlwfvN5/u6SxH6Mxzj5sJ7UPVXo+KmEOnlUtYvFAN9S2kkz3JL3S0kCgwSdX3M+w/e7PlkURouucJNWXDxZYNby+6ViztKq1cf0UmzOIHZF2uZ5YOkz4z2Pje3hN7DVW3xFjgGxwKiTTHECfG20XLW+I6RWLE1F3iJdpZmiw4w== 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 VI1PR03MB6141.eurprd03.prod.outlook.com (2603:10a6:800:13b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13; Thu, 12 Jan 2023 16:03:48 +0000 Received: from DB9PR03MB8847.eurprd03.prod.outlook.com ([fe80::6b03:ac16:24b5:9166]) by DB9PR03MB8847.eurprd03.prod.outlook.com ([fe80::6b03:ac16:24b5:9166%2]) with mapi id 15.20.5986.018; Thu, 12 Jan 2023 16:03:48 +0000 Message-ID: Date: Thu, 12 Jan 2023 11:03:44 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: u-boot: signature check for u-boot scripts Content-Language: en-US To: hs@denx.de, Simon Glass Cc: "u-boot@lists.denx.de" References: <165ab739-bec5-37bc-232e-dfd562c31e6b@seco.com> <18d5f166-2fcf-a41c-ce17-c85ecb044a00@denx.de> From: Sean Anderson In-Reply-To: <18d5f166-2fcf-a41c-ce17-c85ecb044a00@denx.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BLAPR03CA0031.namprd03.prod.outlook.com (2603:10b6:208:32d::6) To DB9PR03MB8847.eurprd03.prod.outlook.com (2603:10a6:10:3dd::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR03MB8847:EE_|VI1PR03MB6141:EE_ X-MS-Office365-Filtering-Correlation-Id: 73b005ef-f6c1-4b01-9310-08daf4b69706 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jtdE//rRSpUw1HugBpGc6wfwf51XMs6IViHM5+JFrC0wW90D0LIv25zhwpn6fQc5qvpu37wpwunI5r2UCWjzQ1IrgN0cJsBYjdyiL+bDts18y4RnY/ujBGLvqlH37Qfxe3sJjs4Ayxueflx0vfa3GPDNM0lLlo6PpFohEvMhNKlteYA/vSJWpEoOE7rGvOZOb5qjlcMHr4PVHGwLyAm4eznD5fXXLDsX7xOFMid0yrU3RIvKqwl1k8L/QdqDh6pQzMbmEMHjgxWCP3XH6xuBNadWm7puOFU5imfIJPGLw36DHc+hiwQPRw/y/hxpuvsp1g6Ur+AuKBJf9q/bc6yFXJs+Di7rnG6mgGMTzDJkbXrn4+pTpJGasroI90zukLcN2gPUlzVLuCKUUpvHMcjLuXgCZsktsi5IYEWy7Afi3/VSlJuu7ZLvlzDHghJiedBtQnyGBZbKAuEakdA+ndHGvfIIwsKisqj15rJBjRT/LG6r2w/7zPY03C6MP2idLT6OXtg9FOMM0qWlDQVxH0yX3YQP/Hy8Jqjpm86jhX0yp6Uj3sc99J5jl/Q8Z0pGrhe92Jmz7Nr8LLdlsgpRQ4CsjhFgN1SUB7eQuq8eRPErZAMxEawWhxv6ETPMcFw6mfnD/85yag1cKq0YlPJWc/t2z3BOl0RzEqt8ryG1LG7DSXMGD3734g4huwbLnBjENRRR+Fck4vzIH5kRggkx8+eyDjsV9sZ+QFFwNra4EhU7Acd+DMQSGuDjYZFEK3dZlcVYZIaAlRMPRKVZEbPh0taEqIXlQTlv01gOeYzRVky8cIw= 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)(346002)(396003)(136003)(376002)(39840400004)(366004)(451199015)(6506007)(6666004)(2906002)(36756003)(4326008)(5660300002)(53546011)(8936002)(44832011)(83380400001)(31686004)(6916009)(8676002)(38350700002)(38100700002)(6512007)(478600001)(41300700001)(6486002)(66556008)(66946007)(26005)(66476007)(52116002)(186003)(86362001)(31696002)(2616005)(316002)(43740500002)(45980500001)(139555002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Y29mVjI0SmhvYWRHaDIzamo1TXJ4MFNMUUQ4U1ovbzJIRkVXMThlZlRlYUwy?= =?utf-8?B?YmQvODZzN0VNWFBQSFNaK0gzR2JubitZVk5kc05zeWVqOWdGTHk1eTB6VWYx?= =?utf-8?B?TGhwZ0tqS0lmRXU2NmEyNW96bVp5YlJGZnRWTmY2STNveGJuUFVLL1VCYUNU?= =?utf-8?B?bVJ1N3lRSTYrTmtSVmtaQjVwNmxmNTE0TTV4UlBFM1pUUUczRUNvcWZFczEx?= =?utf-8?B?eWZnbzJCL1REU1ZpWHdKRmJ5enVLcUxnMjZKRm1HaENoN3pjMHQ0UndNdG1E?= =?utf-8?B?U0VCTWllSWFzZTVDQUgxbS9mc1E2QUhBV2FxUlpSS1NYc0hiM011TUZIVXpl?= =?utf-8?B?bHlObFo0OE5uRDQ1c1JLU1luM1ViWlRlYlFJZlRFa0RTbUJjamFTRE9RaWsw?= =?utf-8?B?bEsxbVRidDBvL3djOWt4K3RHUXJ6TFluQlJPS0ZicXJvdVJ4a2RJenlMODZW?= =?utf-8?B?c0FqS211b3NpSFo0eWNMTFJOZ1BodTJtZjVtWDBmNWhsN1NZd2VwcTJhbmQ1?= =?utf-8?B?NkltNkNtMHRqOWgwWS92VjA4Qm5FNi82NkRoa0FxWGVLTFlXNXhxUXg0ZlhB?= =?utf-8?B?T2RsMktWO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ek5CaWJGandsSHlM?= =?utf-8?B?dEJWdzR0Y2dYa1VuTlVIY3pBZmYxeGtpS01vek40SEw1c0ltSlhxYVhNRngw?= =?utf-8?B?SVZnZ2J0d1VqQzA4UHd3cjZDS0EzNUJ4SUJJbXpxNWNaNm1BUndUekJmaVYy?= =?utf-8?B?S3oxNEFXNk1QQ05VQ3NWblZlRWJDWGhwYk5iSFFvbmRGZnFzQXh2T1g5NGZV?= =?utf-8?B?aXZ4MUR5akd0UGNPQTVzZVl5SEUybkpNeUdNZFg4V1MzUmxDZVhSay9ZeWpM?= =?utf-8?B?U3FRUmorbHM5TUI5UGZyUW1kSU5UQ1QzUUtjSy90ZTM4M25WVER2d1l5bUMv?= =?utf-8?B?bktqNjBpSmVXVVdYREEzTWJCODhXbVNpcGtodFNlYTVMRVB3NHZKY3FmV0sr?= =?utf-8?B?UFhFZXUwN0Rsc2h0S3E1SDVrekZ1NmZZejErOHVrcGlqUmxmTUlUNEQxMWpB?= =?utf-8?B?K09sNnBDSFNxSWdPN0NoODlyalY2TmdCY090aElHekZBbEx2SERKUlIwNk45?= =?utf-8?B?WDV6NjR6c1FtTUVEaU94ajlmRUhtTlpOdFhYbEl1Vm9jWHhOSEVFUFRqZnVz?= =?utf-8?B?UHVjV2kvRkhyeTIzV1ZaNzl5WTlSOVNTOGtybUJ2STR6b3RDL0pKSWZtS1dZ?= =?utf-8?B?ZG1STHM2NHk2a2lKaE1pY1BOd3B5cTFRdDZGWURwOFhTenRhOFhJcDgvRGJm?= =?utf-8?B?MlE9PQ==?= X-OriginatorOrg: seco.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73b005ef-f6c1-4b01-9310-08daf4b69706 X-MS-Exchange-CrossTenant-AuthSource: DB9PR03MB8847.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2023 16:03:48.3846 (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: BSC00yksSqv/0BAF9hvoGd9oqmKHsO81tEJx0R3B8y+lZrpvvBt5YX73OjKvSXkI1ug8ApQ4ePgSoVkNy/2tdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR03MB6141 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 1/11/23 01:13, Heiko Schocher wrote: > Hello Sean, > > Thanks for your answer! > > On 10.01.23 17:27, Sean Anderson wrote: >> On 1/10/23 08:18, Heiko Schocher wrote: >>> Hello Simon, > [...] >>> While writting this email ... in [3] the line >>> >>> require = "conf" >>> >>> poped into my eyes .... and in fit_image_verify_required_sigs() there is check: >>> >>> if (!required || strcmp(required, "image")) >>> continue; >>> >>> and yes! changing in [3] >>> >>> -required = "conf"; >>> +required = "image"; >>> >>> makes sourcing the signed script working (error in case of no >>> signature or wrong signature)! ... but booting the signed fitimage >>> now breaks ... so it seems, I cannot use configuration signing with >>> images signing ? >>> >>> I tried to add two key nodes in signature node of u-boot dtb ... one with >>> require = "conf" and one with require = "image" ... but no luck... >>> >>> Also adding a configurations section to scripts its file did not helped >>> (which will not prevent the problem sourcing a not signed script) >> >> As you discovered, you must either have required = "image", in which case >> >> source : >> >> will be secure. Otherwise, you must use >> >> source \# >> >> Any other way is not secure. > > My "hack" checks a configuration signature in fitimage with script in it... > so also "secure" ... > > BTW: why we need a env variable to enable checking in cmd/source.c? > I would say, if verify fit images is enabled we always should check > signature ... but this is another question... I think it's to allow disabling things for debugging. If the variable does not exist, it defaults to verifying. > So I tried your suggestion: > > => tftp 100000 script.bin.signed;setenv verify 1;source \#100000 > Speed: 1000, full duplex > Using ethernet@24000 device > TFTP from server 192.168.3.1; our IP address is 192.168.3.40 > Filename 'script.bin.signed'. > Load address: 0x100000 > Loading: # > 233.4 KiB/s > done > Bytes transferred = 1679 (68f hex) > ## Executing script at 00000000 > Wrong image format for "source" command > => > > same for > > => source \#100000:script-1 > ## Executing script at 00000000 > Wrong image format for "source" command > => > > Which is the error message from the switch in image_source_script() > from cmd/source.c ... Right. What kind of image is your script? Do you have CONFIG_FIT (and *only* CONFIG_FIT) enabled? > (check if fitimage "is okay"): > => source 100000 > ## Executing script at 00100000 > sha256+ sha256,rsa2048:dev+ Hallo from script > => source 100000:script-1 > ## Executing script at 00100000 > sha256+ sha256,rsa2048:dev+ Hallo from script > => source 100000:script-2 > ## Executing script at 00100000 > Can't find 'script-2' FIT subimage > => > > and changing hash in fitimages signature leads to: > => mw 1001c0 0 1 > => source 100000:script-1 > ## Executing script at 00100000 > sha256+ sha256,rsa2048:dev- Hallo from script > => > > As I described ... problem "hash is detected, but script is executed", > as public key in u-boots dtb has required = "conf"; (as it is used also > for fitimage boot, where we use conf signing) > > May you have an example (u-boot.dtb, its and complete working command > for a signed fitimage script)? $ cat << EOF >> dm-verity.its /dts-v1/; / { description = "dm-verity boot parameters"; #address-cells = <1>; images { dm-verity { data = /incbin/("dm-verity.scr"); type = "script"; arch = "arm64"; compression = "none"; hash-1 { algo = "sha256"; }; }; }; configurations { default = "conf"; conf { description = "Load dm-verity boot parameters"; script = "dm-verity"; signature { algo = "sha256,rsa2048"; key-name-hint = "u-boot"; sign-images = "script"; }; }; }; }; EOF $ uboot-mkimage -EB 0x40 -f dm-verity.its dm-verity.itb $ uboot-mkimage -EB 0x40 -r -F -k /path/to/keys dm-verity.itb > The main problem is (I think) that we check for fitimages which are > used for booting kernels, a "signed configuration" and in fitimage for scripts > only "image" signatures ... and a combination of both is not possible > (except I also sign the image nodes in kernel fitimage too ... which > than leads in checking configuration signature and image signature on > boot... but may a way to go (and disabling hash check) ? Yes, which is why you need to have # in the source command to force only using configurations. IMO we should also check image-only FITs, but Simon disagrees. --Sean