From nobody Fri Apr 3 01:25:06 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