lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <EE1CE61DFCF2C98F+20250210031827.25557-1-chenlinxuan@uniontech.com>
Date: Mon, 10 Feb 2025 11:18:27 +0800
From: Chen Linxuan <chenlinxuan@...ontech.com>
To: Tejun Heo <tj@...nel.org>,
	Josef Bacik <josef@...icpanda.com>,
	Jens Axboe <axboe@...nel.dk>
Cc: Chen Linxuan <chenlinxuan@...ontech.com>,
	Wen Tao <wentao@...ontech.com>,
	cgroups@...r.kernel.org,
	linux-block@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH] blk-cgroup: validate alloc/free function pairs at the start of blkcg_policy_register()

Move the validation check for cpd/pd_alloc_fn and cpd/pd_free_fn function
pairs to the start of blkcg_policy_register(). This ensures we immediately
return -EINVAL if the function pairs are not correctly provided, rather
than returning -ENOSPC after locking and unlocking mutexes unnecessarily.

Co-authored-by: Wen Tao <wentao@...ontech.com>
Signed-off-by: Wen Tao <wentao@...ontech.com>
Signed-off-by: Chen Linxuan <chenlinxuan@...ontech.com>
---
 block/blk-cgroup.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 9ed93d91d754..81c166ee003b 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1727,6 +1727,14 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 	struct blkcg *blkcg;
 	int i, ret;
 
+	/*
+	 * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and policy
+	 * without pd_alloc_fn/pd_free_fn can't be activated.
+	 */
+	if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
+	    (!pol->pd_alloc_fn ^ !pol->pd_free_fn))
+		return -EINVAL;
+
 	mutex_lock(&blkcg_pol_register_mutex);
 	mutex_lock(&blkcg_pol_mutex);
 
@@ -1740,14 +1748,6 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 		goto err_unlock;
 	}
 
-	/*
-	 * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and policy
-	 * without pd_alloc_fn/pd_free_fn can't be activated.
-	 */
-	if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
-	    (!pol->pd_alloc_fn ^ !pol->pd_free_fn))
-		goto err_unlock;
-
 	/* register @pol */
 	pol->plid = i;
 	blkcg_policy[pol->plid] = pol;
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ