From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76C34C07E96 for ; Thu, 8 Jul 2021 13:59:16 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E7EA66141A for ; Thu, 8 Jul 2021 13:59:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7EA66141A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=eyet-services.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8C12F831C4; Thu, 8 Jul 2021 15:58:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=eyet-services.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 49E94831BD; Thu, 8 Jul 2021 15:58:38 +0200 (CEST) Received: from eastern.birch.relay.mailchannels.net (eastern.birch.relay.mailchannels.net [23.83.209.55]) (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 5B017831B8 for ; Thu, 8 Jul 2021 15:58:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=eyet-services.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jaeckel-floss@eyet-services.de X-Sender-Id: instrampxe0y3a|x-authuser|jaeckel@eyet-services.de Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id F3C536427E3; Thu, 8 Jul 2021 13:58:30 +0000 (UTC) Received: from cpanel-004-fra.hostingww.com (100-105-161-168.trex-nlb.outbound.svc.cluster.local [100.105.161.168]) (Authenticated sender: instrampxe0y3a) by relay.mailchannels.net (Postfix) with ESMTPA id D761A642773; Thu, 8 Jul 2021 13:58:27 +0000 (UTC) X-Sender-Id: instrampxe0y3a|x-authuser|jaeckel@eyet-services.de Received: from cpanel-004-fra.hostingww.com (ec2-18-198-100-52.eu-central-1.compute.amazonaws.com [18.198.100.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.105.161.168 (trex/6.3.3); Thu, 08 Jul 2021 13:58:30 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: instrampxe0y3a|x-authuser|jaeckel@eyet-services.de X-MailChannels-Auth-Id: instrampxe0y3a X-Power-Chemical: 0ef6dc14609b7e61_1625752710644_3699173569 X-MC-Loop-Signature: 1625752710644:2210316902 X-MC-Ingress-Time: 1625752710644 Received: from hsi-kbw-109-192-186-038.hsi6.kabel-badenwuerttemberg.de ([109.192.186.38]:44982 helo=draupnir.jaeckel.lan) by cpanel-004-fra.hostingww.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1m1UXo-0006nt-Ax; Thu, 08 Jul 2021 13:58:26 +0000 From: Steffen Jaeckel To: u-boot@lists.denx.de Cc: Steffen Jaeckel , Simon Glass , Alexandru Gagniuc , Bin Meng , Da Xue , Heiko Schocher , Heinrich Schuchardt , Joel Peshkin , Klaus Heinrich Kiwi , Patrick Delaunay , "Yuezhang.Mo@sony.com" Subject: [PATCH v5 6/8] common: add AUTOBOOT_FLUSH_STDIN option Date: Thu, 8 Jul 2021 15:57:38 +0200 Message-Id: <20210708135740.3078100-7-jaeckel-floss@eyet-services.de> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210708135740.3078100-1-jaeckel-floss@eyet-services.de> References: <20210708135740.3078100-1-jaeckel-floss@eyet-services.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-OutGoing-Spam-Status: No, score=-1.0 X-AuthUser: jaeckel@eyet-services.de 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.103.2 at phobos.denx.de X-Virus-Status: Clean The key-sequence based unlock mechanisms are sensitive to junk symbols that could have been sent to stdin and are still waiting to be retrieved. Enabling this option will read all symbols off stdin before displaying the autoboot prompt (and starting to read the password from stdin). Signed-off-by: Steffen Jaeckel Reviewed-by: Simon Glass --- (no changes since v1) common/Kconfig.boot | 9 +++++++++ common/autoboot.c | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/common/Kconfig.boot b/common/Kconfig.boot index e70dcf17cb..d19bc32836 100644 --- a/common/Kconfig.boot +++ b/common/Kconfig.boot @@ -790,6 +790,15 @@ config AUTOBOOT_KEYED U-Boot automatic booting process and bring the device to the U-Boot prompt for user input. +config AUTOBOOT_FLUSH_STDIN + bool "Enable flushing stdin before starting to read the password" + depends on AUTOBOOT_KEYED && !SANDBOX + help + When this option is enabled stdin buffer will be flushed before + starting to read the password. + This can't be enabled for the sandbox as flushing stdin would + break the autoboot unit tests. + config AUTOBOOT_PROMPT string "Autoboot stop prompt" depends on AUTOBOOT_KEYED diff --git a/common/autoboot.c b/common/autoboot.c index 2564ef8a56..35ef526c42 100644 --- a/common/autoboot.c +++ b/common/autoboot.c @@ -297,6 +297,15 @@ static int passwd_abort_key(uint64_t etime) return abort; } +/** + * flush_stdin() - drops all pending characters from stdin + */ +static void flush_stdin(void) +{ + while (tstc()) + (void)getchar(); +} + /*************************************************************************** * Watch for 'delay' seconds for autoboot stop or autoboot delay string. * returns: 0 - no key string, allow autoboot 1 - got key string, abort @@ -306,6 +315,8 @@ static int abortboot_key_sequence(int bootdelay) int abort; uint64_t etime = endtick(bootdelay); + if (IS_ENABLED(CONFIG_AUTOBOOT_FLUSH_STDIN)) + flush_stdin(); # ifdef CONFIG_AUTOBOOT_PROMPT /* * CONFIG_AUTOBOOT_PROMPT includes the %d for all boards. -- 2.32.0