Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1798773pxa; Thu, 6 Aug 2020 16:40:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZ/qmBsmhVFmj0PAktzdvjv01H3wdT4i/uq88ekOyLSe0sY+WTgwTacXsbajSejHpoW911 X-Received: by 2002:a05:6402:1cb3:: with SMTP id cz19mr6110852edb.299.1596757234311; Thu, 06 Aug 2020 16:40:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596757234; cv=none; d=google.com; s=arc-20160816; b=XNNW7kixr09af1Q2Mg6FALb5eArY9t36e1rwjgbpwWJhJwFj1ePlwXd6Q0Z9d6mNUe hpVmw5P88dQPazsUUDIh9bwO7jEyptV+9FZf7KlHUwiCPA8Nh6h2PXmrKHBUliTdjd8+ sxbjm2pQVevSxbeTVNrxQXh/fAOfKT/RXJs5HQvAOnr+Sj+r5F8BOv/S+3ALfVsWdmkw h8oEYJ6+Sn6U6bd3JYgI3s0qxgO96ynBOM1fFfWJQiOU5SIKANuIhL8ahaG2BpzvcVQA WmXLxSov+p2XAEmWx8xKn2Hmi1ZwnSxzWlZXpdivF7XnuxMhOIQhWBW/EOegsnpwckYW 22vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=mRN6QvitSIvL/somoMlX60NzPXdS9FzFfalaag+UTxM=; b=U1kL24/xPPUnVFe62Smu/RTmr2bLF35Xx6Bz97S3GSzSYVV348k/CyD0MRtvROoam5 LCBSA5Wzf9G7Z/q0NrQprNcDWhtO4F5XItDoAH8xJgK+50rsflQ5/3DJJ8kvibV1wC76 AJEktBUuX+sXp8HT9bwqzUVbLZFdXLCYPA095ouJ3vOBWLX6zt1ZbNegOf6YdYD2c5kK ORALkguLzeCtja/oKsLcoJsI8C1rAu2wOyQAhxRQ2OXFi7u67ZEUX02NsfPDbNLU3P6B RvJ9uckgrjvH5lIengArGwlBP2B4LO1w5YKSmjnBpYgJUXn1BWBKTL2m/DWx8C1zWIIS qYsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=RKNOVCYP; dkim=neutral (no key) header.i=@vger.kernel.org header.s=2020e header.b=K4LXh0Sd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si5054667ejo.127.2020.08.06.16.40.11; Thu, 06 Aug 2020 16:40:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=RKNOVCYP; dkim=neutral (no key) header.i=@vger.kernel.org header.s=2020e header.b=K4LXh0Sd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726872AbgHFXjT (ORCPT + 99 others); Thu, 6 Aug 2020 19:39:19 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:60990 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726733AbgHFXjG (ORCPT ); Thu, 6 Aug 2020 19:39:06 -0400 Date: Thu, 06 Aug 2020 23:39:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1596757144; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mRN6QvitSIvL/somoMlX60NzPXdS9FzFfalaag+UTxM=; b=RKNOVCYPvKU5dgrAcJfXJpCLw6QDFJPr4TunVyd4NhVKNBz6XJ8bM0oS6ooFywRTkFZHO6 wBaTDxU3O73ZQ9Z7OaxGP0BRiYG8tuYFcNLkt+zKed7u46svRn4z7UYdURcMlK/1YcbYnG ObX84yg/34OJh9KUPAv5IpMdRGKrAa3GGPsEOR/CoSDVOeBTKZQ72wcSZ60NNiFCdE56AJ notzgDwlPx6MV05FjllQXeqquQJrUd2DTpomUc6fClv9ELqUFcyi4j0qncOidlbd1d4V9A tagDrtS3hNmHdXpcFcpnm4Mx5i/eeyefLCztQUEorZIG1UrY3XRbBLBsLRX+kA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1596757144; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mRN6QvitSIvL/somoMlX60NzPXdS9FzFfalaag+UTxM=; b=K4LXh0Sduu8HHbfoGYV1qPVQUXXTWMeY+kN0WHJpn0oLPUFJOdBsaVExwpvnA9IzmjoaeP fQR8FVpHyX3H/lAQ== From: "tip-bot2 for Arvind Sankar" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/kaslr] x86/kaslr: Make command line handling safer Cc: Arvind Sankar , Ingo Molnar , Kees Cook , x86 , LKML In-Reply-To: <20200727230801.3468620-2-nivedita@alum.mit.edu> References: <20200727230801.3468620-2-nivedita@alum.mit.edu> MIME-Version: 1.0 Message-ID: <159675714346.3192.17629244064214120082.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/kaslr branch of tip: Commit-ID: 709709ac6410f4a14ded158a4b23b979e33e10fb Gitweb: https://git.kernel.org/tip/709709ac6410f4a14ded158a4b23b979e33e10fb Author: Arvind Sankar AuthorDate: Mon, 27 Jul 2020 19:07:54 -04:00 Committer: Ingo Molnar CommitterDate: Fri, 31 Jul 2020 11:07:51 +02:00 x86/kaslr: Make command line handling safer Handle the possibility that the command line is NULL. Replace open-coded strlen with a function call. Signed-off-by: Arvind Sankar Signed-off-by: Ingo Molnar Reviewed-by: Kees Cook Link: https://lore.kernel.org/r/20200727230801.3468620-2-nivedita@alum.mit.edu --- arch/x86/boot/compressed/kaslr.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index d7408af..e0f69f3 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -268,15 +268,19 @@ static void parse_gb_huge_pages(char *param, char *val) static void handle_mem_options(void) { char *args = (char *)get_cmd_line_ptr(); - size_t len = strlen((char *)args); + size_t len; char *tmp_cmdline; char *param, *val; u64 mem_size; + if (!args) + return; + if (!strstr(args, "memmap=") && !strstr(args, "mem=") && !strstr(args, "hugepages")) return; + len = strlen(args); tmp_cmdline = malloc(len + 1); if (!tmp_cmdline) error("Failed to allocate space for tmp_cmdline"); @@ -399,8 +403,7 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size, { unsigned long init_size = boot_params->hdr.init_size; u64 initrd_start, initrd_size; - u64 cmd_line, cmd_line_size; - char *ptr; + unsigned long cmd_line, cmd_line_size; /* * Avoid the region that is unsafe to overlap during @@ -421,16 +424,15 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size, /* No need to set mapping for initrd, it will be handled in VO. */ /* Avoid kernel command line. */ - cmd_line = (u64)boot_params->ext_cmd_line_ptr << 32; - cmd_line |= boot_params->hdr.cmd_line_ptr; + cmd_line = get_cmd_line_ptr(); /* Calculate size of cmd_line. */ - ptr = (char *)(unsigned long)cmd_line; - for (cmd_line_size = 0; ptr[cmd_line_size++];) - ; - mem_avoid[MEM_AVOID_CMDLINE].start = cmd_line; - mem_avoid[MEM_AVOID_CMDLINE].size = cmd_line_size; - add_identity_map(mem_avoid[MEM_AVOID_CMDLINE].start, - mem_avoid[MEM_AVOID_CMDLINE].size); + if (cmd_line) { + cmd_line_size = strlen((char *)cmd_line) + 1; + mem_avoid[MEM_AVOID_CMDLINE].start = cmd_line; + mem_avoid[MEM_AVOID_CMDLINE].size = cmd_line_size; + add_identity_map(mem_avoid[MEM_AVOID_CMDLINE].start, + mem_avoid[MEM_AVOID_CMDLINE].size); + } /* Avoid boot parameters. */ mem_avoid[MEM_AVOID_BOOTPARAMS].start = (unsigned long)boot_params;