From mboxrd@z Thu Jan 1 00:00:00 1970 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 8924A4A2A75; Mon, 31 Aug 2026 13:42:19 +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=1788183741; cv=none; b=qbyZNQpEJfzeceYcAs/fV+yoRD2OC9ABzRRln7ZPPnx8XimsIYpZcZ/RZlgN16pSmiV6ImRihnyc8xEOPsxKYMp+pFA0NP0nv2Nb+8dbzPFNWr6APF/7tYv41vOTw2ZgORNvUaDFinZjs6V7IlvLYuWX3MfadelevaZBuDcc+aw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788183741; c=relaxed/simple; bh=arCKM7ZbRklM9XVQCNOhhwY69fnnDX1FczzX0wzuv6A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qD7BiufVaQNmJnaKqW/Gdl6FmvXfG7sueVbKSryzwGq0YGk1K4SA055pQq2FVfuuBBhGyDVLG4wKNOrxPOBJe/iY9V4V0XLdTeL1aylmQiOyvtTn8ORt4hClkqj4y8/tHgYemDNAwtvu/UG3QHz0HhemfrH2/KKMwVJHbhUhDik= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=l4WiYEUN; 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="l4WiYEUN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5FEE1F00A3F; Mon, 31 Aug 2026 13:42:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788183739; bh=2ojUezFzDgJOXdB2/BWtvucSEdRDlhdJqA8O6ny+4LI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=l4WiYEUNE4VbetLgEtw19WB2zcDVPtX4iuPL6BJdd5nvv/5KOVglI8uPeS8qoidZ3 qhzS1vGN/jGcx1CTmFcZO+2G4RhbA5kxzFwCTRQbCF1d0VwwpOEtu6Wfpe/KQTLitN 7gKsXwK8WxewWrWZITF7IAAmzzpQy+x9a+8bdlLA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bryam Vargas , Stephen Smalley , Paul Moore , Wentao Guan , Sasha Levin Subject: [PATCH 7.1 09/76] selinux: reject a permission value exceeding the class permission count Date: Mon, 31 Aug 2026 15:33:41 +0200 Message-ID: <20260831133359.628596812@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260831133359.185608553@linuxfoundation.org> References: <20260831133359.185608553@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 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bryam Vargas [ Upstream commit d14b5d0e97fccd27974fedc03b903408872907fd ] perm_read() bounds a permission value by SEL_VEC_MAX but never by the nprim of the owning class or common, which is taken verbatim from the policy image. security_get_permissions() then writes perms[value - 1] into an nprim-sized kcalloc() array, so a class declaring fewer permissions than its largest permission value drives an out-of-bounds heap write. The top-level symbol tables are validated this way; the nested per-class permission table is not. Reject a permission whose value exceeds nprim, which is already set when perm_read() runs. Well-formed policies are unaffected. Cc: stable@vger.kernel.org Fixes: 55fcf09b3fe4 ("selinux: add support for querying object classes and permissions from the running policy") Signed-off-by: Bryam Vargas Acked-by: Stephen Smalley [PM: tweak comment for line length] Signed-off-by: Paul Moore (cherry picked from commit d14b5d0e97fccd27974fedc03b903408872907fd) Signed-off-by: Wentao Guan Signed-off-by: Sasha Levin --- security/selinux/ss/policydb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c index ef5bd0736748c..6f91f2bec80cc 100644 --- a/security/selinux/ss/policydb.c +++ b/security/selinux/ss/policydb.c @@ -1159,6 +1159,9 @@ static int perm_read(struct policydb *p, struct symtab *s, struct policy_file *f rc = -EINVAL; if (perdatum->value < 1 || perdatum->value > SEL_VEC_MAX) goto bad; + /* indexes an nprim-sized array in security_get_permissions() */ + if (perdatum->value > s->nprim) + goto bad; rc = str_read(&key, GFP_KERNEL, fp, len); if (rc) -- 2.53.0