Message ID | 20230908233127.0af375d1@imladris.surriel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;toshivichauhan@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <riel@shelob.surriel.com>) 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 <riel@surriel.com> To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, Mike Rappoport <rppt@kernel.org>, x86@kernel.org, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com> 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776564325209507199 X-GMAIL-MSGID: 1776564325209507199 |
Series |
x86,kexec,ima: use memblock_free_late from ima_free_kexec_buffer
|
|
Commit Message
Rik van Riel
Sept. 9, 2023, 3:31 a.m. UTC
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 <riel@surriel.com>
Suggested-by: Mike Rappoport <rppt@kernel.org>
---
arch/x86/kernel/setup.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
Comments
On Fri, Sep 08, 2023 at 11:31:27PM -0400, Rik van Riel wrote: > 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 <riel@surriel.com> > Suggested-by: Mike Rappoport <rppt@kernel.org> Acked-by: Mike Rapoport (IBM) <rppt@kernel.org> > --- > 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; > -- > 2.41.0 > >
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;