Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3387071pxk; Mon, 21 Sep 2020 12:17:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSS57hkvks/+IoBEAkVMWXB98tP6Ey2cKFo1eq0/FQiwtEb9xUApYkhAyjNAzA3Y9G53Xo X-Received: by 2002:aa7:c154:: with SMTP id r20mr395629edp.337.1600715870924; Mon, 21 Sep 2020 12:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600715870; cv=none; d=google.com; s=arc-20160816; b=x6Ho2INfYGvymkhnQRF/cYOn0kbAqeYJfm/Dsfv0MrgUjkSzimHxw3GVG7c83DRJjv jps3ccumCfPdGR7p2BXA09MjXyxQwSbNJWBW+8GXWFnKX8d8GDw9NBwOINTIMSDIdKgH Ms0IpGRlTKXiq36OKSS404lahI+WFfyfYe2AHe2aNvAFQ2oo4Gv85wwgfRTmllXjvYSH 2SX60q0j2ZLx7Lklhr1lxyyWIkwUlZzzmw1p/DE+vwGmEGH39amymsJmYJbCZ1h9TE+v eH6RRYV/oacQSRhm4Ylzf/b9zRqHGC1B8ryTG2K63VFCLhF2hmSm/3s3jRXRZy7j1+SO FCpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=c1UaOqqN8L8mnVxjNiUIJWteiuc/MyzZUtEtEiVniLg=; b=SzC6Acxq4C2oXyIs6rAh7iQbhpRpBpB/xtnvQ4S7uTBRUSCWE71rmsStf0LK/fP/hs oUaJpAl3kCeqY5BRUKEWpTvSRxCWDHxZh/1sFe9JX7wv6PoUsghxtXZsAIUwwAi/cjCz 3dTKwjya81vRAWENV6vF5yRhvZho2wx8FTd2vVCkq5cd+uC6jDZ+OlSkzk5n/52R5FpJ YOPon6klrftqY3/qD3ec72WQWZxeNYewM7EO00jWxPOJgbopeItpAnL1svT5ALLYEjRI O+NQZPykhyr3mkVTeF2Ltv2p5LN+dbiRr+sHepeIJ5Xr3Z7DrAF/rlNNe6B0aqu28kQM 7HPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=rjY2ic5v; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n17si8841103eje.585.2020.09.21.12.17.27; Mon, 21 Sep 2020 12:17:50 -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=pass header.i=@linux.microsoft.com header.s=default header.b=rjY2ic5v; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727630AbgIUTQY (ORCPT + 99 others); Mon, 21 Sep 2020 15:16:24 -0400 Received: from linux.microsoft.com ([13.77.154.182]:53602 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726810AbgIUTQY (ORCPT ); Mon, 21 Sep 2020 15:16:24 -0400 Received: from sequoia.work.tihix.com (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id 3A5C920B36E7; Mon, 21 Sep 2020 12:16:23 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3A5C920B36E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1600715783; bh=c1UaOqqN8L8mnVxjNiUIJWteiuc/MyzZUtEtEiVniLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rjY2ic5vypIguJogutpWx0j/sWdqdWq6zci8/1klZOLIblS7qPS5blAF2lHqNE3A6 n47+vWUxwRJsoc5EGc6nEx8oBz/jTJq+DHuXDQb2TuF0f5/h/aoVemuftZhAenbGrW taD3o8mraHu5bUrnOBVEzdzm5QxXmCJD17YdZYVc= From: Tyler Hicks To: Catalin Marinas , Will Deacon Cc: Pavel Tatashin , Rob Herring , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] arm64: kaslr: Refactor early init command line parsing Date: Mon, 21 Sep 2020 14:15:56 -0500 Message-Id: <20200921191557.350256-2-tyhicks@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200921191557.350256-1-tyhicks@linux.microsoft.com> References: <20200921191557.350256-1-tyhicks@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Don't ask for *the* command line string to search for "nokaslr" in kaslr_early_init(). Instead, tell a helper function to search all the appropriate command line strings for "nokaslr" and return the result. This paves the way for searching multiple command line strings without having to concatenate the strings in early init. Signed-off-by: Tyler Hicks --- arch/arm64/kernel/kaslr.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c index b181e0544b79..4c779a67c2a6 100644 --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -50,10 +50,16 @@ static __init u64 get_kaslr_seed(void *fdt) return ret; } -static __init const u8 *kaslr_get_cmdline(void *fdt) +static __init bool cmdline_contains_nokaslr(const u8 *cmdline) { - static __initconst const u8 default_cmdline[] = CONFIG_CMDLINE; + const u8 *str; + str = strstr(cmdline, "nokaslr"); + return str == cmdline || (str > cmdline && *(str - 1) == ' '); +} + +static __init bool is_kaslr_disabled_cmdline(void *fdt) +{ if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { int node; const u8 *prop; @@ -65,10 +71,10 @@ static __init const u8 *kaslr_get_cmdline(void *fdt) prop = fdt_getprop(fdt, node, "bootargs", NULL); if (!prop) goto out; - return prop; + return cmdline_contains_nokaslr(prop); } out: - return default_cmdline; + return cmdline_contains_nokaslr(CONFIG_CMDLINE); } /* @@ -83,7 +89,6 @@ u64 __init kaslr_early_init(u64 dt_phys) { void *fdt; u64 seed, offset, mask, module_range; - const u8 *cmdline, *str; unsigned long raw; int size; @@ -115,9 +120,7 @@ u64 __init kaslr_early_init(u64 dt_phys) * Check if 'nokaslr' appears on the command line, and * return 0 if that is the case. */ - cmdline = kaslr_get_cmdline(fdt); - str = strstr(cmdline, "nokaslr"); - if (str == cmdline || (str > cmdline && *(str - 1) == ' ')) { + if (is_kaslr_disabled_cmdline(fdt)) { kaslr_status = KASLR_DISABLED_CMDLINE; return 0; } -- 2.25.1