From nobody Fri Apr 3 01:29:46 2026 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (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 9418530BB91 for ; Wed, 25 Mar 2026 18:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774462832; cv=none; b=LwE3dWi3hwUxr0VC6b25QUjwGCn4SYcRpJZ6iPnBliOsB7+Mt2z0PVjeCYM50ZSiQfCWhhSFDZ5g/5m7RPP2TgL6dwMILJuWpVs3z7YV6m5FLdCJzzeybix3Kf/0RGVT9pwBVHewisDLz0Zggtx4GDIsFCbnABcCE07QOHUqn+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774462832; c=relaxed/simple; bh=rgpLpqZJLkucnhNPG0p5vGblP5wlFIaNzmXS/Hf4jzo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bLYruxiXig6sKlacLcMI+zo5BvfrGSDkOPcpgZcvNQAXUI6/CnFaBJA4bCjMa4E7pblDoG5WQB64fUS+j31sw4vwajLOnbJxaNJSZz2e16xNV8689+IwUGhyqRFiIBJv7p8zn684vpOegKpC0wI8MIWhEOaTl6OCN8f35ctNMjA= 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=TP3cUARc; arc=none smtp.client-ip=209.85.222.175 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="TP3cUARc" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-8cfd44fa075so29943785a.0 for ; Wed, 25 Mar 2026 11:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774462831; x=1775067631; 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=zLqludGATIl3hRiyxTIx0CjPLFsz0CkRWvUmhsLy2/k=; b=TP3cUARctAxZaBtW/+rGwA7xjU9Uo5ZIq6gAEr7hMzPvMqVzR/7IccGhsYiMmFQeAv fzwxoiW6YMEeUYDglYbNGPPl1uoGuDuBEfETkHDyjN9JGagZotWbV7xamtmXjbAVmryu b12YF7Nr75GGDfFLbwcsDQXBuXPnduG6d3MoQWYAs2p+Pie+xZsuhGGCrgwhwnVZhG39 2zilVmWH6oJNK9VZPPbF2oZOfSngoRujTnKzdAMAUzSr4hRbtiYe5B96SayioCPq8rBS Ze1rFqaqa/aIYO1PzakDA/BN0SKamfvdByimkYTL4KKJrfiTg7COe0gp6dkAkYituR6L pzaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774462831; x=1775067631; 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=zLqludGATIl3hRiyxTIx0CjPLFsz0CkRWvUmhsLy2/k=; b=YAAIqKZqiXS4xsHW+GyM0OZhfN+BdMybvIUJVAEX2R1wWsiOIli+B2mBjycmRlqJzZ P4jw9LJEDJbJY0shpHydJ3GnQKLPgI1/7t5dfR5/liCPdmIkgRwnWqfv2IMudqTU4t1i BbYC2a3Rbed0qE8ggbepOWXMkJcaL3g+Izee8oWphUKl4gzt4NVUKPgirNfY3LH3UK4+ 0mx7+Kd9EWR6YLFIB2P9VCuUF9z4LkhrjDI/pLf92mNY2IKnRs+SgEwoHutdPv8QE/oY neKQtErD25aap5oud4qHB5X9M9rbraewhREXKNLf5eWpUI4C+QYNWVj3A8r2/N2tuzRs 0zRw== X-Forwarded-Encrypted: i=1; AJvYcCUJUDtrWI8AY72cyZW92tY3I5fP1CTWTzMvTAOj1O8l2o2nnHHyQlRS6wV4vPZMFZl2y4uJ2sbuSONgA6w=@vger.kernel.org X-Gm-Message-State: AOJu0Yxbb/V+cme3/SuAqNBx3DGKGW0HU54r7YsnxCR7OvCk3QtOGxSI XVJltvnNuCazpmHliD9djyCElmX0hpr6uVfFalmhQhZPR+Ga/SShYnSsdcfo4/2tSBI= X-Gm-Gg: ATEYQzwRcf+x7lu12nYIPx7wYQYwQImXu72gK6d/NCVTjrX+Qco4Jtxz8PAY6jeqSsy ZoaSjVkMRo1O9unfRpm+7aa1YoSJW5DPmXMCKUk/6Ud9ClT/UZKhUbOWA1J6IGxqm2fYWsDEqG5 H/j1LllzlGOdaAsp+uJsc+K207WVP4GWPDKwllRwwNjYWKVGnd2K9L58bgasPLDm7eUn25bfGkf 3dtxKeqmTezvBeXAkv/yDIx2GKs3JizoykwKnlQOBJ1P6rY7adX1qx2dahZYKQg/mwn6TXwUJl2 SsysH/GJAxdwt1ADvLqmHIYVDuYUaPtotVGHhwQxF6S+iJAAm/KygWl6fY2iILgI6KaDuO4ExjD lXOiUAVc//EojepJKvfe8GvILJpt/Y1fKsVQKRtVIjSdKTGfIQwmb1MlH3HsLKweh0Pzx5ZTAXT 1oOj8G2tbpjrThl1CQlZnohClACAF9GHQaqWx4GU+2yEFdO/ZbbJKTmnlNw65vbVzU+g== X-Received: by 2002:a05:620a:4627:b0:8cd:7811:941c with SMTP id af79cd13be357-8d00103931amr629323885a.54.1774462830472; Wed, 25 Mar 2026 11:20:30 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e250556sm64225385a.0.2026.03.25.11.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 11:20:30 -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 v3 1/2] liveupdate: prevent double management of files Date: Wed, 25 Mar 2026 18:20:25 +0000 Message-ID: <20260325182026.467307-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260325182026.467307-1-pasha.tatashin@soleen.com> References: <20260325182026.467307-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 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. Acked-by: Pratyush Yadav (Google) Reviewed-by: Samiullah Khawaja Signed-off-by: Pasha Tatashin Reviewed-by: Mike Rapoport (Microsoft) --- kernel/liveupdate/luo_file.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index a38ea4975824..d1bb4213fd14 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); + /* 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, (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, (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, (unsigned long)luo_file->file); list_del(&luo_file->list); file_set->count--; =20 @@ -609,6 +622,10 @@ int luo_retrieve_file(struct luo_file_set *file_set, u= 64 token, luo_file->file =3D args.file; /* Get reference so we can keep this file in LUO until finish */ get_file(luo_file->file); + + WARN_ON(xa_insert(&luo_preserved_files, (unsigned long)luo_file->file, + luo_file->file, GFP_KERNEL)); + *filep =3D luo_file->file; luo_file->retrieve_status =3D 1; =20 @@ -704,8 +721,11 @@ int luo_file_finish(struct luo_file_set *file_set) =20 luo_file_finish_one(file_set, luo_file); =20 - if (luo_file->file) + if (luo_file->file) { + xa_erase(&luo_preserved_files, + (unsigned long)luo_file->file); fput(luo_file->file); + } list_del(&luo_file->list); file_set->count--; mutex_destroy(&luo_file->mutex); --=20 2.43.0 From nobody Fri Apr 3 01:29:46 2026 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 AA9CF31F983 for ; Wed, 25 Mar 2026 18:20:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774462834; cv=none; b=XALrnm40zBVyvMwmNkBXugpWS+lGRFBBdU9hk7Zdql3dH3KK8867Xg7yFFDzy/56gh94N+mTrUdQdjWQTpuWyNtCuwYy0stCY2IyymrfDdN/r6UfKqJLo1pfXgTTNQEQDboTVCQHLzjnM9bGzqGelNVEXAy2NKqzTTQ4tW7KBzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774462834; c=relaxed/simple; bh=GBazXh/uUV+veTugAXj7FLLeItvlURuuxUNZwTmoUrY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iARAl34R6LUUYlpWCFzgi1mz8+isG5nBdr1PX+zT7fIdN2ZH71XfTBWexXMhC1NJ6RDTssATcgI2YS51IvnNg23fUkidzlTQe9HDwKkGDxWr03hUaPl9cNQ2uMWNlwrwtRj4jeIyBwR7iwttg0NvLfkr7JBGgyjDio+bCck3XH0= 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=AnRg3aAb; arc=none smtp.client-ip=209.85.222.169 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="AnRg3aAb" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-8cfc3ca1922so116193885a.1 for ; Wed, 25 Mar 2026 11:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774462832; x=1775067632; 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=PHul+QGmCaYYH+cSj7r6hzl0Za0NZYfxsHk+JlDRO+k=; b=AnRg3aAb7+X+f9ButWL0knvC5TyGmEeeWeiozk8VwOFQ9PH9fkBBXTltpQKqBF+L2C dWys7Lq9dL7uN8EMXFBgZ//MyMaW274PQnhAmaXj0Jdij+5+3vvYVyWA60GoeJc90Mg3 KFmaN/BSQ+hoUNYG1pAdToaiXBS9xOdutDLpGKokUXaXp0WQAsSy4e1Mwn5MVNmV/UBk iK4KVkx1lJrCfqZHuFMNzDsiXy+HL+CK47zM5hRolfbtheWajAYcnjv81679Bh81Eu6b zNkTbouwjI3gxtCF+bCF3hmjD2XxI8UVezgn0ADd/5qCKIxfGnwAVk4O694DWbVESQWE 6YWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774462832; x=1775067632; 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=P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CZ+/m75BJTdMKW4mHY72SepIAzUO5Q4lvCXGins/0v7E9 +0kc3nfOWa1uxmbVooyOZ+B12KhKMps6g8jPQRRk0vXq7iQBJdaIkrAd7nbsHzWjrVQbLk1w/n+ NRW X-Received: by 2002:a05:620a:488d:b0:8cf:cc59:c0a0 with SMTP id af79cd13be357-8d0005ab522mr599385885a.27.1774462831645; Wed, 25 Mar 2026 11:20:31 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d00e250556sm64225385a.0.2026.03.25.11.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2026 11:20:31 -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 v3 2/2] selftests: liveupdate: add test for double preservation Date: Wed, 25 Mar 2026 18:20:26 +0000 Message-ID: <20260325182026.467307-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260325182026.467307-1-pasha.tatashin@soleen.com> References: <20260325182026.467307-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. Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Samiullah Khawaja Signed-off-by: Pasha Tatashin --- .../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