From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BD7ECA9EC1 for ; Sat, 10 Oct 2026 20:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=D5xIJ77nP8pyKk1j4aNr1bPe3m2dUcpcnAVPDVOA+vg=; b=IMbZ9R5tqvSBMqXxdoVXOriL9+ yVq3MYrm6sM+SaZDND93xiiZZfW0aD56HykfRabIteXAOoF7Y7Hlbrxg11SASE/53CRh5BiV3gpPY f8MbrxuIjQ0PQciUCeMMLvIu8bgj/9OKiMezwZ7bT1lyI5tRSn9SDkBsnuH8kvwJCA/JzM8R/ootE 4OTKHeOZFk8B0QlMTX8cFd7invTA4lcpeYDRKTOmrkbO42tCrHAQZ5/bSG3vxsoRFn9ccxx797AKG TcnB7XK38mcl9MbBbiU/qzrJG11HstCL9rSFPuwzkmkUd6M6ZJfQFIZ5sYADpOw7oypAX5kaBOgpq Luk/b3aQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xFdFz-00000008QFm-0WfH; Sat, 10 Oct 2026 20:01:23 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xFdFu-00000008QEo-0ISD; Sat, 10 Oct 2026 20:01:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EC41E1692; Sat, 10 Oct 2026 13:01:08 -0700 (PDT) Received: from arm.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9A0AC3F882; Sat, 10 Oct 2026 13:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1791662472; bh=0ej4w9K2k1nE5MBAzVddXwAyLDwy2dxb36CJ0bopUEc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WRSxdsDg02jA7Wxmfp7hUM+7z5or2VN4zazCFutQjZjCNRVVo7Znbg22CVLNz7YAi ObuzEMW4ie3Brz5P5fTbQVvsd7oFGit6h9P3YDLOgc08xfbI46WYb8fvEkIjCXqCBo Fa+IHGI5x3Zu1VuORzdk3Muk8yB8P1D4NRA1la+w= Date: Sat, 10 Oct 2026 21:00:51 +0100 From: Catalin Marinas To: Jinjie Ruan Cc: will@kernel.org, mark.rutland@arm.com, chenhuacai@kernel.org, kernel@xen0n.name, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, akpm@linux-foundation.org, baoquan.he@linux.dev, rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, leitao@debian.org, yeoreum.yun@arm.com, sourabhjain@linux.ibm.com, robh@kernel.org, coxu@redhat.com, kees@kernel.org, tangyouling@kylinos.cn, liukexin@kylinos.cn, zhangtianyang@loongson.cn, guodongtai@kylinos.cn, maqianga@uniontech.com, chao.gao@intel.com, kai.huang@intel.com, vishal.l.verma@intel.com, seanjc@google.com, piliu@redhat.com, thuth@redhat.com, jbouron@amazon.com, me@linux.beauty, mclapinski@google.com, graf@amazon.com, bgwin@google.com, hbathini@linux.ibm.com, eric.devolder@oracle.com, takahiro.akashi@linaro.org, james.morse@arm.com, palmer@rivosinc.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, driver-core@lists.linux.dev, kexec@lists.infradead.org Subject: Re: [PATCH v6 05/14] arm64: kexec_file: Fix elf_headers memory leak in retry loop Message-ID: References: <20260921090450.807575-1-ruanjinjie@huawei.com> <20260921090450.807575-6-ruanjinjie@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260921090450.807575-6-ruanjinjie@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261010_130118_343167_0C4BF802 X-CRM114-Status: GOOD ( 12.92 ) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org On Mon, Sep 21, 2026 at 05:04:41PM +0800, Jinjie Ruan wrote: > If load_other_segments() fails after image->elf_headers is assigned, > the memory lifecycle is safely managed by the global kimage object > and will be freed in arch_kimage_file_post_load_cleanup(). > > However, during a retry loop in image_load(), a subsequent iteration > will allocate a new buffer and overwrite image->elf_headers. This > permanently leaks the stale memory from the previous iteration before > the global cleanup can track it. > > Fix this by explicitly freeing the stale `image->elf_headers` buffer > before assigning the newly allocated headers. > > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Thomas Huth > Cc: Breno Leitao > Cc: Andrew Morton > Cc: Yeoreum Yun > Cc: Baoquan He > Cc: stable@vger.kernel.org > Fixes: 108aa503657e ("arm64: kexec_file: try more regions if loading segments fails") > Signed-off-by: Jinjie Ruan > --- > arch/arm64/kernel/machine_kexec_file.c | 4 ++++ > 1 file changed, 4 insertions(+) Acked-by: Catalin Marinas