From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9777230BB80; Tue, 12 May 2026 17:53:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778608399; cv=none; b=lM5S5WJ+GT6lMXjdI4j5ubb4qYoNh/Uwxjoc3Rt+bzGP6B5jAn28ermVNLW1xjJ0bmHebWfJGk9q4iJy0MDE3iJs2+Q1XVlvLk6aMRpjgrGJu2CDCj8QKBr48qy1yccmvg+m6/CXGTNK6ob+fRgs2tQJyiDCnxzy6nUU1JyTZYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778608399; c=relaxed/simple; bh=3MR/3sA1ayrUGRPTLsIYEB3ZL5JQHTwqvqjKqP2XxYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pIGWhAI7lr62PVF17wrshzbIYjcbFCF+GufzjKxl/EZKFYW0nnAc/gQjZsgjilb/DJ2GFYGpN9wo11M/MB3PjaENcZi0VYHY8b92vf2CMkvWZjFuY7mZl5ZJA6LHlOPslQeewlEcqPg0bcAfLrWCx9934RO2dFQ6Ert0DBP0tgc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wzRun2lq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="wzRun2lq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F23D1C2BCB0; Tue, 12 May 2026 17:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1778608399; bh=3MR/3sA1ayrUGRPTLsIYEB3ZL5JQHTwqvqjKqP2XxYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wzRun2lq4OI33Shk3EO0lVJ3dZLY0JXRY6Xnuw8RopBLIr1BqaixDLxUwNiXS2l0a UjRxW97AhK3Ld2yWuwLNedx1YMsZtLHkcwLWu7YEQRSrDydFxCZ9Y2GDvw1cm6LB+j QWWer4L0fEqHnrBcIVj7G1kiyXds9uYbgEbiONl8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stephen Smalley , Paul Moore Subject: [PATCH 6.18 063/270] selinux: shrink critical section in sel_write_load() Date: Tue, 12 May 2026 19:37:44 +0200 Message-ID: <20260512173939.778162205@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260512173938.452574370@linuxfoundation.org> References: <20260512173938.452574370@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stephen Smalley commit 868f31e4061eca8c3cd607d79d954d5e54f204aa upstream. Currently sel_write_load() takes the policy mutex earlier than necessary. Move the taking of the mutex later. This avoids holding it unnecessarily across the vmalloc() and copy_from_user() of the policy data. Cc: stable@vger.kernel.org Signed-off-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/selinuxfs.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -583,34 +583,31 @@ static ssize_t sel_write_load(struct fil if (!count) return -EINVAL; - mutex_lock(&selinux_state.policy_mutex); - length = avc_has_perm(current_sid(), SECINITSID_SECURITY, SECCLASS_SECURITY, SECURITY__LOAD_POLICY, NULL); if (length) - goto out; + return length; data = vmalloc(count); - if (!data) { - length = -ENOMEM; - goto out; - } + if (!data) + return -ENOMEM; if (copy_from_user(data, buf, count) != 0) { length = -EFAULT; goto out; } + mutex_lock(&selinux_state.policy_mutex); length = security_load_policy(data, count, &load_state); if (length) { pr_warn_ratelimited("SELinux: failed to load policy\n"); - goto out; + goto out_unlock; } fsi = file_inode(file)->i_sb->s_fs_info; length = sel_make_policy_nodes(fsi, load_state.policy); if (length) { pr_warn_ratelimited("SELinux: failed to initialize selinuxfs\n"); selinux_policy_cancel(&load_state); - goto out; + goto out_unlock; } selinux_policy_commit(&load_state); @@ -620,8 +617,9 @@ static ssize_t sel_write_load(struct fil from_kuid(&init_user_ns, audit_get_loginuid(current)), audit_get_sessionid(current)); -out: +out_unlock: mutex_unlock(&selinux_state.policy_mutex); +out: vfree(data); return length; }