From patchwork Sat Sep 9 03:31:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 137831 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1110462vqo; Sat, 9 Sep 2023 05:49:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlSUg3Rl9Ne+ibbofbt8wl9MbtBA2U85bUlkNX80B/qX0vUohkqidEAm8MRK0fOIqY8ntS X-Received: by 2002:ac2:597b:0:b0:500:a092:d085 with SMTP id h27-20020ac2597b000000b00500a092d085mr3843377lfp.68.1694263768539; Sat, 09 Sep 2023 05:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694263768; cv=none; d=google.com; s=arc-20160816; b=vTkon+ls3abm0ByABV+n7qhvROJ1bkcfm238cZun9eJk8tqyOY2tTX2jtMbL03bLMM LNqvTaXP3nsSc2C/8+wTftlmOnf7O2LKmzjfGICE19HG8OEpmBtATdE0HP/EGWowUNPE vf3DU1vRRNAO6zAn+P5OfPdfLhJftGs+Bad5H1GHVdnAGmd+dWtNqeeiMU44+jETHNle uimwOZsT8f4kK/aMij8SejTEhX6FDXZiznQassFeUH1NyWnfE52wECNyjjTSoRBmdcXN Zubo8sFnD7aKWNKtWaKk3My1mb5oLnGDDWnXC8I5gqPdq1fsxQHoxVLbGybbGcEXRY3V fLfw== 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 :message-id:subject:cc:to:from:date; bh=aY90T5i/SUCYmle9u3tVlEeb9gb2972LN71Yn9nV5BY=; fh=QC14985oLCh/kpc+2QnXiyissDC2LIcMH4eaaZxl7DM=; b=GW9/9oi9RD5Xp0Gs12VO4N/bH+gbYI+2Kyz+3ifwPEdC9L0NEsX1ZQuDCyACPT6j+4 Plt3Xiu5h8h4D6jYD+/iQ15shwofrAdHFb+KXXq9v+g8kzaSsccWVC93kzdu+OeWAZVu mue8FVIxfctamWbSj0JzCI2UrwkhkKIbDI2CMcwWu2zRUi7MKv/FkMrIY7mTcC30NsK6 h0GscBdtHKwCxE9hAFUE1eqag+mfm6uOE/99lApkTwQpYFkE6WlXgVXF+gS+RaUcMEEX adkbp0zb9qdZHeduQLMSCPT07zbVz4oAFTnv6sm+ensQ3c9CcalDYyL1tRl3055BjUnF Y8sQ== 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 cw13-20020a170906c78d00b0099bd6dd9362si2868747ejb.907.2023.09.09.05.49.24; Sat, 09 Sep 2023 05:49:28 -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 S232830AbjIIDcP (ORCPT + 14 others); Fri, 8 Sep 2023 23:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjIIDcO (ORCPT ); Fri, 8 Sep 2023 23:32:14 -0400 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E04A1FDB for ; Fri, 8 Sep 2023 20:32:07 -0700 (PDT) Received: from [2601:18c:9101:a8b6:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qeoh1-0003P4-2B; Fri, 08 Sep 2023 23:31:31 -0400 Date: Fri, 8 Sep 2023 23:31:27 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, Mike Rappoport , x86@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Subject: [PATCH] x86,kexec,ima: use memblock_free_late from ima_free_kexec_buffer Message-ID: <20230908233127.0af375d1@imladris.surriel.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Sender: riel@surriel.com X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE 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: 1776564325209507199 X-GMAIL-MSGID: 1776564325209507199 The code calling ima_free_kexec_buffer runs long after the memblock allocator has already been torn down, potentially resulting in a use after free in memblock_isolate_range. With KASAN or KFENCE, this use after free will result in a BUG from the idle task, and a subsequent kernel panic. Switch ima_free_kexec_buffer over to memblock_free_late to avoid that issue. Fixes: fee3ff99bc67 ("powerpc: Move arch independent ima kexec functions to drivers/of/kexec.c") Cc: stable@kernel.org Signed-off-by: Rik van Riel Suggested-by: Mike Rappoport Acked-by: Mike Rapoport (IBM) --- arch/x86/kernel/setup.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index b9145a63da77..b098b1fa2470 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -358,15 +358,11 @@ static void __init add_early_ima_buffer(u64 phys_addr) #if defined(CONFIG_HAVE_IMA_KEXEC) && !defined(CONFIG_OF_FLATTREE) int __init ima_free_kexec_buffer(void) { - int rc; - if (!ima_kexec_buffer_size) return -ENOENT; - rc = memblock_phys_free(ima_kexec_buffer_phys, - ima_kexec_buffer_size); - if (rc) - return rc; + memblock_free_late(ima_kexec_buffer_phys, + ima_kexec_buffer_size); ima_kexec_buffer_phys = 0; ima_kexec_buffer_size = 0;