From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796328719; b=G4By54chgz0o5nwHQY8u1z6eqAZps4bZmEt8MQHuIh3005Mb3DQuqQgtFdr0uQvetgQ8 Qvu5iKI40XRvvHNDbaXYqQsvrvwJdcTGvwyws+2QjiEGObTFFWXcM3xHl6pKlXuO3A9l4 dDtqhPNnFpH9bPu/OP2XAwcDAQqpGOaK9FZkX5RDH4xehf3ayRJB6rcRDEU4Z237fdrC7 LOpryggg4T4KadNoDic7WB8Q0y/8gLO0UfOD/lRQFWKEYH3JBkKqRL6FIlnZHF1TPqe3e Yq6Reyg7Uqgh6JRn658d51H76lVvd246V0hXTIxAljvF2XeAgq+TarcjwkvDzx5BnFA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796328719; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=u9tzQaGszxQ8o3wmrSp6vG7IvUIBzRyG4seTV/8R57E=; b=Ja0iZOFjQU1JY76ba3uotjnnw53uSoV+7IctMY6Qi1f4s1xpnUNrmfdJrNg3dxSspiWQ ogBJoCwply47CO+SMWOMfVF0Blp9/b8JTkQqBuokuqQQdsmFVn3WAV4Inwv8fsxwPUBwk MHKxPRcL/q/c1WckqWFAmPZ3de3l4yJ2nkmsD8F59vnig0TBBOmNUCKL271errAVDc48q ETmOKcI25mFFECLGie+BDCT+h8Mdf5EKpeDYrTUCOptSu0/9BNVyFaAtNm+8s467gwA1W 2HYKwR7UWNIb1o8YNha/oKjaZJ8SQ4tpR97sKAEjTiI9k4xTP9lPqMikSeDi9YdcjUA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YeOW2LGy; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFB3B606A322 for ; Thu, 3 Dec 2026 20:11:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YeOW2LGy Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F0FF1F000C2 for ; Thu, 3 Dec 2026 20:11:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796328719; bh=u9tzQaGszxQ8o3wmrSp6vG7IvUIBzRyG4seTV/8R57E=; h=From:Subject:Reply-To:Cc:In-Reply-To:References:Date; b=YeOW2LGyqIhMH6FMFOPqMS75SkKZ/xB2ZnfxoAAJmIur4xXXjbIrys6V23IGsOn15 +/Pm5JTQx4cumc+D9zUo2vA8l95c/1GV4Dd6i88Hk91EEXEp94Ij0hgPE1FrvbuCvE HgF1dBYeERizY8cl9EEKKTVCcMTSKXUvPohGLyPQdnjxgyF0rDQWaOknBQtlu+nwCy R/i1i1uYQfFeRRqdifHQdETsgn7JFAHdJQSuj/iCfZO337/6Xh/9SO2PcQ4iWsgtHU lzYuLZ2/18suNms6RWJyKmDPxHFZ45QDIEJ9T0eL6oX83j0F3uYMe9mearIhXfTjLs WqDD/03QSskig== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] selinux: validate primary symbol count when loading policy Reply-To: sashiko-reviews@lists.linux.dev Cc: selinux@vger.kernel.org In-Reply-To: <179632334562.3849443.7476539692307740906@skku.edu> References: <179632334562.3849443.7476539692307740906@skku.edu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 20:11:58 +0000 X-Mailing-List: selinux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] selinux: nprim bound in policydb_read() still allows allocator warnings - [Medium] selinux: nprim size_check() in policydb_read() rejects valid v15-19 policies -- commit 73282705b94805b2c857b96c5fb8c6592be5a8da Author: Kyuwon Cho selinux: validate primary symbol count when loading policy This commit adds a size_check() in policydb_read() to bound each symbol table's primary symbol count against the remaining policy image size. > diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policyd= b.c > index b75c977c6673d..27437fc1e4797 100644 > --- a/security/selinux/ss/policydb.c > +++ b/security/selinux/ss/policydb.c > @@ -2904,6 +2904,12 @@ int policydb_read(struct policydb *p, struct polic= y_file *fp) > goto bad; > nprim =3D le32_to_cpu(buf[0]); > nel =3D le32_to_cpu(buf[1]); > + rc =3D size_check(sizeof(u32), nprim, fp); > + if (rc) { > + pr_err("SELinux: symbol table %u has an invalid primary symbol count= %u\n", > + i, nprim); > + goto bad; > + } > =20 > /* every read_f() implementation reads at least 128 bytes > * for any valid entry [Severity: Medium] Can a malformed policy with zero symbol entries still trigger allocator warnings with this bound? sel_write_load() accepts multi-megabyte images via vmalloc(), so a ~2.1 MiB padded image with nel =3D=3D 0 passes this check with nprim =3D 524289. Bo= th policydb_index() (class/role/user_val_to_struct) and cond_init_bool_indexes() (bool_val_to_struct) use contiguous kzalloc_objs(). On 64-bit, 524289 pointers exceeds 4 MiB and hits the MAX_PAGE_ORDER warning in alloc_order_allowed() because kzalloc_objs() omits __GFP_NOWARN. The kvzalloc_objs()/kvcalloc() calls for type_val_to_struct, sym_val_to_name, and type_attr_map_array also omit __GFP_NOWARN and still warn above INT_MAX. Switching those kzalloc_objs() arrays to kvzalloc_objs()/kvfree() and adding __GFP_NOWARN to the policy index allocations would prevent these warnings. [Severity: Medium] Will this check falsely reject valid version 15-19 policies when SYM_TYPES has unserialized type attributes? Below POLICYDB_VERSION_BOUNDARY (24), type attributes increment p->p_types.nprim without being serialized in SYM_TYPES. For versions 20-23, policydb_read() later reads one ebitmap per type into type_attr_map_array, so the remaining image still holds at least 12 bytes per nprim. For versions 15-19 (below POLICYDB_VERSION_AVTAB), policydb_read() skips reading type_attr_map_array from fp, so those attributes occupy zero bytes anywhere in the remaining image. A compact v15-19 policy where sizeof(u32) * p->p_types.nprim exceeds fp->len will fail to load with -EINV= AL. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179632334562.384944= 3.7476539692307740906@skku.edu?part=3D1