1 Star 0 Fork 31

lujie/libsepol

forked from src-openEuler/libsepol 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-libsepol-reject-invalid-class-datums.patch 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
markeryang 提交于 2024-10-15 09:36 +08:00 . sync backport patches from upstream
From 68c3a9991679702a7adc6e040e5703a7abb50b16 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Tue, 28 Nov 2023 19:23:32 +0100
Subject: [PATCH] libsepol: reject invalid class datums
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Internally class values are stored in multiple placed in a 16-bit wide
integer. Reject class values exceeding the maximum representable value.
This avoids truncations in the helper
policydb_string_to_security_class(), which gets called before validation
of the policy:
policydb.c:4082:9: runtime error: implicit conversion from type 'uint32_t' (aka 'unsigned int') of value 2113929220 (32-bit, unsigned) to type 'sepol_security_class_t' (aka 'unsigned short') changed the value to 4 (16-bit, unsigned)
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
Reference: https://github.com/SELinuxProject/selinux/commit/68c3a9991679702a7adc6e040e5703a7abb50b16
Conflict: Context adaptation
---
libsepol/src/policydb.c | 2 ++
libsepol/src/policydb_validate.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c
index 6ba4f9168..f10a8a95a 100644
--- a/libsepol/src/policydb.c
+++ b/libsepol/src/policydb.c
@@ -2250,6 +2250,8 @@ static int class_read(policydb_t * p, hashtab_t h, struct policy_file *fp)
if (is_saturated(len2))
goto bad;
cladatum->s.value = le32_to_cpu(buf[2]);
+ if (cladatum->s.value > UINT16_MAX)
+ goto bad;
if (symtab_init(&cladatum->permissions, PERM_SYMTAB_SIZE))
goto bad;
diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c
index 6d8641f..69a436b 100644
--- a/libsepol/src/policydb_validate.c
+++ b/libsepol/src/policydb_validate.c
@@ -199,7 +199,7 @@ bad:
static int validate_class_datum(sepol_handle_t *handle, const class_datum_t *class, validate_t flavors[])
{
- if (validate_value(class->s.value, &flavors[SYM_CLASSES]))
+ if (class->s.value > UINT16_MAX || validate_value(class->s.value, &flavors[SYM_CLASSES]))
goto bad;
if (class->comdatum && validate_common_datum(handle, class->comdatum, flavors))
goto bad;
--
2.33.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lujie42/libsepol.git
git@gitee.com:lujie42/libsepol.git
lujie42
libsepol
libsepol
master

搜索帮助