From patchwork Mon Dec 19 10:12:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 34449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2310978wrn; Mon, 19 Dec 2022 02:38:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf6h+b+11leOVJIFmpbB+zZftBDH/jNteWIp3k1qc1EEIrYbHUXYC314TgsPZU00YqR0+h1c X-Received: by 2002:a17:903:4094:b0:189:7548:20a7 with SMTP id z20-20020a170903409400b00189754820a7mr35818888plc.56.1671446287959; Mon, 19 Dec 2022 02:38:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671446287; cv=none; d=google.com; s=arc-20160816; b=jT0cFdIRf6uiKugSlzSM1n+GacqU8Waaa3wzc3WdjK6LdXIRRfjGgVPBizJkfnhOyA qkro4j0kJMQy8W2yTiu8Lv/BNm4XDMw3jzwJgkohdbO9U0Pl+qDgSKCupvvBIt6Mr9Hw SEyLy0gu0ewXgR60mUseERXE9UUw2mkw5T3P/Zm3wa6Th4dmRjxuRteXjbcgkqgIzLQW 3dYdxW+6NhLBLcE7ttBs7P/ZBW8z+kVZqsjxFzJj330IYoc9eMyEgXEDLuAk/Fw6fbsB pCn46xR1J/VwvA6VcGTtCGurjmZQCv4++i4aEY8yZZMlC7hZ7sq0gkehnC3tt/gkBzdB A+Hw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=vuVK/8nIOHr+KA0Xr06M05DgvrPOdH+1vn46y4niMtg=; b=pCTjbM+mXo4IA5qWdNO5T79jkOdHuSVyaBDn+cY6LGJyOGYA7H4rIURiHSNvFZOxW1 Y1qEwNQyJoLMD9znVvdDchF6ulCBsHWvh/7GFyP+PsS6sJD0vYOnE1JfuOdVHdh1eCRp P4xM1bvyTN+Lsbw6s8TW/agZgjd4LQ5NM5h2T3SH15en7PkrCjyoQFoZeJd+m6MfKDd5 GZX/2EsE15c+kkqUWB4RRzI6gzXdGCvaVQMAB5x0J/x7uKSK7QU+We+orDAwnKqChCY3 82CyC0vVx/dlK5aByB1T+vqAL6g9QscsJykzRXTgKhnC0iwy2zy2FqNZkS7cCm/vyJes 2SiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VuAtJpn1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p7-20020a1709026b8700b00189cbf69543si9751356plk.286.2022.12.19.02.37.53; Mon, 19 Dec 2022 02:38:07 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VuAtJpn1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231453AbiLSKNM (ORCPT + 99 others); Mon, 19 Dec 2022 05:13:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231158AbiLSKNK (ORCPT ); Mon, 19 Dec 2022 05:13:10 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2578A444; Mon, 19 Dec 2022 02:13:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6410AB80D2E; Mon, 19 Dec 2022 10:13:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB7B1C433D2; Mon, 19 Dec 2022 10:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671444786; bh=so62ehXrt0ugpolpXDq/vhciOHZFZ9Z/0bVRkGbhDyE=; h=From:To:Cc:Subject:Date:From; b=VuAtJpn1m+nCSNRBmNIusc0AHAFMcriDsUG6yWQXEc7DQZWU2o/8BMmhJAs9VECrE zzcKFvzMVyJBGdkCKhFMjMtjbcN5cqkg0619MSWfC1xRqKz4xvemVueJoSOQeqNfSp 7R/aJh3adC/Lk5FuZJp0qZnC4DQNUME5pKDycN9/yc1gYP3f3RM5gdQHX4xv1PrwDe hg1S+IuR72E9/NjBmk23EB1l3xFZrgeg9xbGBcAjhDoVLAdlcTnTzk9zPsjJHz+hy8 aOXmJxsVX44WGsQb/i3YoYr3c2NQJsgqgpgqUVosSUicbWGP+PuN3WHYplMUaRNEqn TIGN8RJR4R9rw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1p7D9Y-0002ab-5M; Mon, 19 Dec 2022 11:13:48 +0100 From: Johan Hovold To: Ard Biesheuvel Cc: "Jason A. Donenfeld" , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , Steev Klimaszewski , Bjorn Andersson , Andrew Halaney Subject: [PATCH v2] efi: random: fix NULL-deref when refreshing seed Date: Mon, 19 Dec 2022 11:12:37 +0100 Message-Id: <20221219101237.9872-1-johan+linaro@kernel.org> X-Mailer: git-send-email 2.37.4 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752362972116902960?= X-GMAIL-MSGID: =?utf-8?q?1752638463160829023?= Do not try to refresh the RNG seed in case the firmware does not support setting variables. This is specifically needed to prevent a NULL-pointer dereference on the Lenovo X13s with some firmware revisions, or more generally, whenever the runtime services have been disabled (e.g. efi=noruntime or with PREEMPT_RT). Fixes: e7b813b32a42 ("efi: random: refresh non-volatile random seed when RNG is initialized") Reported-by: Steev Klimaszewski Reported-by: Bjorn Andersson Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Signed-off-by: Johan Hovold Tested-by: Steev Klimaszewski --- Changes in v2 - amend commit message with a comment on this being needed whenever the runtime services have been disabled drivers/firmware/efi/efi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 31a4090c66b3..09716eebe8ac 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -429,7 +429,9 @@ static int __init efisubsys_init(void) platform_device_register_simple("efi_secret", 0, NULL, 0); #endif - execute_with_initialized_rng(&refresh_nv_rng_seed_nb); + if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) + execute_with_initialized_rng(&refresh_nv_rng_seed_nb); + return 0; err_remove_group: