From nobody Tue Feb 10 08:26:43 2026 Received: from mail-yx1-f44.google.com (mail-yx1-f44.google.com [74.125.224.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B84EC2DE1E3 for ; Fri, 14 Nov 2025 19:00:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; cv=none; b=fXGV/AnHEXjrcdQDKF03nxZf7v7/Tqs4QmXFg7k6W1mA5OwfZR2HnnPVq5pkBtHM33C4CHy9giM4y5GgxnWFbWcSYhyOZ9dLnv7K1zW9SoVmQ5moh7ydfJK3jcq21SwhL71K39DaHRduIQQLRaA39HH02jbsy5m/P1qyi1+PPdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763146821; c=relaxed/simple; bh=o0zvz+ex74fmsOkX2dx3qTlCtxsfWnru4svlJYsefQU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VlBYIFJ4xiZwklFvzJqeOv53NFmrleJqVq3bSnu3miphGQEQEh27SnEttZLezoKtN44+6EVZlqmj8r+mRlWUKI2PQzDcz6Bs+HKZEnzUjrt0UfNEl2Nv2WeO+uw7sSiIcCapq0Srtwuaqqlc+miuWW1eCS8Fb23OFI2PoRCX2vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=UuaJlWJT; arc=none smtp.client-ip=74.125.224.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="UuaJlWJT" Received: by mail-yx1-f44.google.com with SMTP id 956f58d0204a3-640c9c85255so2494773d50.3 for ; Fri, 14 Nov 2025 11:00:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1763146813; x=1763751613; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=l2RJjwQybqCNudNEQM/yW3I9X0XoWZDL8m1h5Nt8Pcs=; b=UuaJlWJT/r8dcPB0lZyVSHg/Kdv9czhrJCgMG0+fmSVNYTYHdGC8F24FlKNbSOwPaV 205hGZiSII3d5S+sc8/vS/bOjXCVZjbGVNT/P6SeeXUfNwVCMwBPyMUSZUHUj4f51GQ2 VYhgAez6jBr1q50ahXnISbNZXGCUk37SvGs5T5T4jHMbIBqHRLfu/BsB6fvB40Vhfiup A/q6cKBQ3UQCMIV86TZZpIU3MxtKRCPsVfxJmOSLaQ/Hd5vzsEvA+wVlebrjv4B/AF2m QSntWmfIEad52Q3JeIXtXqeGEmLVDjGkwOqXwvSe9wcEit2rVxViZULYl8BqGV+IvQz2 IHew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763146813; x=1763751613; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=l2RJjwQybqCNudNEQM/yW3I9X0XoWZDL8m1h5Nt8Pcs=; b=ntHhQcaBW0+KV8MeL6XVwwdSUU4816aQ+3oh5OagBUH93SMF8I9ZraNWKxYS5pfeq3 kjuGCSV0hNHz6y7TnlmL8oRLmuw2vg08IfEfZoo3paQQg0Ubw87ALmiIP0HiYP/N0ckQ xSKbPfGduCkiTpsadow2Q/kme0s+WWSUcRCtkVt/tEjZS0vxba65a/ASrW6LubxJKcDU ZUC7DFAtWusWd9G/d5VPmCjTRJdoBsKYz1m743v5PRUl255Zdmx7z8TT3P1bzSOuSeVk gu8gGs89DkSEx67pb2pEOlssop2PVyzCaxWHWFuC9qa3IhtdcdC0K0hkXuSeK7rt5jp8 qalw== X-Forwarded-Encrypted: i=1; AJvYcCX3Y4bHIa5A8QDpMAZGmAKsrbzGhU98fLNeIHId9xSuJBPnSxrNUBV02N8I5KI3eFynkobqApzkZUfJdsg=@vger.kernel.org X-Gm-Message-State: AOJu0YzZaCXZSPuPJ79Bw54R0yL8yE9UJ+yEuBfy8u/9iQ9MCETNAvL5 DRGmVbVSAq/yimNkaUONF3mXghG+WxIp5WgqRXjS0Shbrtmukot2uubULduYLGV9ddY= X-Gm-Gg: ASbGncsUVk1jJGS6ihJJeY284OLw1QM4LG+u57fr44s27i+t/LSV+LgZAyBKKErCJrr ZUxZlBxuQ0fFiGvYauj6QmNjf2skzMaxdfKMlMxQD7HFDxYrPFS/79rH7xH0bNCzu78jq62OyXB j49vFmTgtrFFQsoZqZKDHLGm2wIF64VxYFWHllvlKRTr2bgGNBWgo5vS4pnBcC6YOR3ORF/c1Lh Si9DqabKAORAUyV4/LGveBrzG9owhwAdM82s5JU5hwEDf3p7nGMygALbc4jaGJbf92ezkC0Jgme 1c1NKQCPFKIbFVmDhu0baDmk4bV3Ak59FbbH6QGb6N930qywYdOoy0BZyJMQ5QSgcfU4JDB8WAO TIZs48E2h/KJeMuT4BtSkzeY16zonD92kM2iI45BcBoOosE63kwdzLqXSeE2fVqL5w61BVETDhR vpiM4Qs+V+hhfj8NpH/n6txPrtJoKIN7m5F4tOkuzeDIPefJ7dQjxGwfQShDrHdgcilgfJ X-Google-Smtp-Source: AGHT+IELgQoKzNLiqxIk7OfyWTZZMKRkFfp9XFZAkA8ePupq0CHZkUurfOFSw9PuZ2noGq0xfhQIkw== X-Received: by 2002:a05:690e:42cf:b0:63e:1e80:99cb with SMTP id 956f58d0204a3-641e764225dmr2603590d50.34.1763146812573; Fri, 14 Nov 2025 11:00:12 -0800 (PST) Received: from soleen.c.googlers.com.com (182.221.85.34.bc.googleusercontent.com. [34.85.221.182]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6410e8f4f2esm2014058d50.0.2025.11.14.11.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 11:00:12 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, bhe@redhat.com, pasha.tatashin@soleen.com, rppt@kernel.org, jasonmiu@google.com, arnd@arndb.de, coxu@redhat.com, dave@vasilevsky.ca, ebiggers@google.com, graf@amazon.com, kees@kernel.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH v2 05/13] kho: Verify deserialization status and fix FDT alignment access Date: Fri, 14 Nov 2025 13:59:54 -0500 Message-ID: <20251114190002.3311679-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog In-Reply-To: <20251114190002.3311679-1-pasha.tatashin@soleen.com> References: <20251114190002.3311679-1-pasha.tatashin@soleen.com> 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" During boot, kho_restore_folio() relies on the memory map having been successfully deserialized. If deserialization fails or no map is present, attempting to restore the FDT folio is unsafe. Update kho_mem_deserialize() to return a boolean indicating success. Use this return value in kho_memory_init() to disable KHO if deserialization fails. Also, the incoming FDT folio is never used, there is no reason to restore it. Additionally, use get_unaligned() to retrieve the memory map pointer from the FDT. FDT properties are not guaranteed to be naturally aligned, and accessing a 64-bit value via a pointer that is only 32-bit aligned can cause faults. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover.c | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 704e91418214..bed611bae1df 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -18,6 +18,7 @@ #include #include #include +#include #include =20 #include @@ -451,20 +452,27 @@ static void __init deserialize_bitmap(unsigned int or= der, } } =20 -static void __init kho_mem_deserialize(const void *fdt) +/* Return true if memory was deserizlied */ +static bool __init kho_mem_deserialize(const void *fdt) { struct khoser_mem_chunk *chunk; - const phys_addr_t *mem; + const void *mem_ptr; + u64 mem; int len; =20 - mem =3D fdt_getprop(fdt, 0, PROP_PRESERVED_MEMORY_MAP, &len); - - if (!mem || len !=3D sizeof(*mem)) { + mem_ptr =3D fdt_getprop(fdt, 0, PROP_PRESERVED_MEMORY_MAP, &len); + if (!mem_ptr || len !=3D sizeof(u64)) { pr_err("failed to get preserved memory bitmaps\n"); - return; + return false; } =20 - chunk =3D *mem ? phys_to_virt(*mem) : NULL; + mem =3D get_unaligned((const u64 *)mem_ptr); + chunk =3D mem ? phys_to_virt(mem) : NULL; + + /* No preserved physical pages were passed, no deserialization */ + if (!chunk) + return false; + while (chunk) { unsigned int i; =20 @@ -473,6 +481,8 @@ static void __init kho_mem_deserialize(const void *fdt) &chunk->bitmaps[i]); chunk =3D KHOSER_LOAD_PTR(chunk->hdr.next); } + + return true; } =20 /* @@ -1458,16 +1468,12 @@ static void __init kho_release_scratch(void) =20 void __init kho_memory_init(void) { - struct folio *folio; - if (kho_in.scratch_phys) { kho_scratch =3D phys_to_virt(kho_in.scratch_phys); kho_release_scratch(); =20 - kho_mem_deserialize(kho_get_fdt()); - folio =3D kho_restore_folio(kho_in.fdt_phys); - if (!folio) - pr_warn("failed to restore folio for KHO fdt\n"); + if (!kho_mem_deserialize(kho_get_fdt())) + kho_in.fdt_phys =3D 0; } else { kho_reserve_scratch(); } --=20 2.52.0.rc1.455.g30608eb744-goog