From patchwork Fri Nov 20 18:05:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Peshkin X-Patchwork-Id: 1403935 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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=WcM/b0SJ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4Cd4Hz4bsvz9sSs for ; Sat, 21 Nov 2020 05:06:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 409AF82366; Fri, 20 Nov 2020 19:06:17 +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="WcM/b0SJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D5C5982384; Fri, 20 Nov 2020 19:06:13 +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-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (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 ECD208232D for ; Fri, 20 Nov 2020 19:06:04 +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-x535.google.com with SMTP id 62so7927286pgg.12 for ; Fri, 20 Nov 2020 10:06:04 -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=2uTlXKGkhmwK/Maw/nAQNeRMduBKnMCBZ9/P9jmWv8M=; b=WcM/b0SJCrk95ECwyy6z3mqwvOKS/SeZcvcEgAsY4S6emm7ScYNC8fy++1txrRAKgG IazSy6XYlbHWihAf4GRqkMj055A9vbKODZsVXYsYyEU7ETyLMvX9LRQXpBOU+QSYN1di eDlva8M+PSedzwgrW8w5DFzQv71kKThgDH4Ms= 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=2uTlXKGkhmwK/Maw/nAQNeRMduBKnMCBZ9/P9jmWv8M=; b=rgMSmtjZOKtVyYNBZkK5XVDgpgn/b0domwHNHhnFRIM/AUm+HLKzgkX+Lm1A2nKpmJ mwkk5HSgfua7rn7LWATrzKEVPj77iq57rk63s6dTW18Ysbf5pvTd5MZYluqf7CAGPEUm EE2SNCbsFWL6SOJdMqQjl84LqPZV28LhVGYutdDxc92v7w9kf/aRi2yx61Uw0WseEDCN AKBVlkSgK6f+mwVZoCLJPJPcaAWkcYBjobBaYbxAab0d/jZZXnjx/CuX+Qd78Qg28CGg S5XACncD6wmYEj9+73cZNXEQ3Mt4+dW1+n5MEMOFd2HI8fL9Hq0yNEGzikiLdacBzSgE eYoA== X-Gm-Message-State: AOAM532pyYYRDNx+BHuVTJBrcwDKDOErXrNoJmd2Bc5BvQaAyXLtJ4iG G8PUloWP0QouEq2vN/Ze4H4sd2hil2NQRRu2i8JDjTHHasHFnfyEuqWAySQyIQ6yzOmwtQEvkUc r5csRRYLR6VuoVDj82zioFsbbyJcgmVDJm5j2I14IGnD+eC+iBj9A10OS435qUkiQDTQtDSoe X-Google-Smtp-Source: ABdhPJyRocmNpUSXa6ExZ3L/svEeFH8tn4os5/SBNtmAr5C4jwCERtZ7alEL47+YIw/3kSLpd87wow== X-Received: by 2002:a17:90a:f211:: with SMTP id bs17mr11786172pjb.144.1605895551888; Fri, 20 Nov 2020 10:05:51 -0800 (PST) Received: from xl-irv-13.lvn.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id i16sm4385234pfr.183.2020.11.20.10.05.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Nov 2020 10:05:49 -0800 (PST) From: Joel Peshkin X-Google-Original-From: Joel Peshkin To: u-boot@lists.denx.de Cc: Joel Peshkin , Simon Glass , Bin Meng , Patrick Delaunay , Heiko Schocher , trini@konsulko.com, Heinrich Schuchardt Subject: [PATCH v2] Add optional salt to AUTOBOOT_STOP_STR_SHA256 Date: Fri, 20 Nov 2020 10:05:24 -0800 Message-Id: <20201120180524.30251-1-jp933255@xl-irv-13.lvn.broadcom.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20201120014114.48895-1-jp933255@xl-irv-13.lvn.broadcom.net> References: <20201120014114.48895-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 From: Joel Peshkin 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: trini@konsulko.com Cc: Heinrich Schuchardt Cc: Joel Peshkin To: u-boot@lists.denx.de Reviewed-by: Simon Glass --- Changes for v2: - Increase MAX_DELAY_STOP_STR - Check salt size against MAX_DELAY_STOP_STR before copying - Minor cleanup --- 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..982b561 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; /*