Message ID | 20230720101431.71640c8a@imladris.surriel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3163179vqt; Thu, 20 Jul 2023 07:35:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlGpxzP6FHbpAG8MHTmIsl1m2u8Poh0asnaX0wybnvNKHK6/vQiHDHY/KJ6LWvgLkqoowlyn X-Received: by 2002:a05:6402:60c:b0:51e:1bf3:f4ac with SMTP id n12-20020a056402060c00b0051e1bf3f4acmr4922539edv.27.1689863709852; Thu, 20 Jul 2023 07:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689863709; cv=none; d=google.com; s=arc-20160816; b=jv4dJk86JrQ6nZtS7NA5ZJQGpn4HMPa+TMB+wD+VUHHmBfisHssTS9zu1kofbXKJSb 0gvG7EoG4ItYMJ/h8+77RYCoWUXi4lB29psx7Pl/6n2L3CWu5o7JGdEfWy+59jUH/qYG fbyLeSiz+kxoSXGueiEoXDabwJsqbHjjXrcKrg01VZFd4d0AeyWGcdnzxI27jzO41kAX zjni2oYgCqu86+2Wg+1cSPf9qgxSDU5hvG4ybF+hW1ev2/ipJkVc/Jd/GSqPr22+8FhW GKTT4rSgxK/SoFMjWcCJw2AyxFteYqX/l00GX7e2M3H0FN+Sk1Ri3m40H8dOGCzgVoTc 5VmQ== 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=BwHNPA3EmPwz7rrk+MvHbZahq447cJRhqehgoafnMhk=; fh=ea8CkGoS8YkU+6sx1MG6qBGr4Rrahcz0yzg98E9m/HI=; b=dPI7VGPzp6f8zX2zaU/KndIxrSMTi8T81yRE93f05OYKtV2qg9BP7QLwj3T9wmqKyF Q7WIEErL04jpA8PWpBucAC+9zqlfgzlDzxVtILo/Gwr8QHMDqWxWyJ81lIXbdliiZN/d K2ejLYuliWsCCW9btIGN9Bd2tNShByMdK+YCW+TNarzvpAAWoOAaKeO/E5g2RTRDUJgb xFbZPQKzh/2SZAgLfB+S5gDPw1+2UizBGwngoOSV78QTn5kqnK9re+fjNYhduUdCYXS+ 9GVa0rKAXHp/CFsbtMn8/G8EY5uGHUS56u32La/VKZSO5Hu4IwMR0f0FbxLWaMFWt805 9InA== 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 o20-20020aa7c514000000b0051df73ddeffsi872133edq.358.2023.07.20.07.34.44; Thu, 20 Jul 2023 07:35:09 -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 S232193AbjGTOWt (ORCPT <rfc822;assdfgzxcv4@gmail.com> + 99 others); Thu, 20 Jul 2023 10:22:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232187AbjGTOWr (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 20 Jul 2023 10:22:47 -0400 X-Greylist: delayed 462 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 20 Jul 2023 07:22:45 PDT Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED8782703; Thu, 20 Jul 2023 07:22:44 -0700 (PDT) Received: from [2601:18c:8180:ac39: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 1qMUQN-0001k2-2d; Thu, 20 Jul 2023 10:14:35 -0400 Date: Thu, 20 Jul 2023 10:14:31 -0400 From: Rik van Riel <riel@surriel.com> To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, Mike Rapoport <rppt@kernel.org>, devicetree@vger.kernel.org, x86@kernel.org, Rob Herring <robh+dt@kernel.org>, Juergen Gross <jgross@suse.com>, Dave Hansen <dave.hansen@linux.intel.com> Subject: [PATCH] mm,ima,kexec: use memblock_free_late from ima_free_kexec_buffer Message-ID: <20230720101431.71640c8a@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,T_SCC_BODY_TEXT_LINE 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: 1771950529547757670 X-GMAIL-MSGID: 1771950529547757670 |
Series |
mm,ima,kexec: use memblock_free_late from ima_free_kexec_buffer
|
|
Commit Message
Rik van Riel
July 20, 2023, 2:14 p.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 ++------
drivers/of/kexec.c | 3 ++-
2 files changed, 4 insertions(+), 7 deletions(-)
Comments
On Thu, Jul 20, 2023 at 10:14:31AM -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") Fixes: b69a2afd5afc ("x86/kexec: Carry forward IMA measurement log on kexec") Acked-by: Rob Herring <robh@kernel.org> (I'm assuming someone else is taking this) > 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 ++------ > drivers/of/kexec.c | 3 ++- > 2 files changed, 4 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c > index fd975a4a5200..aa0df37c1fe7 100644 > --- a/arch/x86/kernel/setup.c > +++ b/arch/x86/kernel/setup.c > @@ -359,15 +359,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; > diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c > index f26d2ba8a371..68278340cecf 100644 > --- a/drivers/of/kexec.c > +++ b/drivers/of/kexec.c > @@ -184,7 +184,8 @@ int __init ima_free_kexec_buffer(void) > if (ret) > return ret; > > - return memblock_phys_free(addr, size); > + memblock_free_late(addr, size); > + return 0; > } > #endif > > -- > 2.41.0 >
On Fri, 2023-07-21 at 13:38 -0600, Rob Herring wrote: > On Thu, Jul 20, 2023 at 10:14:31AM -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") > > Fixes: b69a2afd5afc ("x86/kexec: Carry forward IMA measurement log on > kexec") > Thank you for digging further back in the history of that code. > Acked-by: Rob Herring <robh@kernel.org> > > (I'm assuming someone else is taking this) I hope so, but I don't know who...
On Fri, Jul 21, 2023 at 08:40:41PM -0400, Rik van Riel wrote: > On Fri, 2023-07-21 at 13:38 -0600, Rob Herring wrote: > > On Thu, Jul 20, 2023 at 10:14:31AM -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") > > > > Fixes: b69a2afd5afc ("x86/kexec: Carry forward IMA measurement log on > > kexec") > > > Thank you for digging further back in the history of that code. > > > Acked-by: Rob Herring <robh@kernel.org> > > > > (I'm assuming someone else is taking this) > > I hope so, but I don't know who... You could split this into 2 patches, then there's no doubt. And each Fixes is clear. Rob
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index fd975a4a5200..aa0df37c1fe7 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -359,15 +359,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; diff --git a/drivers/of/kexec.c b/drivers/of/kexec.c index f26d2ba8a371..68278340cecf 100644 --- a/drivers/of/kexec.c +++ b/drivers/of/kexec.c @@ -184,7 +184,8 @@ int __init ima_free_kexec_buffer(void) if (ret) return ret; - return memblock_phys_free(addr, size); + memblock_free_late(addr, size); + return 0; } #endif