Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4552028ybb; Tue, 24 Mar 2020 00:32:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsMcA35sKuoGUtdPMdrc7gXMN6AFnovXCDCUTI6ZCXoJufGfA2U/wZu6T8Ib3xtv4oCKk4V X-Received: by 2002:aca:724f:: with SMTP id p76mr2536701oic.112.1585035120009; Tue, 24 Mar 2020 00:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585035120; cv=none; d=google.com; s=arc-20160816; b=iFEgl/gT57QbrbQGnSZNNf88JZkrAF5rlA4xJHLUeVIO3c0zObjcuk/sP7V+XUx9ta /+oeoKFMyDOlGCohTyPq5Etv5deuwiH+RKBt3By/7MkWkuH+no/j/aNBMEQ4s9xM9Ykd i4QtD3d4T8c0NXhBydkZT9pvsRp3U0pga/nJzyUVW5xpO+85L8Gg5t9K1x/5Q668ZbwY ekxyezIliQtys7v1Fu4Vn4IEENflon8glZjwHEmUf7yE+lRuvryiIs2kUeiIl9ICXbuf 2aAUJpQszt1vwio5C6FGf8aY62WbTzRdw/FuZ73tOvMz2B4Gh9atFVuNUAORWmbsAX7K b/vQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eR+uDkZlwayIbsgbPeyhEUp7doO9+jBvD/Fsht7osWo=; b=WuaepQP1byvM7r12Z12c+QBDWy+sdaUeMuoBowsW0Sddm01iBovqCaVfh2Tbi54YND Eeae4UdP6IdkOIRHsCNYnfbtlzsLdWKi0tW+d8VszWFEdTAWzGEBx3Xm/g1JFP3zrwOF UBwySGnry9gm3VLAPNRG1CrwwBqfEuy+Z6+DpkvBmCldGG9IPCQvpuB2Ce12i3wqVv1A tXHwNVhJ4s45NgZNzk1x/WDqzHmRyG5JrTQOva1iXApBC6BUuElpMDzoNNGJTC6kZIE0 CUZve25vZoOWlEvO3EkGEsiz1OtusOS/8gQm40x+NNprcjRa/cArfgpmJaz+zBfplzkb du+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=XoVHwOun; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3si648216oof.81.2020.03.24.00.31.47; Tue, 24 Mar 2020 00:31:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=XoVHwOun; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727536AbgCXHbL (ORCPT + 99 others); Tue, 24 Mar 2020 03:31:11 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38922 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727524AbgCXHbK (ORCPT ); Tue, 24 Mar 2020 03:31:10 -0400 Received: by mail-pf1-f195.google.com with SMTP id d25so8849952pfn.6 for ; Tue, 24 Mar 2020 00:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eR+uDkZlwayIbsgbPeyhEUp7doO9+jBvD/Fsht7osWo=; b=XoVHwOunlnnbXskW9yEXFl7rJ9ssINpRGhRVPBNdeKX2ubyzIqYnH7eOAuSMPP47WM vpKFBPcMqG36hjx5V9ijQ5XnCZZkQIWI1tZjd3oRZHyBNBWUi8pl2Gt2hBTYwifQ6ftG GYYAaKaGAfU6znHtAwVS6nk59jizZ8IkH8NR3GC2jDw2RAP+PoQIb66l7GXWxPSDOk6X t86QXLZ+el4hQ8fIoCNxLsTKPO8lBNpFPmrg8J/tRYBogRjl6D83lkUa6ICTHiT9t0Pp Qnpj/UoH5ouKUI08kBZfOPHpXugMxTI5KFE/nG2KOA+7/RRz8rf7p8QYWs/H0b7RkqFM J+QA== 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=eR+uDkZlwayIbsgbPeyhEUp7doO9+jBvD/Fsht7osWo=; b=uoFBK+GmTzp2xkgycA/Q4W4bdYtmnmmt9PUDcBrkhghAiW0OFNpioLAvh2bNGPPPnt hO7q1aUDYomkRQE6OqGMrT6+WbWOTXAJlgp/W/l+V649ro/YO5sz+/ViHWLrx7dlexQx JN5knCdnsggnObxKLHL3VGOjqpSixyIyyoHDgUWjG99THg2fptqweq2IBZiVQd8GFXEN vai3RqgxZ5ujZutD0iaB1w0lHwbZdI5nirgtpzVYex2wUG46CKvVIDZKjFODUqz62DJB R/iYP33VK1vsKypwwL8G4fANcDzCR4Wj6rRt7ddtqsA8/xkeVoJqfqRpJpr4zxvAYUfX u2Bw== X-Gm-Message-State: ANhLgQ2Gwk0jBderftUNGfyFPChZzaLZ3i+8CizZwVpuyrfGq6kESQBR xKLTS1eyJ6Fwtknsq64Eg2rGEA== X-Received: by 2002:a63:ff4e:: with SMTP id s14mr26364986pgk.269.1585035069344; Tue, 24 Mar 2020 00:31:09 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id i187sm15124648pfg.33.2020.03.24.00.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 00:31:09 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, paul.walmsley@sifive.com, alex@ghiti.fr, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Zong Li Subject: [PATCH RFC 7/8] riscv/kaslr: add cmdline support to disable KASLR Date: Tue, 24 Mar 2020 15:30:52 +0800 Message-Id: <292e5511fff99d564c947c9ee71be367be947f55.1584352425.git.zong.li@sifive.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide a cmdline parameter 'nokaslr' to disable KASLR. Signed-off-by: Zong Li --- arch/riscv/kernel/kaslr.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/arch/riscv/kernel/kaslr.c b/arch/riscv/kernel/kaslr.c index 0bd30831c455..6920727e4b4a 100644 --- a/arch/riscv/kernel/kaslr.c +++ b/arch/riscv/kernel/kaslr.c @@ -156,6 +156,36 @@ static __init u64 kaslr_get_seed(void) return ret; } +static __init const u8 *kaslr_get_cmdline(void) +{ + static const u8 default_cmdline[] __initconst = CONFIG_CMDLINE; + + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { + int node; + const u8 *prop; + + node = fdt_path_offset(dtb_early_va, "/chosen"); + if (node < 0) + goto out; + + prop = fdt_getprop(dtb_early_va, node, "bootargs", NULL); + if (!prop) + goto out; + + return prop; + } + +out: + return default_cmdline; +} + +static __init bool kaslr_is_disabled(void) +{ + const u8 *cmdline = kaslr_get_cmdline(); + + return strstr(cmdline, "nokaslr") != NULL; +} + static __init bool is_overlap(uintptr_t s1, uintptr_t e1, uintptr_t s2, uintptr_t e2) { @@ -379,6 +409,10 @@ uintptr_t __init kaslr_early_init(void) if (!seed) return 0; + /* Check whether disable kaslr by cmdline. */ + if (kaslr_is_disabled()) + return 0; + /* Get the random number for kaslr offset. */ kaslr_offset = get_random_offset(seed, kernel_size); -- 2.25.1