From patchwork Mon May 6 17:31:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13655843 X-Patchwork-Delegate: plautrba@redhat.com Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (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 EAEEA156C62 for ; Mon, 6 May 2024 17:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715016686; cv=none; b=ZLOIQAQhXmiM+NjHztvBENTcpvhpR/TLwPxaCbaqFqoGzjhD9HeYZew8MkIPew+KLULigK73SoAuoatL+wLJgw4VUk5JJHQuEBbu4aKVuJeUBrILbdDK4Fd6DyRTjrfnMyPBPa5i7w4R5srYehbdsCfbnRTaZB4GC9vLgBoSq0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715016686; c=relaxed/simple; bh=pPN+b9Td3M/ZKWj5dgOSeSw228e9XzlhpkceFeIrjhY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZHJPvNZtvBijVxbvo5FSHiYVWjEJcogHusuuB/xGQw31LVu/KhYonlO1R3HExMgKjhs3mnmwDLuJpFWfReG916dtLMIXbKogDJ7uEeLpJDRF73wk27ZqG7+Q03uJQwwklkTACHxTUnQwD/vwMNATNeMe9ieDRX5LZcLbxG9CRdE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=gwmm3YbZ; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="gwmm3YbZ" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1715016674; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Wuq9EH3o7JPGp/3kJrLrZVF5SB3GVmqJCQOeWe2S5iA=; b=gwmm3YbZuulvUM96VjwgWgbQwdgO9+zueHy47sUZ99Yee9FHluIHJEf4NDDXnZWHYlJ+gg PxlMrttS/JL3rYYHA1Hw5nVJI/8GonyNF50u8DO+O9ngmJrK8hiKAOJ1oQCQ3ZZWJ5XFZp 1wbQI+vfPib1pmZyneQ/kaSeS6pqFezdYZxNJnU4w4Nc6bY27QFmcuSJ3ENzBTCgwAU/RF Pha6Gx+r8dW+8M92QiLN3otsf1ZqvMOp1tl5tfU72Lf0N9ZLE4x7Sf0tXFzKXuQEJ0Cn11 8Kvb7rgEpN7MGTnh6uWhd6/35dVtUjYdQacuppqXlFPBEo15mmHW0ru0srNJvw== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 1/4] libsepol: reject self flag in type rules in old policies Date: Mon, 6 May 2024 19:31:07 +0200 Message-ID: <20240506173110.220702-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche The flag RULE_SELF in type rules is only supported in modular policies since version 21 (MOD_POLICYDB_VERSION_SELF_TYPETRANS). Reported-by: oss-fuzz (issue 68731) Signed-off-by: Christian Göttsche Acked-by: James Carter --- libsepol/src/policydb_validate.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c index e1623172..be3ebe5f 100644 --- a/libsepol/src/policydb_validate.c +++ b/libsepol/src/policydb_validate.c @@ -1077,6 +1077,10 @@ static int validate_avrules(sepol_handle_t *handle, const avrule_t *avrule, int switch(avrule->flags) { case 0: case RULE_SELF: + if (p->policyvers != POLICY_KERN && + p->policyvers < MOD_POLICYDB_VERSION_SELF_TYPETRANS && + (avrule->specified & AVRULE_TYPE)) + goto bad; break; case RULE_NOTSELF: switch(avrule->specified) { @@ -1503,8 +1507,16 @@ static int validate_filename_trans_rules(sepol_handle_t *handle, const filename_ goto bad; /* currently only the RULE_SELF flag can be set */ - if ((filename_trans->flags & ~RULE_SELF) != 0) + switch (filename_trans->flags) { + case 0: + break; + case RULE_SELF: + if (p->policyvers != POLICY_KERN && p->policyvers < MOD_POLICYDB_VERSION_SELF_TYPETRANS) + goto bad; + break; + default: goto bad; + } } return 0; From patchwork Mon May 6 17:31:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13655846 X-Patchwork-Delegate: plautrba@redhat.com Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (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 EAEA3745D9 for ; Mon, 6 May 2024 17:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715016687; cv=none; b=nWP6onWKDzEXi2ltl0T7oAcmr55K+iDdxxG/SgqDIiBykV0LU94Owsprd+wK8cVStqeWYphvlZxxFpRSDzAzF/t15D2HmLR8zzAbKfKe3dT1EB8y2Sb8OQ8C1sJm7MPllh1VBYsQXZnGj9x3/I2o+ECw4Ak8BXtpDMj0V5Vp+NU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715016687; c=relaxed/simple; bh=EcCnGZIZl6Xl3/AkK5GAj+l6qPF2tYUunBXDGc7FRJQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Oy5Fq+S7Z/PB2qRE1bHJ7J9gZsHEFeRUOydDFP7C5M0KxiwO7Bea1kyYHRr/aI1T5X3Sf7d0Fj2BzMgSBeeeXVPIMbLljB8W71ROQTCb01FmfNOaJQbfK4wkpe1OhXQAq7Z9yBekb8+HPutWtydvwBcxjGSV0P49/7JXqidfyJ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=gsYde0UJ; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="gsYde0UJ" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1715016675; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=03P2U+ZJd6Ai4thqTWC+JJvhTL+i9PpJjo9ZtC6iNmM=; b=gsYde0UJZP6ypMl5zy9Y9lL82G731fquzTjPIfCgIiMXI9UCRfmC/sy6j3IvlS3OYPeHV8 zkdsfjKCk7LvHeD7jFAb2jd+g9inVHt0vWr1yEQhVustJVAvG8MQ/SVuC6iG8kL3bqgg4k 6i+fGl1PNYlgRqXfE0EkE5Nu8dcuxBrAtRY8QYehPWL54ty85jhA+1t2oxyPRtkPArYDnP ZUeEjbS+Ey4BcZ8PTxPPlklJ0oArtvsUsyc/3orzzG/X0iSgZXthbNIWhZGhnc3kMBN8rM U91AOxiyPajmt79Pl4BHKWOqVXwfTdZffqCJDlv9Y9E7R5CmAADpi8G5r2WV4g== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 2/4] libsepol: only exempt gaps checking for kernel policies Date: Mon, 6 May 2024 19:31:08 +0200 Message-ID: <20240506173110.220702-2-cgoettsche@seltendoof.de> In-Reply-To: <20240506173110.220702-1-cgoettsche@seltendoof.de> References: <20240506173110.220702-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche Kernel policy versions 20 to 23 store attributes only in type_attr_map and reference gaps in the type arrays. Thus they are exempted from gaps checks. Only exempt kernel policies, not base and module ones. Signed-off-by: Christian Göttsche --- libsepol/src/policydb_validate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c index be3ebe5f..04135d84 100644 --- a/libsepol/src/policydb_validate.c +++ b/libsepol/src/policydb_validate.c @@ -63,7 +63,7 @@ static int validate_array_init(const policydb_t *p, validate_t flavors[]) goto bad; if (validate_init(&flavors[SYM_ROLES], p->p_role_val_to_name, p->p_roles.nprim)) goto bad; - if (p->policyvers < POLICYDB_VERSION_AVTAB || p->policyvers > POLICYDB_VERSION_PERMISSIVE) { + if (p->policy_type != POLICY_KERN || p->policyvers < POLICYDB_VERSION_AVTAB || p->policyvers > POLICYDB_VERSION_PERMISSIVE) { if (validate_init(&flavors[SYM_TYPES], p->p_type_val_to_name, p->p_types.nprim)) goto bad; } else { @@ -803,7 +803,7 @@ static int validate_datum_array_gaps(sepol_handle_t *handle, const policydb_t *p * For policy versions between 20 and 23, attributes exist in the policy, * but only in the type_attr_map, so all gaps must be assumed to be valid. */ - if (p->policyvers < POLICYDB_VERSION_AVTAB || p->policyvers > POLICYDB_VERSION_PERMISSIVE) { + if (p->policy_type != POLICY_KERN || p->policyvers < POLICYDB_VERSION_AVTAB || p->policyvers > POLICYDB_VERSION_PERMISSIVE) { for (i = 0; i < p->p_types.nprim; i++) { if (bool_xnor(p->type_val_to_struct[i], ebitmap_get_bit(&flavors[SYM_TYPES].gaps, i))) goto bad; From patchwork Mon May 6 17:31:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13655845 X-Patchwork-Delegate: plautrba@redhat.com Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (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 E2E87157461 for ; Mon, 6 May 2024 17:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715016686; cv=none; b=FUy1FUKj0sKfCrY3ohMH4x5lMHbYsWi66/7gaRzbXfdtq0pRCDb6WKKaF0XcQhDnrl4RdE0iqbcdbxzqCuyNMMWrtB7yVkfSqDb0GE1sS3pbAmXkyAdwHEyP+9jbOsozkIFJbrmQHBVi6nK/FHybAfVDNyqh2RHeruy4ap9kvqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715016686; c=relaxed/simple; bh=tLHTTHlGYt/fYagdKk4nQfjoj+kHe4j04dMJzROC5Ac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q30eZvAIOU+tT1FzzZJ9CMVWlPK/c/ZBReUZK3o2S8mxMMpyw51rwxug5Fb2cTtzliR62Xpx39PUWvkD1jjSfsZBj2pQcTUL1Ox3AWy/flJhbkZ5OdVhE2IxWT1f1w9doJJjHA+jaxKd4CzMoPD/USi4DjGIKrR1fbwwjtPK7ys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=FpCgmlYR; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="FpCgmlYR" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1715016675; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cgKlFWBUNTuRT8UNnBvufxMflDwtbQ8n7t4JMgj9Euw=; b=FpCgmlYRcoPiB0pMKAyYYMU6uGUrkiBqZjxHtzcjR8n54cyDYmV5jWS6UH19o2R1XD/U2V YST3yoFS1ZQIGUtTWL5ZTZsKCsW7k+tV7sf0eBMbYEwnkcBm6wbFTrKLQK4Vk+zZdmCfK7 I7+ad9qUMt8zikZG6Hw3Zqx3IJRcXv0CHJjAObxM3f4dPs+aT+1jDgCgUIaUar2J1UdyGv 8KdbPmhjxsxJXdQtg/TO7fbi1HVOlpAwAC600nEKjaTHxP9VaNxQJ+Vc+ViT7pJG5dwRM5 881YY0BxWIvlZRsdeJHyetU4Y+jxq4+wLPVZ8O4AptV9k8clhJySU5rlXeEZ+w== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 3/4] libsepol: validate type-attribute-map for old policies Date: Mon, 6 May 2024 19:31:09 +0200 Message-ID: <20240506173110.220702-3-cgoettsche@seltendoof.de> In-Reply-To: <20240506173110.220702-1-cgoettsche@seltendoof.de> References: <20240506173110.220702-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche Validate the type-to-associated-attributes maps also for policies prior to version 20. To ensure only valid entries in these maps, skip the degenerate case for gaps during construction. Signed-off-by: Christian Göttsche --- libsepol/src/policydb.c | 2 +- libsepol/src/policydb_validate.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c index 49f9e8af..e90ccca1 100644 --- a/libsepol/src/policydb.c +++ b/libsepol/src/policydb.c @@ -4450,7 +4450,7 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose) } } /* add the type itself as the degenerate case */ - if (ebitmap_set_bit(&p->type_attr_map[i], i, 1)) + if (p->type_val_to_struct[i] && ebitmap_set_bit(&p->type_attr_map[i], i, 1)) goto bad; if (p->type_val_to_struct[i] && p->type_val_to_struct[i]->flavor != TYPE_ATTRIB) { if (ebitmap_set_bit(&p->attr_type_map[i], i, 1)) diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c index 04135d84..84c1071c 100644 --- a/libsepol/src/policydb_validate.c +++ b/libsepol/src/policydb_validate.c @@ -1787,10 +1787,8 @@ int policydb_validate(sepol_handle_t *handle, const policydb_t *p) if (validate_range_transitions(handle, p, flavors)) goto bad; - if (p->policyvers >= POLICYDB_VERSION_AVTAB) { - if (validate_typeattr_map(handle, p, flavors)) - goto bad; - } + if (validate_typeattr_map(handle, p, flavors)) + goto bad; validate_array_destroy(flavors); From patchwork Mon May 6 17:31:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 13655844 X-Patchwork-Delegate: plautrba@redhat.com Received: from server02.seltendoof.de (server02.seltendoof.de [168.119.48.163]) (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 E2E3B156F2C for ; Mon, 6 May 2024 17:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.48.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715016686; cv=none; b=bnMMVKhke4gpufOZdxhLzv8nrmMeDnugm0ZGJhkjFkg4TAVgXtyYgA8BnM6L4FZnJWX+Z49eRroJyxqzP/6fJGPMRIC8Ic4DWcckB/20bpKSt/LgvrRYQZMUL4O3s3rksejpLJnPj/fY256pvbEUBUpQkaY75uJiJmCfnbaraUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715016686; c=relaxed/simple; bh=Vb0+o1lzdniadgW7gsKfQ0S55IhcVa0/AcRrIENd9Bw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fBPe/m0vCLVbDEaC7U5BbVy/71Bxvh9JxweNogjeMcNyzmGE1XyYL+KciHLWJlgNJACXTjdOcos/y9eLkiie2VJk1w7PX+lMInBiqdydH0geJgtbYr65Ukt/8ZBwMgJhzZeGWKYe58dpeby5CUk10AJt1vaQGgu6qU+bgrEVAGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de; spf=pass smtp.mailfrom=seltendoof.de; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b=nnQVmdhb; arc=none smtp.client-ip=168.119.48.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seltendoof.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=seltendoof.de header.i=@seltendoof.de header.b="nnQVmdhb" From: =?utf-8?q?Christian_G=C3=B6ttsche?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seltendoof.de; s=2023072701; t=1715016675; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yvushllLuxdVvmeHSg5fjJJy6/k/GoAdIesx5yCLqjU=; b=nnQVmdhbYC0poFPSl4hjueMos0sxpaa9dkrrJQBzHAgmUaSkp+PmNYVNSqAl42IX4r1Zkr +EK+yOSoVa9YFtK8OAVYhB1dYaB0XTzgrGqr3zZ6+1f4eqAXQax+UDPipUfYf+rv7326yQ MDT33hRUOw37p55WFZkQ2D5mMGIcg25XHXxhqjdW/AduCprVuQnW0sPkPV3kcTHU5OSUca u4NEQlRRZ/1Gxhs6P9EBq8fLLHulgMzJgjtJd1x/LscFbW4EsKKZyyvfN1da8nIa30SDZU cRu723pKRd2V/ZhOyR/TukUw4ecxBqX2RUpzcBDky6GiybJ1WA48Y9WxoOCjtg== To: selinux@vger.kernel.org Cc: =?utf-8?q?Christian_G=C3=B6ttsche?= Subject: [PATCH 4/4] libsepol: include prefix for module policy versions Date: Mon, 6 May 2024 19:31:10 +0200 Message-ID: <20240506173110.220702-4-cgoettsche@seltendoof.de> In-Reply-To: <20240506173110.220702-1-cgoettsche@seltendoof.de> References: <20240506173110.220702-1-cgoettsche@seltendoof.de> Reply-To: cgzones@googlemail.com Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Göttsche If writing a policy fails due to a limitation by the requested policy version include a prefix if the version refers to a module policy. Signed-off-by: Christian Göttsche --- libsepol/src/write.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libsepol/src/write.c b/libsepol/src/write.c index 2fcc1701..f8cd9e1d 100644 --- a/libsepol/src/write.c +++ b/libsepol/src/write.c @@ -1103,8 +1103,10 @@ static int class_write(hashtab_key_t key, hashtab_datum_t datum, void *ptr) buf[1] = cpu_to_le32(cladatum->default_role); if (!glblub_version && default_range == DEFAULT_GLBLUB) { WARN(fp->handle, - "class %s default_range set to GLBLUB but policy version is %d (%d required), discarding", - p->p_class_val_to_name[cladatum->s.value - 1], p->policyvers, + "class %s default_range set to GLBLUB but %spolicy version is %d (%d required), discarding", + p->p_class_val_to_name[cladatum->s.value - 1], + p->policy_type == POLICY_KERN ? "" : "module ", + p->policyvers, p->policy_type == POLICY_KERN? POLICYDB_VERSION_GLBLUB:MOD_POLICYDB_VERSION_GLBLUB); default_range = 0; } @@ -2219,7 +2221,8 @@ int policydb_write(policydb_t * p, struct policy_file *fp) p->policy_type == POLICY_BASE) || (p->policyvers < MOD_POLICYDB_VERSION_MLS && p->policy_type == POLICY_MOD)) { - ERR(fp->handle, "policy version %d cannot support MLS", + ERR(fp->handle, "%spolicy version %d cannot support MLS", + p->policy_type == POLICY_KERN ? "" : "module ", p->policyvers); return POLICYDB_ERROR; }