Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp560284rdb; Fri, 8 Sep 2023 09:00:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFyejr1hSW7df1i9qbWFCPNnTy7Dya9aaqZQEef7fxZHrPW5ePf3GRyJPCriP5j1KjACACn X-Received: by 2002:a17:90b:1190:b0:26d:bf8:5883 with SMTP id gk16-20020a17090b119000b0026d0bf85883mr2849754pjb.4.1694188836267; Fri, 08 Sep 2023 09:00:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694188836; cv=none; d=google.com; s=arc-20160816; b=BnA17AE2z3Cb6R9lYsXGKuzNxczH6HTitXhveZI39+EZExFlJ/bLn8Q6iMxI+uyEAQ u+LbsQSrfVjOWmBlKk0we8qWHQCwpQekilppIglSrIi18QTYRe9+9qqfsAyy64QxECy/ bYlFf25hoDbAWUuMq8bEAxoSSYt/tZzYnk+AxXxxrCU9BLBwJ9UifsSQfIPL1E7A+ns5 KqR4Ruh5G6FsmDtWksoGPmcFjMAqGkQkluTU6D8/dvyhEsHGPR5bLdqNqfQ/YTFOI/Vu xCN/qCSwd9veWmXOG2mFH67+B5ayGxK2/qFWm2gB6538N3SJNPKWLB6oRAuDAY07MPb3 X4Jg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv71-20020a632e4a000000b0056532fbe293si1591498pgb.323.2023.09.08.09.00.10; Fri, 08 Sep 2023 09:00:36 -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 S242393AbjIHKpa (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 Content-Transfer-Encoding: 8bit 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 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 */ -- 2.20.1