Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 EE39325B0AA; Thu, 20 Aug 2026 15:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787239464; cv=none; b=sPF2tulsBhv03g4nBZ/DT5yWJBqMegs9Ow8HKe4M4RzD99MJ2eBZwe/XRLnt2PqBsx241Dtt7Kc6OrK5Wem52p/3m2OvIllhGCknXhNa48ujk/c2I+Wa4uA/10QT9UVFn58GgL1x97AdnsGMUgIMRc8jXREfOIlJ3NnyKwKuVeg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787239464; c=relaxed/simple; bh=dW+5MH0NtzlZTGGBOcq670utUYHFLwFSEod1creyYCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pV9P6Ua6oFnIBrEEu3dmTBqWOyVuWJvKhGFb6EDfoQBlXyEn5Uv1u5v9QuymO3hE9EW3U+92BZVB9OaTsKEAzDU7u1+AUnD2/zTMydJdy4wdKXShhJbyebDFd0YhLpEDtGHuRx/aKcLAzlBrxvyE8S6l76Yr9bdRx7in6V4vh4U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GCqnWVmv; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="GCqnWVmv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52AAB1F000E9; Thu, 20 Aug 2026 15:24:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787239462; bh=zuPj2jPRMxm9YTHCXYrflE5wTVMxoF+MyBuHHomaD1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GCqnWVmvAZczCHsxie/FepHFy5wjn2FPeFrnNX2URX6bcvDfdIPnws1VvtKCnh/x1 b+8hi9Ii/EeSyPdeDyIe6lWj7PY6sIF2HHYhGeWbtuq0snTijIueIji0top5zb7oDB bqO4v9olioPKZog5k9t7uQ0ri6ufe9bCCQp0kLOQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bryam Vargas , Stephen Smalley , Paul Moore Subject: [PATCH 6.12 018/220] selinux: do not cancel a policy conversion that never started Date: Thu, 20 Aug 2026 16:53:28 +0200 Message-ID: <20260820145224.051198148@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260820145223.480031205@linuxfoundation.org> References: <20260820145223.480031205@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bryam Vargas commit e5c0235a3c4e9eb047a16cd02323fe4ecf2f570e upstream. sel_write_load() calls selinux_policy_cancel() when sel_make_policy_nodes() fails, and that helper dereferences the outgoing policy to cancel its sidtab conversion. On the first policy load there is no outgoing policy: security_load_policy() returns early for that case, before it converts anything, and state->policy is still NULL. A first load that fails while building the selinuxfs tree therefore takes a NULL dereference in selinux_policy_cancel(), reached from a write(2) to /sys/fs/selinux/load. Skip the cancel when there is no old policy, mirroring the check security_load_policy() already makes before it converts. Cc: stable@vger.kernel.org Fixes: 02a52c5c8c3b ("selinux: move policy commit after updating selinuxfs") Signed-off-by: Bryam Vargas Acked-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/ss/services.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -2175,7 +2175,9 @@ void selinux_policy_cancel(struct selinu oldpolicy = rcu_dereference_protected(state->policy, lockdep_is_held(&state->policy_mutex)); - sidtab_cancel_convert(oldpolicy->sidtab); + /* a first load has no outgoing policy and converted nothing */ + if (oldpolicy) + sidtab_cancel_convert(oldpolicy->sidtab); selinux_policy_free(load_state->policy); kfree(load_state->convert_data); }