From nobody Mon Feb 9 10:12:47 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EF6BC77B7C for ; Sat, 27 May 2023 12:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232596AbjE0MgT (ORCPT ); Sat, 27 May 2023 08:36:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232540AbjE0MgL (ORCPT ); Sat, 27 May 2023 08:36:11 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D315E13D for ; Sat, 27 May 2023 05:35:50 -0700 (PDT) Received: from dggpemm500006.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QT1V70jw7zTkdx; Sat, 27 May 2023 20:35:43 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Sat, 27 May 2023 20:35:47 +0800 From: Zhen Lei To: Eric Biederman , Baoquan He , , CC: Zhen Lei , Michael Holzheu , Andrew Morton , Amerigo Wang Subject: [PATCH 1/6] kexec: fix a memory leak in crash_shrink_memory() Date: Sat, 27 May 2023 20:34:34 +0800 Message-ID: <20230527123439.772-2-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230527123439.772-1-thunder.leizhen@huawei.com> References: <20230527123439.772-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If the value of parameter 'new_size' is in the semi-open and semi-closed interval (crashk_res.end - KEXEC_CRASH_MEM_ALIGN + 1, crashk_res.end], the calculation result of ram_res is: ram_res->start =3D crashk_res.end + 1 ram_res->end =3D crashk_res.end The operation of function insert_resource() fails, and ram_res is not added to iomem_resource. As a result, the memory of the control block ram_res is leaked. In fact, on all architectures, the start address and size of crashk_res are already aligned by KEXEC_CRASH_MEM_ALIGN. Therefore, we do not need to round up crashk_res.start again. Instead, we should round up 'new_size' in advance. Fixes: 6480e5a09237 ("kdump: add missing RAM resource in crash_shrink_memor= y()") Fixes: 06a7f711246b ("kexec: premit reduction of the reserved memory size") Signed-off-by: Zhen Lei Acked-by: Baoquan He --- kernel/kexec_core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 3d578c6fefee385..22acee18195a591 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -1122,6 +1122,7 @@ int crash_shrink_memory(unsigned long new_size) start =3D crashk_res.start; end =3D crashk_res.end; old_size =3D (end =3D=3D 0) ? 0 : end - start + 1; + new_size =3D roundup(new_size, KEXEC_CRASH_MEM_ALIGN); if (new_size >=3D old_size) { ret =3D (new_size =3D=3D old_size) ? 0 : -EINVAL; goto unlock; @@ -1133,9 +1134,7 @@ int crash_shrink_memory(unsigned long new_size) goto unlock; } =20 - start =3D roundup(start, KEXEC_CRASH_MEM_ALIGN); - end =3D roundup(start + new_size, KEXEC_CRASH_MEM_ALIGN); - + end =3D start + new_size; crash_free_reserved_phys_range(end, crashk_res.end); =20 if ((start =3D=3D end) && (crashk_res.parent !=3D NULL)) --=20 2.25.1