From patchwork Fri Sep 8 10:44:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 137768 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp704669vqo; Fri, 8 Sep 2023 11:03:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEy9ice3zQGNmoocM5vTwQswc8g6T5Cnf5JSqpJC1adhiCtrjOlXVGUS2BYbYqhHMTEzsSw X-Received: by 2002:a05:6512:238e:b0:500:91c1:9642 with SMTP id c14-20020a056512238e00b0050091c19642mr2795202lfv.21.1694196222734; Fri, 08 Sep 2023 11:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694196222; cv=none; d=google.com; s=arc-20160816; b=y1S3bp+tTQb1k9L01rNNF9hahitVUDYmHO7F9htzf/dvnYtkmsLq2Md4lIbek189d9 +IJOeJXFT+zjGSqUTO7mDgtYSv7gFwPfLw7i/im6ji6mnzLR/OGZ9iBMFyD3fj2F5kAx iRxIEMxhnq/fm9kYLgCJGgJE5mbdl5/2tw6tNuHa9SE72zu2upyILoN9kXFfTVlEiG0v xDDOt89sjVehQzFFbP9nnJxsKDzmnkEt6Db4fStEKpnCbzXEYodUi7WeOIe7zrNzf4GH PhwkuxKYZS35QUQBO3rIqeHg+aLrD46SNM7jIqsQYybYMxCdISm+cXMUKQl3d7fvIknZ 7uWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=KgR4XTYnF55TAF39ME0z5hjQ2CP8JeIC4gtl/9wcTlE=; fh=R0YYFT90f6WLczjoUQv5H5fVxdqUhB7Ey4yyrjW0oOQ=; b=osymgfTuEUFvBCsNORtDzNGRrRLyQ0Mn5li4cTj/UGgvq/BZxXzKkFy7CeuNxOLOB7 g6ihB28zfLbvUe1vjj60cLaIx8fFjK30I9GYrCdtuaqTt9dn+oVMIrqzTaqmyI4Vsqrv yH6VMQtQgpbCdW/fxza73FEVs7v8FKwTBICQghu2bu/NgbuPP3MsaVHXvCG2H07pkKnb 2J8KA5o8zobZWlvnO/tuV4DkHDGh8JulokCeY/CtFCvD/gaMVFVH6kobada3CKF/QGD/ 1tRO9U2OjlhfYiQKDgMz3yaOe7D9Q9zU/Jf1i5ifUG8IilBwDj4wHlfg9JySHVKwt6kd SvLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020aa7d845000000b00525b997a7b9si1962906eds.610.2023.09.08.11.03.00; Fri, 08 Sep 2023 11:03:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242885AbjIHKpa (ORCPT + 99 others); Fri, 8 Sep 2023 06:45:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbjIHKp3 (ORCPT ); Fri, 8 Sep 2023 06:45:29 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E79481BC6; Fri, 8 Sep 2023 03:45:23 -0700 (PDT) X-QQ-mid: bizesmtp80t1694169918tbzdih2r Received: from localhost.localdomain ( [221.226.144.218]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 08 Sep 2023 18:45:17 +0800 (CST) X-QQ-SSF: 01200000000000B0B000000A0000000 X-QQ-FEAT: +ynUkgUhZJlvTaar5ynbaN+YgYzMmbUdQ02O1U3/wK5rnjfdU3lCgnxHq1KSh 2uYb4IfLddN/iLAHzZs2HA7vVrF2kjUV7smG4FvrvT68BHAshGCf9uHqml1ZeUsHAtrZUhH hfKMeCyLgJgslljOcpIPfFtqGPqaTcqZDlTXLdLrpIPnDECWGjYkjW2rNbwzhkkB/wDA5Du XO2GFfrYdVvZuGKuxLi/CXhD2mQeuyjmNHq1Z3qIkGhrN38AiHTf5g60lfY7SVzAFt+qDu4 krD8GX0cCe616kffi2HA8Q+u4qmHRc2H7Bn9wR3sgnT+V0NEx3wPD/nmY2EmDYpl0dKN1oM Q4AGcBR9n7UrgteQl3l474MikW7SPZ8Ta+YgeGD X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4282646312144880661 From: Song Shuai To: robh+dt@kernel.org, frowand.list@gmail.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Song Shuai Subject: [PATCH] of/kexec: Omit kaslr-seed when kexecing with nokaslr Date: Fri, 8 Sep 2023 18:44:58 +0800 Message-Id: <20230908104458.775740-1-songshuaishuai@tinylab.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz4a-0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776493498259851652 X-GMAIL-MSGID: 1776493498259851652 The chosen node always adds the kaslr-seed property which is needless for the kernels kexeced with the cmdline contained "nokaslr". So omit the kaslr-seed when kexecing with nokaslr. Signed-off-by: Song Shuai --- drivers/of/kexec.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c index f26d2ba8a371..c0d53b10cb70 100644 --- a/drivers/of/kexec.c +++ b/drivers/of/kexec.c @@ -19,6 +19,7 @@ #include #include #include +#include #define RNG_SEED_SIZE 128 @@ -263,6 +264,14 @@ static inline int setup_ima_buffer(const struct kimage *image, void *fdt, } #endif /* CONFIG_IMA_KEXEC */ +static bool is_nokaslr_cmdline(const char *cmdline) +{ + char *str; + + str = strstr(cmdline, "nokaslr"); + return str == cmdline || (str > cmdline && *(str - 1) == ' '); +} + /* * of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree * @@ -429,15 +438,15 @@ void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, else if (ret) goto out; - if (rng_is_initialized()) { + if (!is_nokaslr_cmdline(cmdline) && rng_is_initialized()) { u64 seed = get_random_u64(); ret = fdt_setprop_u64(fdt, chosen_node, "kaslr-seed", seed); if (ret) goto out; } else { - pr_notice("RNG is not initialised: omitting \"%s\" property\n", - "kaslr-seed"); + pr_notice("RNG is not initialised or Kexec with nokaslr:" + " omitting \"%s\" property\n", "kaslr-seed"); } /* add rng-seed */