From patchwork Mon Sep 28 00:46:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1372209 X-Patchwork-Delegate: bmeng.cn@gmail.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=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=knXEKmQX; 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 4C03l10Xbdz9sSs for ; Mon, 28 Sep 2020 10:47:24 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B539682355; Mon, 28 Sep 2020 02:46:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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=chromium.org header.i=@chromium.org header.b="knXEKmQX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9AA9382358; Mon, 28 Sep 2020 02:46:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) (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 0834082332 for ; Mon, 28 Sep 2020 02:46:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x342.google.com with SMTP id y5so8043201otg.5 for ; Sun, 27 Sep 2020 17:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZbE5Q/6IhGHsoOF2SO13Hda/CzCCoy8eJFXQjyZbER8=; b=knXEKmQXSt60ziwMACN3oHvP3yi7PZUhpF5VoVqdiCiBF72aGhmdS3tkhchgIdw5DY SiEeauzjExWLb0kbGshcr6RmlJOWPceQCTtoWa0RdWN5pgBMTysZFvVjWZLFbcIksiF/ W6PF2V39wIDUFIV4N4uoJXQoytTGEsHuM6l+8= 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:mime-version:content-transfer-encoding; bh=ZbE5Q/6IhGHsoOF2SO13Hda/CzCCoy8eJFXQjyZbER8=; b=l6YePUMh96Xkcv4HPZVxJIEsuw3GuA1p9AWLh+ECpxbkF7X8klVJQQG0dznTC6P0zR 1GfvNTibUgX3Bv6UcE5m2OoU3okUBhP8qc6dZTDbwu1sxsXnn30ZzflzokAzB4pnueNR pPRr8/aK1gYn1pek7dF+D3pM5l2h7Ss5FSKJSg+S1qLgP+6ycAzucxbX7gV3sbHNjeaT LTrqpjIdVGsa9jzOfnQwSYj94URHvG0q694c4c1wOIrbmMW8lEO1CEWlsMHBlBAGfRMQ vUF2wKVDGQsQVGM/A+mA++/nxaR2jsE4udcQnNV9tU0hpUZQObDQTICqST492HWsHgI0 xONQ== X-Gm-Message-State: AOAM530076LqNDNAtXmNg03lzfUk3ZVVKwuKGxfdAoamlFXnIfpTeosE Td8+5Htmh+2AWx3lwE/9WkpUvyoVnVbxCdW6 X-Google-Smtp-Source: ABdhPJyvb4NfGoP8dzuIv8hHrSV1allzNd9K0kchzcIdgfmhmu9jkHZMuMdvl8rQBXyS9nxgRxZrvA== X-Received: by 2002:a9d:b95:: with SMTP id 21mr7493831oth.143.1601253993671; Sun, 27 Sep 2020 17:46:33 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id t7sm1790995ooq.0.2020.09.27.17.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 17:46:33 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , Wolfgang Wallner Subject: [PATCH 03/12] x86: zimage: Sanity-check the kernel version before printing it Date: Sun, 27 Sep 2020 18:46:15 -0600 Message-Id: <20200928004624.1652803-4-sjg@chromium.org> X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog In-Reply-To: <20200928004624.1652803-1-sjg@chromium.org> References: <20200928004624.1652803-1-sjg@chromium.org> MIME-Version: 1.0 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 With Chrome OS the kernel setup block is stored in a separate place from the kernel, so it is not possible to access the kernel version string. At present, garbage is printed. Add a sanity check to avoid this. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- arch/x86/lib/zimage.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c index 7418c9a5fed..d425ded596d 100644 --- a/arch/x86/lib/zimage.c +++ b/arch/x86/lib/zimage.c @@ -31,6 +31,7 @@ #include #endif #include +#include #include /* @@ -175,11 +176,19 @@ static const char *get_kernel_version(struct boot_params *params, { struct setup_header *hdr = ¶ms->hdr; int bootproto; + const char *s, *end; bootproto = get_boot_protocol(hdr, false); if (bootproto < 0x0200 || hdr->setup_sects < 15) return NULL; + /* sanity-check the kernel version in case it is missing */ + for (s = kernel_base + hdr->kernel_version + 0x200, end = s + 0x100; *s; + s++) { + if (!isprint(*s)) + return NULL; + } + return kernel_base + hdr->kernel_version + 0x200; }