From nobody Fri Apr 3 23:09:22 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