From nobody Thu Apr 2 18:49:14 2026 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 22D3036E482 for ; Fri, 27 Mar 2026 03:33:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774582422; cv=none; b=b3pn+oIiDsmA2lHstXZf+bP9mOl0NXevzYjhEEg4gre/GxYWQ3GuoMKE5KsS/ZfnFMKCTOAeLSBSnTNMOzZowyW67WWi9e7E0fcWLY7xBjZLzFx/4LrtOfzXAIp04Lco4KI6R3ku3LX+nU40+Hn/Vkym1ZlbKzusr1o+tNNxmzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774582422; c=relaxed/simple; bh=wAWOJdQ2lJZNDFwBbLTs3uK2E6jcDIXtd9lK4m5SsE8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lOuzV3FJBBMltRQTmNyyJS74W8lHGxb3BgtiBxpDslvVG4w/1Z+hAWKAp5zSJyXvrGug9qEHVUxcH2GYSKgFxHWRdWGw4QFkyWU//AUAX6+Au6evIdFIRxzm9Q32O5zSvQGuZjyh70lM8gJLA8xA7lItjDFUU2pTjEd6R71i1bs= 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=O8WBD9CV; arc=none smtp.client-ip=209.85.219.43 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="O8WBD9CV" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-89a1347051aso26279026d6.2 for ; Thu, 26 Mar 2026 20:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774582420; x=1775187220; 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=4wsuYjjRM0hOSuiSmqKTO5rWSTT9azGBUD//zIgxv50=; b=O8WBD9CV5YtvJHfiyAnWxR7fK0Erjyq9gAdHLfmZxzGFes9VFX8L33gnImZOZAg7wT wPIqJL3QW/8qHGMcJFuSuAryGmMS3OrVDfLn0OQAYPYGP8Goi03zGWYmkEX2Ib6CuKno RHfCHyIIBJMe8uj0Y9m1xS14WHBLBLHQDsaGhxFtzMucXh/UPycMpHR2ZfKeV22RMmo3 nNyNPKXahAt5Nhj+cMb2goZ6n+ucsuz8TQWPrH9pLj/m3japzNcMeIMPfIfFN53kA41Y XGLuqJl0nnkyeU0QqcFNIaTWi1uyZ40jjzNGIycwosLN67SbwZNhgNQXkAcemlTgcL6r 0wRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774582420; x=1775187220; 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=4wsuYjjRM0hOSuiSmqKTO5rWSTT9azGBUD//zIgxv50=; b=ILeDYWFezMi8L91w7LzvP/RIrAISEyTfJpMn+vst6TDVCIVNNqHcVnRcNlQ4R/pwAA Cdd8p0ss9EKYh2dutLVOT6PtK42xEu6VRRHmDzHvVkqv794RYWDKLvOxs/mqRNQ+LGo1 C0D+96tiDen1MKVEzzfiI3mQle7Y6y6q70Uje8sLhXl+dqHS5kQ7D48edeLOp1EdOrnM QM3OpPIxPGq/74QOSAgvjAwcrg26sGKOgDp2MarCMxM970XXBeXgrdSSnW594Zn3hCRo lNDo3R4/3amg/SeC446qH3fOXxfpWyQQimJmiZEzsdbyrsWk+QMUnZbGPTsj/mUYiOz0 Gitg== X-Forwarded-Encrypted: i=1; AJvYcCVNp6od4/LoMtF1034Wmlb2Hj0WwgJin2EqSq7WMpbh2gTGruAAiVhzqd9q7DGc1LRXFr9kE9S+ntpvkfg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1cHceMMQY7OlWxglJADE48bPP3iukJ8agCpIqf40WIW8P6Kyi VJAuGGLykMlLQAhCgOErzxLHNR71uTfdXyZBf5gcSo+y5FiAvaqV6/Fbvdg2Xd4Vluw= X-Gm-Gg: ATEYQzwg5lHPeIsyl70QLo94rmUtGAIins77yX5hAPTChqBs5R2qaX6UuOJQ/f5bcOa EgulAD9z+GK49ZOPXRm9FuhauWkXEHRkzdr2PR7kfdmHMAoJJOL1C+1F53vAQUJW3dPH3cPUTOF gEW3leVSl7A+XgEcUZTpgOAWCWt5GO+zj01zFBY77G3DUImia9D7T/6lgby0Dq+6Hs5GbmTWw4x a1Vdf+dKRdHfh0klWLo7FYYs7PT48otWr9wFzThkM1f1GAiHr43XxHh6XVexrmluuaWex4Ik3lC LjbOX+FvzZnPP5TTvd1HjIOTr2Y8qAUV/V6m2pnsdgPnPiWG5qbeHKYAJD6/xzoE4bPDasauUJG 9k2tva/zkx8sCXFeYdZvtU4c3uVwjBjz7RUni0ZFQ7hhsp001nuOxmr1MlSBui17tYplR35a3/9 a5zKujaOyoEUH5ELE1X3i2ig4Hm7tavOuOIBz1s+Soo6pv6hCQqbLDusHXv7sLowXHrw== X-Received: by 2002:a05:6214:2f0a:b0:896:f47e:fd53 with SMTP id 6a1803df08f44-89ce8d15897mr12694906d6.17.1774582420090; Thu, 26 Mar 2026 20:33:40 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89cd5a22711sm46519186d6.27.2026.03.26.20.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 20:33:39 -0700 (PDT) From: Pasha Tatashin To: rppt@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 03/10] liveupdate: Protect file handler list with rwsem Date: Fri, 27 Mar 2026 03:33:27 +0000 Message-ID: <20260327033335.696621-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260327033335.696621-1-pasha.tatashin@soleen.com> References: <20260327033335.696621-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" Because liveupdate file handlers will no longer hold a module reference when registered, we must ensure that the access to the handler list is protected against concurrent module unloading. Utilize the global luo_register_rwlock to protect the global registry of file handlers. Read locks are taken during list traversals in luo_preserve_file() and luo_file_deserialize(). Write locks are taken during registration and unregistration. Signed-off-by: Pasha Tatashin Reviewed-by: Pratyush Yadav (Google) --- kernel/liveupdate/luo_core.c | 6 ++++++ kernel/liveupdate/luo_file.c | 22 +++++++++++++++++----- kernel/liveupdate/luo_internal.h | 2 ++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index dda7bb57d421..f9ae9364a962 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,11 @@ static struct { u64 liveupdate_num; } luo_global; =20 +/* + * luo_register_rwlock - Protects registration of file handlers and FLBs. + */ +DECLARE_RWSEM(luo_register_rwlock); + static int __init early_liveupdate_param(char *buf) { return kstrtobool(buf, &luo_global.enabled); diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index a6d98fc75d25..4aea17a94b4f 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -277,12 +277,14 @@ int luo_preserve_file(struct luo_file_set *file_set, = u64 token, int fd) goto err_fput; =20 err =3D -ENOENT; + down_read(&luo_register_rwlock); list_private_for_each_entry(fh, &luo_file_handler_list, list) { if (fh->ops->can_preserve(fh, file)) { err =3D 0; break; } } + up_read(&luo_register_rwlock); =20 /* err is still -ENOENT if no handler was found */ if (err) @@ -777,12 +779,14 @@ int luo_file_deserialize(struct luo_file_set *file_se= t, bool handler_found =3D false; struct luo_file *luo_file; =20 + down_read(&luo_register_rwlock); list_private_for_each_entry(fh, &luo_file_handler_list, list) { if (!strcmp(fh->compatible, file_ser[i].compatible)) { handler_found =3D true; break; } } + up_read(&luo_register_rwlock); =20 if (!handler_found) { pr_warn("No registered handler for compatible '%.*s'\n", @@ -851,32 +855,36 @@ int liveupdate_register_file_handler(struct liveupdat= e_file_handler *fh) if (!luo_session_quiesce()) return -EBUSY; =20 + down_write(&luo_register_rwlock); /* Check for duplicate compatible strings */ list_private_for_each_entry(fh_iter, &luo_file_handler_list, list) { if (!strcmp(fh_iter->compatible, fh->compatible)) { pr_err("File handler registration failed: Compatible string '%s' alread= y registered.\n", fh->compatible); err =3D -EEXIST; - goto err_resume; + goto err_unlock; } } =20 /* Pin the module implementing the handler */ if (!try_module_get(fh->ops->owner)) { err =3D -EAGAIN; - goto err_resume; + goto err_unlock; } =20 INIT_LIST_HEAD(&ACCESS_PRIVATE(fh, flb_list)); INIT_LIST_HEAD(&ACCESS_PRIVATE(fh, list)); list_add_tail(&ACCESS_PRIVATE(fh, list), &luo_file_handler_list); + up_write(&luo_register_rwlock); + luo_session_resume(); =20 liveupdate_test_register(fh); =20 return 0; =20 -err_resume: +err_unlock: + up_write(&luo_register_rwlock); luo_session_resume(); return err; } @@ -910,16 +918,20 @@ int liveupdate_unregister_file_handler(struct liveupd= ate_file_handler *fh) if (!luo_session_quiesce()) goto err_register; =20 + down_write(&luo_register_rwlock); if (!list_empty(&ACCESS_PRIVATE(fh, flb_list))) - goto err_resume; + goto err_unlock; =20 list_del(&ACCESS_PRIVATE(fh, list)); + up_write(&luo_register_rwlock); + module_put(fh->ops->owner); luo_session_resume(); =20 return 0; =20 -err_resume: +err_unlock: + up_write(&luo_register_rwlock); luo_session_resume(); err_register: liveupdate_test_register(fh); diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_inter= nal.h index 8083d8739b09..4bfe00ac8866 100644 --- a/kernel/liveupdate/luo_internal.h +++ b/kernel/liveupdate/luo_internal.h @@ -77,6 +77,8 @@ struct luo_session { struct mutex mutex; }; =20 +extern struct rw_semaphore luo_register_rwlock; + int luo_session_create(const char *name, struct file **filep); int luo_session_retrieve(const char *name, struct file **filep); int __init luo_session_setup_outgoing(void *fdt); --=20 2.43.0