From patchwork Sun Nov 22 01:18:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Peshkin X-Patchwork-Id: 1404414 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=btRsqdzn; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cdss82gDFz9s1l for ; Sun, 22 Nov 2020 12:19:46 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9CEEC821A4; Sun, 22 Nov 2020 02:19:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com 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=broadcom.com header.i=@broadcom.com header.b="btRsqdzn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D53A082591; Sun, 22 Nov 2020 02:19:33 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MIME_HEADER_CTYPE_ONLY, SPF_HELO_NONE,T_TVD_MIME_NO_HEADERS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C099881F67 for ; Sun, 22 Nov 2020 02:19:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=joel.peshkin@broadcom.com Received: by mail-pg1-x52f.google.com with SMTP id t37so10789407pga.7 for ; Sat, 21 Nov 2020 17:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xXBZp/Ii0DoIuPQtc+NRSYEKfDLMxLia6dKzIvhPpqY=; b=btRsqdznvp4Q3IFDRb+cbxbcqc2KONUeJjXKEm6iuV80uUG1YcWAprNaFG5koc5n1s T72OTygfWjIljAbT8hnMEDYPOVzVDY18pEXPOCQYpYrkh6j1KtzTASEzsCXdHk86zOIB 8mYDVHK4AcOppbbZAkl0YdMNPIwozVP6PSO70= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xXBZp/Ii0DoIuPQtc+NRSYEKfDLMxLia6dKzIvhPpqY=; b=b6DyDL+Dt5IEv8iiTEw0m67E39b4dcpeBCJ5xQUsU9Vou8KudCa9owOBvUQHlS6S5O N2reES/bj8pxBKT0aTCUP3LC0U2DoDaT6pIwDrfHMuxfOYGi6OulhK+FFuk7x7iWDyUk 0uulwGmdGamACbFZKl/agNyUEAudlAJC7ile3lZ19lW3Hdse4oRdQr0BBZ24JKlBrNm/ pTrHcfLAwBW4eLSQtWcKl6+JX6hnXCws0PC8o49k9fE4wqA31NAomn9NcG2q0l8W/J4g GN6cyKippaLy5snqpeYzEJfHJ+4lcURpTSp9kZopgFb8Vk+hAkKx+7Vph87UyXJgPKaA S/rQ== X-Gm-Message-State: AOAM5316Tlpmw8/HmK5dWCsNIGinH9WbhBMWh4UiFbBsGtzAFl4/OXLe mFzsXmSnJ0Ivm25J8Da8+3pUpil/Kat1mpr5GKflaCZoahgE8ltT9L8gacwhDzTmgBIDmOGXCI8 jy7CrYbXPO+smevPVKv+O3JSI6WYu8kVxFdNCRdTR0sb96reEQlAQFBe/N3nTxn6OgKlKrl7P X-Google-Smtp-Source: ABdhPJx0z79FFHnttT2+SL9RA5xlOIxjnLl/i/GO4DijksWU+m9JJpXdfzMrQCiNjCdDTqkho5lrFg== X-Received: by 2002:aa7:9315:0:b029:18b:6372:d43e with SMTP id 21-20020aa793150000b029018b6372d43emr19338428pfj.2.1606007966131; Sat, 21 Nov 2020 17:19:26 -0800 (PST) Received: from xl-irv-24.lvn.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id e2sm7258010pjv.10.2020.11.21.17.19.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Nov 2020 17:19:24 -0800 (PST) From: Joel Peshkin To: u-boot@lists.denx.de Cc: Joel Peshkin , Simon Glass , Bin Meng , Patrick Delaunay , Heiko Schocher , Heinrich Schuchardt Subject: [PATCH v3] Add optional salt to AUTOBOOT_STOP_STR_SHA256 Date: Sat, 21 Nov 2020 17:18:59 -0800 Message-Id: <20201122011859.105816-1-joel.peshkin@broadcom.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20201120180524.30251-1-jp933255@xl-irv-13.lvn.broadcom.net> References: <20201120180524.30251-1-jp933255@xl-irv-13.lvn.broadcom.net> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Adds an optional SALT value to AUTOBOOT_STOP_STR_SHA256. If a string followed by a ":" is prepended to the sha256, the portion to the left of the colon will be used as a salt and the password will be appended to the salt before the sha256 is computed and compared. Signed-off-by: Joel Peshkin Cc: Simon Glass Cc: Bin Meng Cc: Patrick Delaunay Cc: Heiko Schocher Cc: Heinrich Schuchardt Cc: Joel Peshkin To: u-boot@lists.denx.de Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- Changes for v2: - Increase MAX_DELAY_STOP_STR - Check salt size against MAX_DELAY_STOP_STR before copying - Minor cleanup Changes for v3: - Cleanup changing (c) to c after review feedback --- common/Kconfig.boot | 5 ++++- common/autoboot.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/Kconfig.boot b/common/Kconfig.boot index 3f6d9c1..8a98672 100644 --- a/common/Kconfig.boot +++ b/common/Kconfig.boot @@ -819,7 +819,10 @@ config AUTOBOOT_STOP_STR_SHA256 This option adds the feature to only stop the autobooting, and therefore boot into the U-Boot prompt, when the input string / password matches a values that is encypted via - a SHA256 hash and saved in the environment. + a SHA256 hash and saved in the environment variable + "bootstopkeysha256". If the value in that variable + includes a ":", the portion prior to the ":" will be treated + as a salt value. config AUTOBOOT_USE_MENUKEY bool "Allow a specify key to run a menu from the environment" diff --git a/common/autoboot.c b/common/autoboot.c index e628baf..ddb6246 100644 --- a/common/autoboot.c +++ b/common/autoboot.c @@ -25,7 +25,7 @@ DECLARE_GLOBAL_DATA_PTR; -#define MAX_DELAY_STOP_STR 32 +#define MAX_DELAY_STOP_STR 64 #ifndef DEBUG_BOOTKEYS #define DEBUG_BOOTKEYS 0 @@ -80,6 +80,7 @@ static int passwd_abort_sha256(uint64_t etime) u8 sha_env[SHA256_SUM_LEN]; u8 *sha; char *presskey; + char *c; const char *algo_name = "sha256"; u_int presskey_len = 0; int abort = 0; @@ -89,6 +90,14 @@ static int passwd_abort_sha256(uint64_t etime) if (sha_env_str == NULL) sha_env_str = AUTOBOOT_STOP_STR_SHA256; + presskey = malloc_cache_aligned(MAX_DELAY_STOP_STR); + c = strstr(sha_env_str, ":"); + if (c && (c - sha_env_str < MAX_DELAY_STOP_STR)) { + /* preload presskey with salt */ + memcpy(presskey, sha_env_str, c - sha_env_str); + presskey_len = c - sha_env_str; + sha_env_str = c + 1; + } /* * Generate the binary value from the environment hash value * so that we can compare this value with the computed hash @@ -100,7 +109,6 @@ static int passwd_abort_sha256(uint64_t etime) return 0; } - presskey = malloc_cache_aligned(MAX_DELAY_STOP_STR); sha = malloc_cache_aligned(SHA256_SUM_LEN); size = SHA256_SUM_LEN; /*