From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=113.46.200.227 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796006134; b=QDLYgdFZUzWo3h33mGzOHF/W5xdgVh7WpBdNJhrKEtRyWz6rXQCnz88I1HCA8m4WBrC5 DyStsNSZPWReVhxIndM/+U/Y1/IMP13ZgKVA8soKLGvDRYNi6epMCb9asaY0NVxehQpFd E17t6rAMkSX1qf6Ei6MsAF2aEJG9AQXRPvRf42REUl8ZBXB1ABhNHkqPjIyuRHhn5Co/h oZvI9Ede7c3h9LIGrGx6s90EeC5E61kvmdOBKSAfw4mH0ezUEkZ+FM8uQVIXcge7H6W1w zgXoocbO8aJEsW7srytK4Ug9Apm3in5uFzd0Us7TyBc8I/1dykO9wq6R9s2aYL1cvpg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796006134; h=DMARC-Filter:dkim-signature:Received:Received:Received:From:To:CC: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=S2+GAWJu093KmsSX+p7Xa5DYqGY04zbqmyhRiBRhNQA=; b=lqsNo5LnlxE4EDkh9HKH5ZbVZJ9u4Ih5ZDNguQlv+Isu1Z9FdLGgiLhNxYwz1N5Vgc3/ npcNSyjmFd57FG2dPDD2FqKv8FlMW/2dnFi6TZdCvVKYkLh0uFxeQ2lktbdqITxElkrgn e+Y+RZ4OKg8AZr79IqC95VnK4Gb9S+Hd/IJ6G9WMYMAM58/Xe23oJ69MssQ+/zBP9YIyU BnXa15GtSBuaAtO0zr9FH3rJ9014DeQjNjE0DVJRLjUJh1Xd7RR9tuzu+NKDoQbwDtQ5y 5gwOdmHj0vSbhJmK/AarhAE/1+sAdXucC6libZppU3U8Me5B5sivTC3E1cWaEiOk7ag== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b="FoP+S/Zu"; arc=none smtp.remote-ip=113.46.200.227 Received: from canpmsgout12.his.huawei.com (canpmsgout12.his.huawei.com [113.46.200.227]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2148A606A31C; Mon, 30 Nov 2026 02:35:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2148A606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=FoP+S/Zu dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=S2+GAWJu093KmsSX+p7Xa5DYqGY04zbqmyhRiBRhNQA=; b=FoP+S/ZuUgZhkugJDKfGpPKJdLiOb7/sLhugz8VzW0r5yZvf1zD2eUrmRcL1Ggxbu1nf5oSNo oN+tNaSB5x1PKoeODmysqEG3iDjqciVhzCGBPrGyusX/zt47k4k4N53kn/6G6ymsH00DcYKpOxs EIUqKWzwMUGNTecHH4ZlqLc= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4jd7QV6DRrznTZn; Mon, 30 Nov 2026 10:34:42 +0800 (CST) Received: from kwepemo200009.china.huawei.com (unknown [7.202.195.26]) by mail.maildlp.com (Postfix) with ESMTPS id 2ADFD40586; Mon, 30 Nov 2026 10:35:29 +0800 (CST) Received: from localhost.localdomain (10.50.159.234) by kwepemo200009.china.huawei.com (7.202.195.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Mon, 30 Nov 2026 10:35:28 +0800 From: Long Wei To: , , CC: , , , , , , , Long Wei Subject: [PATCH v2 1/2] mm: memfd_luo: pick up seals added after preserve at freeze Date: Mon, 30 Nov 2026 10:32:46 +0800 Message-ID: <20261130023247.2728481-2-longwei27@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130023247.2728481-1-longwei27@huawei.com> References: <20261130023247.2728481-1-longwei27@huawei.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemo200009.china.huawei.com (7.202.195.26) A seal added to a memfd after the memfd was preserved with a liveupdate session is accepted without any error, but once the kexec handover is over the retrieved memfd no longer has it: the change silently disappears instead of being rejected. memfd_luo_preserve() snapshots the file seals into the serialized state, but userspace may keep operating on the memfd until the handover, by design, so the preserve-time snapshot is naturally incomplete: a seal can be added at any point in the window between preserve() and kexec. memfd_luo_freeze() only re-read the file position and retrieve() replays the frozen snapshot, so those window changes were never picked up. Freeze is the last point before kexec where they can still be sampled; there is no second chance after it. Re-read the seals at freeze time, mirroring the file position handling: freeze is the final snapshot point and changes made after it are not preserved. The new seal set is only revalidated when it actually diverged from the preserve-time snapshot, and the validation must fail here rather than at retrieve(): while the old kernel is still in control the live update can still be aborted, but after the handover a seal that memfd_luo_retrieve() cannot replay would already be past the point of no return. Fixes: 8a552d68a86e ("mm: memfd_luo: preserve file seals") Signed-off-by: Long Wei --- mm/memfd_luo.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c index 6b68220275eb..08524125475e 100644 --- a/mm/memfd_luo.c +++ b/mm/memfd_luo.c @@ -54,6 +54,9 @@ * File seals set on the memfd are preserved and re-applied on restore. * Only seals known to this LUO version (see ``MEMFD_LUO_ALL_SEALS``) may * be present; preservation fails with ``-EOPNOTSUPP`` otherwise. + * Seals added after preserve are picked up when the file is frozen for + * kexec. Freeze is the final snapshot point: like the file position, + * changes made after it are not preserved. * * Restrictions * ============ @@ -322,7 +325,9 @@ static int memfd_luo_preserve(struct liveupdate_file_op_args *args) static int memfd_luo_freeze(struct liveupdate_file_op_args *args) { + struct inode *inode = file_inode(args->file); struct memfd_luo_ser *ser; + int seals; if (WARN_ON_ONCE(!args->serialized_data)) return -EINVAL; @@ -330,10 +335,28 @@ static int memfd_luo_freeze(struct liveupdate_file_op_args *args) ser = phys_to_virt(args->serialized_data); /* - * The pos might have changed since prepare. Everything else stays the - * same. + * F_ADD_SEALS takes inode_lock, so sample the seals under the same + * lock to get a consistent final value. f_pos is sampled here under + * the same inode_lock as preserve did; freeze is the last snapshot + * point for both. */ + inode_lock(inode); + seals = memfd_get_seals(args->file); + if (seals < 0) { + inode_unlock(inode); + return seals; + } + + if (seals != ser->seals) { + if (seals & ~MEMFD_LUO_ALL_SEALS) { + inode_unlock(inode); + return -EOPNOTSUPP; + } + ser->seals = seals; + } + ser->pos = args->file->f_pos; + inode_unlock(inode); return 0; } -- 2.43.0