Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp262248ybg; Tue, 28 Jul 2020 05:32:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBaWdk/HwW5eVOHPZVdoPRCnAkVqnSrgyZ4J5H8/GjyN323dklEgFe8EZtcJcDabm+H/kw X-Received: by 2002:aa7:d299:: with SMTP id w25mr13868041edq.209.1595939551259; Tue, 28 Jul 2020 05:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595939551; cv=none; d=google.com; s=arc-20160816; b=v1Ie1xSFDV2u1+hA/PR0JzX9uRMeqyLURothSSMZWaq4/BtOgi981Cg9K3eE//cNN+ gvbV86hTv8lIkbzYyEMG3WZyd5LnjizhemgTwPZsIzdWewSEggfqlfE1zx8q3bIz5yLV 95s6aSrmKaVzK/Qh03o2T3/EBL6XHPBoJtX5dQQmVs4f/Z0fzV9CSheXFVNWb/if5SXU fo4jbUSr2x7pM4XUoTOEXpfTCuc7NmL4BopLQGT6pEfO7sHquC5YqtioEN5bzyZ9590S Qhug5XtZkd0TmCsWe1SP7ZQnKOJp/Km5nkAHLK542Jnt5MCqGsdhM4MYlfnp7nPCTLCr olYg== 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=/S0GPeOT575VDIu9dVFjsNOq+UDoG7rnlQNeDEnhF38=; b=tVJbdEG5EClyYOioRJ0/zbJ4cceEGAjI6cHaBiJ8cg14s4pheUIscx2lXM0uiRtywV ZUVd+9JZDPna+ZYm4jo9xVdeJrDnezlnAgDjddldJPvOiveJ4jP2ZqQw8FUaDzwuWmHj XvVmUs6VdBCvCYtGYYGZdYYVWg+HoCqmzNUjGV0eL8yPtu8stzXXsMld0NH+cxXklsmV rXz8Ha83Skwk/LdraZNyhNx9VmhrDMGtN+YysFnh8dJOef4pFkX/wngg7AhMZc83h1Ws IXA1hPGZfseDBYs4djWudbxHYiFA6S+RQXN6EhvMbr/Mst1shJSG9Q88HqNiqMl/AZ+t i1aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=gBB9GmPi; dkim=neutral (no key) header.i=@linutronix.de; 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 lj13si6906193ejb.357.2020.07.28.05.32.08; Tue, 28 Jul 2020 05:32:31 -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=gBB9GmPi; dkim=neutral (no key) header.i=@linutronix.de; 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 S1729637AbgG1M3V (ORCPT + 99 others); Tue, 28 Jul 2020 08:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729620AbgG1M3S (ORCPT ); Tue, 28 Jul 2020 08:29:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A921C061794; Tue, 28 Jul 2020 05:29:18 -0700 (PDT) Date: Tue, 28 Jul 2020 12:29:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595939356; 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=/S0GPeOT575VDIu9dVFjsNOq+UDoG7rnlQNeDEnhF38=; b=gBB9GmPiODnYJRU3B9dYhjS6KCpEm69Aw5JE94RNyxIQCf5TDQIrZ85tvulEL1W0bY8FF7 aAyHDfBTuRFUq0N5r+7oF4FMAxiL4gxANsAI5BJC9AS+kFJj+IXTWcJ5a8egV8O2SJ7qWw M8PoAkJu5pfHUWGKgBpzkKFtnPiit/+pga3nWFba3oIA9EgQjFBYSYcHvQDse/t4MfL/mF GusD3C82yU6rtV4FubYKFd7fpGmObTJy6a1ZkyENRgURKWz6RyDiR6T3LwrG4VJjp+zv08 KSXxpjWd5Ak1VXvIUQ6Hi9ll12gjAmpFf0yQe6wVJFRjnQR8PTCPyW2oQ0vsvw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595939356; 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=/S0GPeOT575VDIu9dVFjsNOq+UDoG7rnlQNeDEnhF38=; b=5Iz87Nq6MnoH0JxXNLX03HL2dtfaAIV7DhP3cwMrcMPmSBYoVF26Dv8cilpm2/2Ts3k0SN 3SzSl9Jh+GqKPPCw== 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 , 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: <159593935568.4006.12876607482586309970.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: c8465b03acf9d4bb43b9714b6cfb99442defe664 Gitweb: https://git.kernel.org/tip/c8465b03acf9d4bb43b9714b6cfb99442defe664 Author: Arvind Sankar AuthorDate: Mon, 27 Jul 2020 19:07:54 -04:00 Committer: Ingo Molnar CommitterDate: Tue, 28 Jul 2020 12:54:42 +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 Link: https://lore.kernel.org/r/20200727230801.3468620-2-nivedita@alum.mit.edu --- arch/x86/boot/compressed/kaslr.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index d7408af..a4af896 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 = 0; /* * Avoid the region that is unsafe to overlap during @@ -421,12 +424,10 @@ 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++];) - ; + if (cmd_line) + cmd_line_size = strlen((char *)cmd_line); 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,