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=1796533262; b=haAGz1WX/AAVluYPJ45LrPKE3gDbQHMNLaowUcFaOdaUa+Kgn9BpoeMX3sLMEOMm2Qn9 yjd3WPZ8J+wIxMi6//Glz09fseZ048DY6aWbGzAREdC5CYdo1lljCduxkaPu2fUhHw2oB oh7+iYKLq7vkGF0ZgvyX81IA5vKsD3sIhR0TW3DMqzrelnLJNhddECQmb/9fTR5rSWQSe IeGwYRIILcHXvK405bC2aPEN7TTYunqunIPpvI5Yvi+pi5bi+lSg7r/FpQkzmfaM9VPG5 /t5zrM+2258rAjii1WAfj6I9EnO4dtCItHBezXCtTZFgT21yiWYIaXh/FS1ZBkKiTig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796533262; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=XbeSHgPIKvuHgKTQjGT9jHpxAxbX15vOtEQ8fsrdivI=; b=T99il7a5+iBZAh/aRmZcnHWLe843k+XV25QKyKuzcHtibY4G3GC98wi+IioAH43Y4V57 kh2wrAW+JY6jGpAF/5tX3+tdax0wSwiujeodn4IpsTKP9ABltsEjw4rEadrJ2/iqyLZJ2 IAAuVIErvOfyrYSWO1jc9Pcgmx4HO89Wz/1N4Eu5EJNtGUA2Fd7/QHNOl+rM5S1/f7U/r A3TkfNP3l5covH/WH3yipfGRnnMB6qFlrxqyR80awByjzvWp3tAon2zoLKJCd81AHAFMh uYn9W41u+iCbmipZQ7DPqn+mIA253c/NbJdUKQUwamFBWY37tCrWOAVNsIEgHebbqMQ== 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=mT4XGdPY; 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 38070606A31F for ; Sun, 6 Dec 2026 05:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mT4XGdPY Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE8931F0093B for ; Sun, 6 Dec 2026 05:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796533261; bh=XbeSHgPIKvuHgKTQjGT9jHpxAxbX15vOtEQ8fsrdivI=; h=From:Subject:Reply-To:Cc:In-Reply-To:References:Date; b=mT4XGdPYEQ5Dp7HKVXONChytwsn8g3GUnSQcajYxBIh+ZTsOAivom7AJMM2pLO5Wy zDhW8dOFyrkW9GRwLzrF5CSR/s/8I+NDLbfxAerSVEyb/5j5IoP24Q+PT7c2l4saP/ vMSBEK28nwGQN8ckA9RWNCjmJjXFkL11x9OfRLSO77sMjPBAXTvXxRzm4e6gtOZlVn k48dRvZbk/MQG/PR4EWbPq7VZYy8908DOWr938yQVPXnY36TDz248BorfJ2xVS+6mn 1ZQlE1Y0W9cpv0YXD03D3dFtiwoy+zrUiHfe9OMyObiipE4IbzcqT1RQ4/oIyYXypP cfhzHasR7VGzg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5] selinux: validate primary symbol count when loading policy Reply-To: sashiko-reviews@lists.linux.dev Cc: selinux@vger.kernel.org In-Reply-To: <179643369147.1996725.5532974391711154788@skku.edu> References: <179643369147.1996725.5532974391711154788@skku.edu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 05:01:01 +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 1 potential issue to consider: - [Medium] selinux: unbounded SYM_ROLES nprim allows 4 GiB vmalloc in policydb_index() -- commit 6e9bd0ca3cd7432aa4d0db65b40d675a7a002abe Author: Kyuwon Cho selinux: validate primary symbol count when loading policy This commit bounds primary symbol table counts against the remaining policy size (with exemptions for roles and pre-v20 types), caps the class count at U16_MAX, and switches policy index array allocations to kvzalloc with __GFP_NOWARN. > diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policyd= b.c > index b75c977c6673d..db302805ca7b9 100644 > --- a/security/selinux/ss/policydb.c > +++ b/security/selinux/ss/policydb.c > @@ -758,23 +758,27 @@ static int policydb_index(struct policydb *p) [ ... ] > - p->role_val_to_struct =3D kzalloc_objs(*p->role_val_to_struct, > - p->p_roles.nprim); > + p->role_val_to_struct =3D kvzalloc_objs(*p->role_val_to_struct, > + p->p_roles.nprim, > + GFP_KERNEL | __GFP_NOWARN); > if (!p->role_val_to_struct) > return -ENOMEM; [ ... ] > @@ -2904,6 +2909,22 @@ 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]); > + if (i =3D=3D SYM_CLASSES && nprim > U16_MAX) { > + pr_err("SELinux: class table has an invalid primary symbol count %u\= n", > + nprim); > + rc =3D -EINVAL; > + goto bad; > + } > + if (i !=3D SYM_ROLES && > + (i !=3D SYM_TYPES || > + p->policyvers >=3D POLICYDB_VERSION_AVTAB)) { > + rc =3D size_check(sizeof(u32), nprim, fp); > + if (rc) { > + pr_err("SELinux: symbol table %u has an invalid primary symbol coun= t %u\n", > + i, nprim); > + goto bad; > + } > + } [Severity: Medium] Can switching p->role_val_to_struct to kvzalloc_objs() while leaving SYM_ROLES unbounded let a tiny policy allocate up to ~4 GiB of vmalloc memory in policydb_index()? Before this patch, kzalloc_objs() rejected p->p_roles.nprim once the array exceeded KMALLOC_MAX_SIZE (4 MiB on x86_64), failing fast before reaching kvcalloc() for p->sym_val_to_name[SYM_ROLES]. With kvzalloc_objs(), __kvmalloc_node_noprof() falls back to vmalloc up to INT_MAX (2 GiB). A malformed policy with SYM_ROLES nprim set to 0x0fffffff now allocates and zeroes nearly 2 GiB for role_val_to_struct and another 2 GiB for sym_val_to_name[SYM_ROLES]. Because sel_write_load() runs policydb_read() under selinux_state.policy_mutex, this stalls concurrent policy and boolean operations and can pin the memory since sparse role tables are accepted. Would capping SYM_ROLES nprim avoid this regression? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179643369147.199672= 5.5532974391711154788@skku.edu?part=3D1