From nobody Tue Apr 7 02:55:51 2026 Received: from mail-yx1-f52.google.com (mail-yx1-f52.google.com [74.125.224.52]) (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 D68E915B998 for ; Tue, 17 Mar 2026 02:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773715857; cv=none; b=mCMl1ZdtJ0pOkcR3sIV5+njXnWpzi2B/yDgpT3c6Ea7uey0ypbrfU4sJWRf1r+kz5AALMpGjvOT2ELoqzU3b4hY8Skj0HWyEJht2+uarj+qttH7CuPZvVKuNmIk8jWL3Y3m2racikqG5RcAGDffYA0dzRr9v24KxZpSIwxJxUX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773715857; c=relaxed/simple; bh=Ev5NOOaLCTI0R2tSGGS3VlAUiQ39CSjOS/qrd80m92E=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cwGPl8aT+jhhdIhCEstt+1ZOnbon8mi6fX+WxATJPVISTj4hAzrIRkU2mo+79Ne3r/NDJYUDVpBUjqcIVW1WywrbgGzqFmXsmVRfwAWfCdE6H/6VpkSe8qTd6NHsmVnNLDKxbos1HG4UPTKR55toPoW9qS2igfV9lRDG2py4rSE= 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=Zznyh+69; arc=none smtp.client-ip=74.125.224.52 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="Zznyh+69" Received: by mail-yx1-f52.google.com with SMTP id 956f58d0204a3-64acd19e1dfso4951892d50.0 for ; Mon, 16 Mar 2026 19:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1773715855; x=1774320655; 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=lSH13KJcmbIwWK3JLHjAk43mNZH52hkh+lGVSi7g5tY=; b=Zznyh+69cZVnbacReyCeZENb+dQTEqRAV30iHUfyklR7ZkfcD9MCbEdAoZpNBhuxjP bS3+9gYHvgM+/ZwwTrvmLhrZQsIkaZKGjj0LyEiU6ItvZ4CcBqe4UnYaIu+tcah50Kqv 8IYD0AdQUAdHJILEWbuPnf1EQX0lBQ6Y3se6mz9R6RQCn7P36W2PaEJEJUpjgJ9dKxnn N4/PqXPyXCgla0LqEtHJreHec2mq4ItF510EUuNoMLwJs5pqRx4v/puCD3H0dDUu0Q7s lHx+tIJfPJtrB8TQHr6EWzUU8Mw5Je/Sf4pQIpYH5MlAQy3K3e4cJ4yayxUqUFLq+A0Y 4gkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773715855; x=1774320655; 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=lSH13KJcmbIwWK3JLHjAk43mNZH52hkh+lGVSi7g5tY=; b=gUUzpJqfze4WzF8R7D63aCIxN195aW9x/BhPTloO2GFEncfOk8R+zLwjdKVfl7OtD5 qu8RaqLQBLVJcKIdUvynjOrFcNEqehfkMeseSaB80mbM31EyyAsn/LimKDM810h+9q+6 Z60U53P5A7AMxJNSKw3WuH78UnjBuUdFTkJtrs2qFRh7L+kCiDUAICjBBm1EdoJ3gX54 jwSP16w/AP32Mb2NJF4SvO54ejuKWyUgqKqofmwEEGiNK6kHq49WqcpDz7RrhuIxkbo6 w1+HMZQ4o5MuA2PojWYs9QOUVQYSqxxalFMPxDbY2742F/F57gqudEz4BCjJAgTAA4tb kBjw== X-Forwarded-Encrypted: i=1; AJvYcCVhdeGWbTAGpbeFSFp/9LxmmEhiVQ2p1Rr8uUR8xE1fcoNEUhiqi8ww7XR+ex93asCYAdNGieWzobXJ24Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxdK9gylS9UQApEtr4oDh6+1nJDRoXsw4QTYKUhHjZiC7o6MsMC nDUSy+iJRAlKk5mNUohyIf8T20zvqs/FRmjMpAm2bWzZ5qOAxJkDk61kYKesqLuUSX0= X-Gm-Gg: ATEYQzxQI/9KLGnKUIxxw7O8Q5rT4QhDbxWrEl1s1z7byEkUi/Xy00yQkSGA/R/AZRE HC+XYy94HsGflSZe8os30R9dpH9r7qFOEYv+2zuPQu+jEs17cLXjNKmo5yKrKessQUX/xOETNo3 K/1pF3mHTg2Of+C10zZsXvTrmHPV7P5t12bi2ALSn5MvFSUqdHmBDelMguaSotJiPl2RbUoUBgL MqWWldO1HzRoCVAxVya9hubjFki1H6JvqcJoQHNyHwCFLQiIJhwe4MvmXa+HlY2lzXGTeATp2kF wweP0aYIDQsOjZnAlRST1p10z1Bys7oA7hXw1DNslB47GfK/uLD81+Vb7NiQZ7LA0GRyvRcEdi9 eiFcTeT8wXO/T7jY8vBKEjbXw9HdoR8amS5ySBj12TpOR+nEz2MXTlnKqYS6/39RjdJtQW8lt0Q ioBbNd9Ah2+1sLcDy7+DMYXVXxwiqDYpImd2LCHL9GceNrM743xKxmTFIVRuz0fDlz2K8NSSQoj ZT5284hfPqtayTEc0QD5sLq/ZUAZ5jjpf5TZkZ8/MPTguZGMw== X-Received: by 2002:a05:690c:288:b0:797:4722:f8a7 with SMTP id 00721157ae682-79a1c26723bmr151441587b3.61.1773715854973; Mon, 16 Mar 2026 19:50:54 -0700 (PDT) Received: from soleen.c.googlers.com.com (57.233.150.34.bc.googleusercontent.com. [34.150.233.57]) by smtp.gmail.com with ESMTPSA id 00721157ae682-79a5a866c85sm14951757b3.35.2026.03.16.19.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2026 19:50:54 -0700 (PDT) From: Pasha Tatashin To: pasha.tatashin@soleen.com, rppt@kernel.org, pratyush@kernel.org, linux-kernel@vger.kernel.org, dmatlack@google.com, akpm@linux-foundation.org, linux-mm@kvack.org Subject: [PATCH 1/6] liveupdate: Protect file handler list with rwsem Date: Mon, 16 Mar 2026 22:50:44 -0400 Message-ID: <20260317025049.494931-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog In-Reply-To: <20260317025049.494931-1-pasha.tatashin@soleen.com> References: <20260317025049.494931-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 eventually no longer hold a module reference when registered, we must ensure that the access to the handler list is protected against concurrent module unloading. Signed-off-by: Pasha Tatashin --- kernel/liveupdate/luo_file.c | 61 +++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index 5acee4174bf0..6a0ae29c6a24 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -112,6 +112,7 @@ #include #include "luo_internal.h" =20 +static DECLARE_RWSEM(luo_file_handler_lock); static LIST_HEAD(luo_file_handler_list); =20 /* 2 4K pages, give space for 128 files per file_set */ @@ -277,10 +278,12 @@ int luo_preserve_file(struct luo_file_set *file_set, = u64 token, int fd) goto err_fput; =20 err =3D -ENOENT; - list_private_for_each_entry(fh, &luo_file_handler_list, list) { - if (fh->ops->can_preserve(fh, file)) { - err =3D 0; - break; + scoped_guard(rwsem_read, &luo_file_handler_lock) { + list_private_for_each_entry(fh, &luo_file_handler_list, list) { + if (fh->ops->can_preserve(fh, file)) { + err =3D 0; + break; + } } } =20 @@ -777,10 +780,12 @@ int luo_file_deserialize(struct luo_file_set *file_se= t, bool handler_found =3D false; struct luo_file *luo_file; =20 - list_private_for_each_entry(fh, &luo_file_handler_list, list) { - if (!strcmp(fh->compatible, file_ser[i].compatible)) { - handler_found =3D true; - break; + scoped_guard(rwsem_read, &luo_file_handler_lock) { + list_private_for_each_entry(fh, &luo_file_handler_list, list) { + if (!strcmp(fh->compatible, file_ser[i].compatible)) { + handler_found =3D true; + break; + } } } =20 @@ -850,25 +855,27 @@ int liveupdate_register_file_handler(struct liveupdat= e_file_handler *fh) if (!luo_session_quiesce()) return -EBUSY; =20 - /* 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; + scoped_guard(rwsem_write, &luo_file_handler_lock) { + /* 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' alrea= dy registered.\n", + fh->compatible); + err =3D -EEXIST; + goto err_resume; + } + } + + /* Pin the module implementing the handler */ + if (!try_module_get(fh->ops->owner)) { + err =3D -EAGAIN; goto err_resume; } - } =20 - /* Pin the module implementing the handler */ - if (!try_module_get(fh->ops->owner)) { - err =3D -EAGAIN; - goto err_resume; + 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); } - - 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); luo_session_resume(); =20 liveupdate_test_register(fh); @@ -909,10 +916,12 @@ int liveupdate_unregister_file_handler(struct liveupd= ate_file_handler *fh) if (!luo_session_quiesce()) goto err_register; =20 - if (!list_empty(&ACCESS_PRIVATE(fh, flb_list))) - goto err_resume; + scoped_guard(rwsem_write, &luo_file_handler_lock) { + if (!list_empty(&ACCESS_PRIVATE(fh, flb_list))) + goto err_resume; =20 - list_del(&ACCESS_PRIVATE(fh, list)); + list_del(&ACCESS_PRIVATE(fh, list)); + } module_put(fh->ops->owner); luo_session_resume(); =20 --=20 2.53.0.851.ga537e3e6e9-goog