From nobody Tue Dec 2 02:32:40 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C9502D7DEB for ; Tue, 18 Nov 2025 18:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763489899; cv=none; b=l3M804ecrvNjDvzK+49JT5mcxkWRedN3ad/8yk8IShE9MnRp6ubCosNqt1yJZxMzdKyi6HtYbQm2Yb7UUX4nM9HmVcG1ef/yXgzQvuHIQ/+QR68KMzQiQpyvsV1Lf4UDqk2G57pjdK8kdMVxBf+e/U7iJLkWQ8tSHITQmKllLqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763489899; c=relaxed/simple; bh=FWLUqOdMeWCRKRBg/ecVB9LXW/vLiI6Nwu+aIyQipT8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VofGhXcrGbXwR6xOFOp++uxk+LrcnZkAfwfuQEcoaq0//ylrUPI5QdfyBbIWRymaA+OONmor2+QAPwHOQXTspfOJcigTTgEj63EjvFGu+0nLcyDbzh4SF27RtCmZ2RXQEaQ4PAE67D0X+unb/oZudaP2AxjWj0xgeonhOyJZ4Ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hIjpsigb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hIjpsigb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15735C4CEF1; Tue, 18 Nov 2025 18:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763489898; bh=FWLUqOdMeWCRKRBg/ecVB9LXW/vLiI6Nwu+aIyQipT8=; h=From:To:Cc:Subject:Date:From; b=hIjpsigbCNnQYXYNp8d9ZiAyOO1Zwgsu9A+V1gdsHGNJLBYjlzdFAmsJyyIxCkIrc dyQx6yhhm3emDdwE8Zq+dJcSTcIJNvIGvlLMTjtw/BURzonlJqWGAoAEsXRLJC0ZYL dIh5QFwCOWleYdyi9USWnzQ94WEHzrewk/ggEEpK+4MTLdNpb6+VnEHGVd3DlyYsIA kXrRhIXQRXWPSEQa1gsGhn+lYj20u5z3jAcXU7WlsbQPltws8ptQp8VOoXjADjRtVS Dg8mUZrezNJApRZ0WpIOptUq95rvLeQPsPIP7d/CYSsHORCkQBD3VJ7OCehG1xyQ8G +gwgNphc5NjHA== From: Pratyush Yadav To: Andrew Morton , Alexander Graf , Mike Rapoport , Pasha Tatashin , Pratyush Yadav Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] kho: free already restored pages when kho_restore_vmalloc() fails Date: Tue, 18 Nov 2025 19:18:10 +0100 Message-ID: <20251118181811.47336-1-pratyush@kernel.org> X-Mailer: git-send-email 2.51.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When kho_restore_vmalloc() fails, it frees up the pages array, but not the pages it contains. These are the pages that were successfully restored using kho_restore_pages(). If the failure happens when restoring the pages, the ones successfully restored are leaked. If the failure happens when allocating the vm_area or when mapping the pages, all the pages of the preserved vmalloc buffer are leaked. Free all of the successfully restored pages before returning error. Fixes: a667300bd53f2 ("kho: add support for preserving vmalloc allocations") Signed-off-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 224bdf5becb68..515339fa526e0 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -1088,11 +1088,11 @@ void *kho_restore_vmalloc(const struct kho_vmalloc = *preservation) phys_addr_t phys =3D chunk->phys[i]; =20 if (idx + contig_pages > total_pages) - goto err_free_pages_array; + goto err_free_pages; =20 page =3D kho_restore_pages(phys, contig_pages); if (!page) - goto err_free_pages_array; + goto err_free_pages; =20 for (int j =3D 0; j < contig_pages; j++) pages[idx++] =3D page; @@ -1102,20 +1102,20 @@ void *kho_restore_vmalloc(const struct kho_vmalloc = *preservation) =20 page =3D kho_restore_pages(virt_to_phys(chunk), 1); if (!page) - goto err_free_pages_array; + goto err_free_pages; chunk =3D KHOSER_LOAD_PTR(chunk->hdr.next); __free_page(page); } =20 if (idx !=3D total_pages) - goto err_free_pages_array; + goto err_free_pages; =20 area =3D __get_vm_area_node(total_pages * PAGE_SIZE, align, shift, vm_flags, VMALLOC_START, VMALLOC_END, NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0)); if (!area) - goto err_free_pages_array; + goto err_free_pages; =20 addr =3D (unsigned long)area->addr; size =3D get_vm_area_size(area); @@ -1130,7 +1130,10 @@ void *kho_restore_vmalloc(const struct kho_vmalloc *= preservation) =20 err_free_vm_area: free_vm_area(area); -err_free_pages_array: +err_free_pages: + for (int i =3D 0; i < idx; i++) + __free_page(pages[i]); + kvfree(pages); return NULL; } base-commit: f0bfdc2b69f5c600b88ee484c01b213712c63d94 prerequisite-patch-id: f54df1de9bdcb4fe396940cdcc578f5adcc9397c --=20 2.47.3