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 33126C46467 for ; Wed, 11 Jan 2023 06:13:48 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E17E981F28; Wed, 11 Jan 2023 07:13:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1673417626; bh=F22auKKiEUIFGD4G3DF96Plj8ybYCgwQuApX5ahx1Xk=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Reply-To:From; b=Of6O6vCHSRH5zhBk76DNPdTXckTNB1/Huqdfi5XXSoy53vjz/vnPV7edV8BR+6QtE p1r4bM0PkUylbBvdN+1jqG0ey5BqDg7cBjvddQedEuGizIVls8czMDpYnDQ5KXWXYV A0qMVJNBHqSNINRMaPo1cnfx0e/94Cra25YrMxJPp+CMkYMvgccj8lUGsX2RP0+MlH BCAGH5ro3PCqGe4Vb46ADB+cI3Kgi243u3z0Fj+dE9ide4NPcNQ2D1Hz4A6Lyy4h+O AM+uvzKQJdKp++QCyOmX6cEP0Jrh8JoPy8G/O9rSgsok93+VAeDzfMJH3NxnOT84QD DR3+Hmtcfnuhw== Received: from [192.168.1.107] (fibhost-66-247-38.fibernet.hu [85.66.247.38]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: hs@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 1A1C780EB7; Wed, 11 Jan 2023 07:13:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1673417623; bh=F22auKKiEUIFGD4G3DF96Plj8ybYCgwQuApX5ahx1Xk=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=GNGW+S4lzFYydNh0qK+/Zs81wg9AjLd9U6xiAoUTEK/jSqSVFJbTNG+ubwDfjsE52 YNZSQLZ50wGWrVEIP83BaBmacWIn4b6nII8Sw6Wla+vLYVqaX++XSnEdsebPnbkgfr VIJK7qxkg72pU+GFeyQI/VMVR5tY422iVfIswzcXpcfXNAxVg1Ty2KQ0N4Qm67sh7c P7NUC9/DVqYnhre+iHa9PFdrnvnlv+O6ZODaHaHAHTFBc/eYY+URSVqKqGLMFRqBzl lmi0BKOtsikokUdTiwGyqRT4sqLT2qIWpPsrCw+0Wv5vcG/spsKf6WdM5CHj2zmjUi GW/9ReSfaIjFQ== Subject: Re: u-boot: signature check for u-boot scripts To: Sean Anderson , Simon Glass Cc: "u-boot@lists.denx.de" References: <165ab739-bec5-37bc-232e-dfd562c31e6b@seco.com> From: Heiko Schocher Message-ID: <18d5f166-2fcf-a41c-ce17-c85ecb044a00@denx.de> Date: Wed, 11 Jan 2023 07:13:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <165ab739-bec5-37bc-232e-dfd562c31e6b@seco.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: , Reply-To: hs@denx.de 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 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... 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 ... (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)? 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) ? bye, Heiko -- DENX Software Engineering GmbH, Managing Director: Erika Unter HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs@denx.de