From nobody Fri Apr 3 17:47:36 2026 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 76C8336E470 for ; Mon, 23 Mar 2026 20:31:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774297910; cv=none; b=AHxKO22oskDctzHGIPaFIEB5GB9t4ON4MR92E5DJ13O5n9xHP1Y/HGK8zFjMBy87qzW33QCp4R2hlvV+GhKF/YOFfTZnFd98ipnZEuYS7TCPDgYZxgdNrGAjXm3+rs8k/+n3xIovWQJTRwrs3uGcQA1DpV3W1P0bjMSi4iaa3mQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774297910; c=relaxed/simple; bh=h/f8j6IJuYkI1ktQO+TMs/HB/IY4/aGXmmNR202EWLY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dO+JszoFjHK+3jTtyNGxndX8eqmlGkCyZCBfLzuXTMYEg6ZBnnXh/+b3SlHmrkX7uN60jGaFNuca7ONh9sSgo+YqJD226K468IoLtEOLcJN/xw2mYCvePAO3K4zVpHy7KFVZDYrDnZcoYswgbJL5WLgTWxWziuQzr08tOkRw89M= 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=WPbgS7q1; arc=none smtp.client-ip=209.85.222.176 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="WPbgS7q1" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-8cd90401034so51690585a.0 for ; Mon, 23 Mar 2026 13:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774297908; x=1774902708; 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=mp+NroOy4/hHawAvVZuOZcBwNbvsjzSVce/sSOrDnHI=; b=WPbgS7q1tHn5LhjucuO2HYkeIPuFEHk1NcHk31ofqr/q/899AYn5kv/6qdP1u84hBz xz5ln0FzHTK5yg8tVb1H/QBuusjw0T+T+DlPtD7wSf12wVwfpaJlwmDuYokiYC+y52Xj krpY8h4eFMam1mmsBGVez7GFgAtaAZNj4CuUdLrRf/rJisGtt5GIxsmh+3e739tIqrtX pIa0dnJ0aDRzs7y8aVBPWLvr0b9+YyKIgF+B1GO1khVMf1TPH1HSifZyWEaYCBTxRANR hTtxdCIw0cbGRCGD+9f1vMEme7jD8z9ouXDP+M9y/AR0dLjYIYjZAxDTWOVAJ4id2Ixm GTMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774297908; x=1774902708; 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=mp+NroOy4/hHawAvVZuOZcBwNbvsjzSVce/sSOrDnHI=; b=K06xrxB3huATVLS8DLPhqkhf3h6oNjcHTFh5SMdJu+5OfBfYqhH+wpPE045olO+JU/ XbVhrPgw/bRvlC8Jx8HyGUh+ExGZ4EqNIaGfSSEfkwPbIJBStSG9ge0dmA7Hs+Nm5VjY NUTCGIe2Hoh8KH5Yqe8YjtgEv3OKNM5z4eyFWlTgZVCBnfb8ZyeMPNwEdxd1fD2bVoN2 gdJ/+/x3Tk7fELe8/1HG/7NQktfFL8tvE62PtX7kMgW+2PAfP6kP5zAG46p5qjNxMwnP N5hiXhqivCMMOiZgM1OLwuq6j23HD4CtlXMkJ5eIRFWJPi9SlZzoThE5Fpk5N7ujb53y b0uw== X-Forwarded-Encrypted: i=1; AJvYcCXGUrONIBpIzGz9D5JWDJAYKThYVcVKD6GqQFg/TbkQRUnE4stb8powz0XIJJYPbpbjHiGC4C+YGtzpdz4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+hxIf6x0g1pKF51EqWKSYOTeiaztTLN/WIbT9/r+QhQLJv7sn RswQn1uHPfFynBBwpEjL355x8Tsc0RGShZyApKSJ20rpe37KZo0GJpDOVevrSpmsCSM= X-Gm-Gg: ATEYQzzyoHxv0zYCKPnYqHWIQ4nRVqTVUAQfRAH4EzjktHL50iVovjGvlNBKlDBtunR L9ALG24wv1HTcijQ0SVfiiqpT9rM8DUqq805nwxiAM3vP2/3OKB4HnC2KTI/fgrHQIAM0nGy9DC j2w8VvI7zMgh7cgNiI42t0HWyCEEux+vQMdr5xeBFp1gKH0FAsz72TkrSODkOYaTRUxGRky1yd1 9RwWmGewnSsmtgWTWpcS7GrcB4MQXlMiLd9M/nuN8YM0lGihNoBgDRCroTXxDBXodLk0cgI8FEa OH1LwE9m86uBkSA+sY2ZFzZqCbaghO+7JIv+Xub6okGIPvluDHAyjMe0HkZoxhZlNjlYkoMtu5X pIeuWULhlPHdgmIXDt2tsjUeTrSwAndf0L6QvEYLInRKB6lDb5ziSqRjjLPm6/77G7o8ml6+fh6 FRMQt6nA+DWVv6on1YEHhnuvSvMqXk8eJpQT++yuEem8JhO75LtrHsX1VF+HK0cpiimg== X-Received: by 2002:a05:620a:2802:b0:8cd:80f1:f468 with SMTP id af79cd13be357-8cfc7f49c3dmr2025158685a.41.1774297908246; Mon, 23 Mar 2026 13:31:48 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8cfc8fb9c10sm1014271785a.19.2026.03.23.13.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 13:31:47 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Subject: [PATCH v2 1/2] liveupdate: prevent double management of files Date: Mon, 23 Mar 2026 20:31:44 +0000 Message-ID: <20260323203145.148057-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260323203145.148057-1-pasha.tatashin@soleen.com> References: <20260323203145.148057-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" Currently, LUO does not prevent the same file from being managed twice across different active sessions. Use a global xarray `luo_preserved_files_xa` to keep track of file pointers being preserved by LUO. Update luo_preserve_file() to check and insert the file pointer into this xarray when it is preserved, and erase it in luo_file_unpreserve_files() when it is released. This ensures that the same file (struct file) cannot be managed by multiple sessions. If another session attempts to preserve an already managed file, it will now fail with -EBUSY. Signed-off-by: Pasha Tatashin Reviewed-by: Samiullah Khawaja --- kernel/liveupdate/luo_file.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index a38ea4975824..5f48c3c8c561 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -110,11 +110,15 @@ #include #include #include +#include #include "luo_internal.h" =20 static DECLARE_RWSEM(luo_file_handler_lock); static LIST_HEAD(luo_file_handler_list); =20 +/* Keep track of files being preserved by LUO */ +static DEFINE_XARRAY(luo_preserved_files_xa); + /* 2 4K pages, give space for 128 files per file_set */ #define LUO_FILE_PGCNT 2ul #define LUO_FILE_MAX \ @@ -249,6 +253,7 @@ static bool luo_token_is_used(struct luo_file_set *file= _set, u64 token) * Context: Can be called from an ioctl handler during normal system opera= tion. * Return: 0 on success. Returns a negative errno on failure: * -EEXIST if the token is already used. + * -EBUSY if the file descriptor is already preserved by another s= ession. * -EBADF if the file descriptor is invalid. * -ENOSPC if the file_set is full. * -ENOENT if no compatible handler is found. @@ -277,6 +282,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u= 64 token, int fd) if (err) goto err_fput; =20 + err =3D xa_insert(&luo_preserved_files_xa, (unsigned long)file, + file, GFP_KERNEL); + if (err) + goto err_free_files_mem; + err =3D -ENOENT; scoped_guard(rwsem_read, &luo_file_handler_lock) { list_private_for_each_entry(fh, &luo_file_handler_list, list) { @@ -289,11 +299,11 @@ int luo_preserve_file(struct luo_file_set *file_set, = u64 token, int fd) =20 /* err is still -ENOENT if no handler was found */ if (err) - goto err_free_files_mem; + goto err_erase_xa; =20 err =3D luo_flb_file_preserve(fh); if (err) - goto err_free_files_mem; + goto err_erase_xa; =20 luo_file =3D kzalloc_obj(*luo_file); if (!luo_file) { @@ -323,6 +333,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u6= 4 token, int fd) kfree(luo_file); err_flb_unpreserve: luo_flb_file_unpreserve(fh); +err_erase_xa: + xa_erase(&luo_preserved_files_xa, (unsigned long)file); err_free_files_mem: luo_free_files_mem(file_set); err_fput: @@ -366,6 +378,7 @@ void luo_file_unpreserve_files(struct luo_file_set *fil= e_set) luo_file->fh->ops->unpreserve(&args); luo_flb_file_unpreserve(luo_file->fh); =20 + xa_erase(&luo_preserved_files_xa, (unsigned long)luo_file->file); list_del(&luo_file->list); file_set->count--; =20 --=20 2.43.0 From nobody Fri Apr 3 17:47:36 2026 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (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 60C6B3E025D for ; Mon, 23 Mar 2026 20:31:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774297911; cv=none; b=URIyxXsNx176D4VMhEovCqOKu0vlg3OXlHtF9vBzFIvRYcUBxdNbdcHzGAYE5Okux+JTkEtnsvqR0ZdkTbCUGsXoN+ykOkZWUy1skRE2ueBytkzQJI2yJB+arxgd9s14H9T3ZZ5QhyjngbnSPipYkPQLopoK+7ikDN/oYUIEfS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774297911; c=relaxed/simple; bh=LI3SMXsnBn5nSeznTWFsUVVpxVDKbB9pJnDUUCkPN10=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mN1zkwe7I57n0+wM3EnWz8ejK4mJp/z86VDMyCtcEHS8aUd0v1oFSkmzLbt/8uN6sdBzFNE1XccrT1pJPScoCk6i5RdgC2EWeVN1j9YB0/+abJrdxIzQMVf1lF40sbsUlUEso6DTCRuSufm5ulpZJt6E5M3oujhcPAPcKfBWoOQ= 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=AhqGxn3N; arc=none smtp.client-ip=209.85.160.178 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="AhqGxn3N" Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-50335b926c2so4525421cf.2 for ; Mon, 23 Mar 2026 13:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774297909; x=1774902709; 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=Ob8Y//wo6MRj/M0Dz67mgrBX7aDHTN1F2suUDWyFSyU=; b=AhqGxn3NeinaN5xnp4M13fajPpek7zCWCOexIWv8Ud1lSvbHmvz3ePiUFttpiLyIrG CWDgh865IZ0/QMtBF7iuPSoj/+keNHnETZw5PmLspU6X/gbbrSyCaUXXYtzbPX2/UxeC hANSyiyEF3QrSLpM8bbEyRh1goPEycqh4YfGjrYivWZiR/4lffglcWqE6RM61nxdHoQr lNBbdCg1ZbdhA1Zxwsfrs0C7iZAzVhu149RMah2fFdommhY5QytVtSyDB/woTMQDw88s ngzEVgd+La0vQOv5j5zPNa67fpzcEKdW0KVYH36/hx/XMjrVeglDLXTDVCdxeHMrp64L DXzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774297909; x=1774902709; 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=Ob8Y//wo6MRj/M0Dz67mgrBX7aDHTN1F2suUDWyFSyU=; b=CLrqE0T440I6+IF+4aFYYJqcVT+cE3/y3oBOhj4XMPzFk5Oq9r4go6ViiHlSwyoXnC U8mvCcg9ti8wcc4i0Ooa1hWJE3AliKrzofQjDecwVmkHM8oGcTOW/q06TCIRT4uLlT4p c+vWkQw+RI4/kgh774QpHnCeQ5uQk64JovlmLZ5z/9x2MVi12gfvABsCK6vBfv42hLfI 8rH5jvJ+xRB5AS/mS4TJ88DZQK6JYa5w2b3eHVN69Zxz6d7F3BPzchQ9ocPj91Rl/dxl sgiA2ViBpcxlKKhYSDegqS7BdsyXfJcDasDDjLBg/UwbYDM4y4rw5UJVz9wAvWSjdk0X o9vg== X-Forwarded-Encrypted: i=1; AJvYcCVzrptA/NQtdNoCXuHnR8Nfr5DuTzrG0CDyooONVS/XAKIg5lAJIshWMnIyoWBnm0QU0dNf6ZFwtnY6G34=@vger.kernel.org X-Gm-Message-State: AOJu0YzRhekh+R4/WR2x7XGyHpwone/RFw7MFUddjqi8foci5JUPHao3 rMZ9GhWVi5GIDbiv0i2eQBLU2GvjBwheZTFNisuQOfY53iDq43ea3MgQD8Wq+Cgl0DU= X-Gm-Gg: ATEYQzxUv6xbOpgkXfajd2GZIbehdHJ+HyPWjTnuQ4hjMGl0hF4fsIpY0C3KyThRmYK Nstw9pPFwBKVH1C4nnBBG6PBiguUK7Lk+K2dUyzDvn9R6tmavFA3SRdVH7ZfSZZMN7CFEJZvXrL 6o0YIfvu7pgJy17EvkNj0vu7atsF7vgDmYvSxtf3LimrwWYpzAY9/DvSK0tst8oXzT7Unhg8XFD P4Xdnz6ZabXdx5eLx/VXmdeB9rbvKjR+KHJ/4ZjBL1cLg6JbRaplOBwU6jQtLsaKjLShl8qjkQ4 R/+nOphva7ALUvY7xrJqmkeUf1WZfCzdWq88D6Nux1HU2fWB9wbEawM6UmPF5cu8TbgGtM2P3nC ZMQTsT7/AssQw9tcGUi2Uy0l2xJYU3kRPHs1JAIPBqnNITfNawI/8ETgIr12y0iPjufT8SwQVvK nF78DNGHayV3KNkyssADjkejwFYKjVnKeRFHn3U1PU+HH3jBeZhHaMxLUOjHTxwiHu4iIXVhGBo lgL X-Received: by 2002:a05:622a:213:b0:50b:4bb6:d9b6 with SMTP id d75a77b69052e-50b4bb6e880mr132565441cf.32.1774297909339; Mon, 23 Mar 2026 13:31:49 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8cfc8fb9c10sm1014271785a.19.2026.03.23.13.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 13:31:48 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Subject: [PATCH v2 2/2] selftests: liveupdate: add test for double preservation Date: Mon, 23 Mar 2026 20:31:45 +0000 Message-ID: <20260323203145.148057-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260323203145.148057-1-pasha.tatashin@soleen.com> References: <20260323203145.148057-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" Verify that a file can only be preserved once across all active sessions. Attempting to preserve it a second time, whether in the same or a different session, should fail with EBUSY. Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Samiullah Khawaja --- .../testing/selftests/liveupdate/liveupdate.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testin= g/selftests/liveupdate/liveupdate.c index c2878e3d5ef9..37c808fbe1e9 100644 --- a/tools/testing/selftests/liveupdate/liveupdate.c +++ b/tools/testing/selftests/liveupdate/liveupdate.c @@ -345,4 +345,45 @@ TEST_F(liveupdate_device, preserve_unsupported_fd) ASSERT_EQ(close(session_fd), 0); } =20 +/* + * Test Case: Prevent Double Preservation + * + * Verifies that a file (memfd) can only be preserved once across all acti= ve + * sessions. Attempting to preserve it a second time, whether in the same = or + * a different session, should fail with EBUSY. + */ +TEST_F(liveupdate_device, prevent_double_preservation) +{ + int session_fd1, session_fd2, mem_fd; + int ret; + + self->fd1 =3D open(LIVEUPDATE_DEV, O_RDWR); + if (self->fd1 < 0 && errno =3D=3D ENOENT) + SKIP(return, "%s does not exist", LIVEUPDATE_DEV); + ASSERT_GE(self->fd1, 0); + + session_fd1 =3D create_session(self->fd1, "double-preserve-session-1"); + ASSERT_GE(session_fd1, 0); + session_fd2 =3D create_session(self->fd1, "double-preserve-session-2"); + ASSERT_GE(session_fd2, 0); + + mem_fd =3D memfd_create("test-memfd", 0); + ASSERT_GE(mem_fd, 0); + + /* First preservation should succeed */ + ASSERT_EQ(preserve_fd(session_fd1, mem_fd, 0x1111), 0); + + /* Second preservation in a different session should fail with EBUSY */ + ret =3D preserve_fd(session_fd2, mem_fd, 0x2222); + EXPECT_EQ(ret, -EBUSY); + + /* Second preservation in the same session (different token) should fail = with EBUSY */ + ret =3D preserve_fd(session_fd1, mem_fd, 0x3333); + EXPECT_EQ(ret, -EBUSY); + + ASSERT_EQ(close(mem_fd), 0); + ASSERT_EQ(close(session_fd1), 0); + ASSERT_EQ(close(session_fd2), 0); +} + TEST_HARNESS_MAIN --=20 2.43.0