Skip to contentSkip to conversation

SELinux: bigendian problems with filename trans rules

PATCH Applied Eric Paris 3 participants 3 messages Feb 20, 2014 SELinux security module

lore
Share & tools
lore

Eric Paris

author
#0 lore raw

PATCH 1/1 SELinux: bigendian problems with filename trans rules

When writing policy via /sys/fs/selinux/policy I wrote the type and class of filename trans rules in CPU endian instead of little endian. On x86_64 this works just fine, but it means that on big endian arch's like ppc64 and s390 userspace reads the policy and converts it from le32_to_cpu. So the values are all screwed up. Write the values in le format like it should have been to start.

---
 security/selinux/ss/policydb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
security/selinux/ss/policydb.c +4 -4
index c0f4988..9c5cdc2 100644
@@ -3338,10 +3338,10 @@ static int filename_write_helper(void *key, void *data, void *ptr)
 	if (rc)
 		return rc;
 
-	buf[0] = ft->stype;
-	buf[1] = ft->ttype;
-	buf[2] = ft->tclass;
-	buf[3] = otype->otype;
+	buf[0] = cpu_to_le32(ft->stype);
+	buf[1] = cpu_to_le32(ft->ttype);
+	buf[2] = cpu_to_le32(ft->tclass);
+	buf[3] = cpu_to_le32(otype->otype);
 
 	rc = put_entry(buf, sizeof(u32), 4, fp);
 	if (rc)
Signature · 1 line
1.8.5.3
Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines · Eric Paris

When writing policy via /sys/fs/selinux/policy I wrote the type and class of filename trans rules in CPU endian instead of little endian. On x86_64 this works just fine, but it means that on big endian arch's like ppc64 and s390 userspace reads the policy and converts it from le32_to_cpu. So the values are all screwed up. Write the values in le format like it should have been to start.

---
 security/selinux/ss/policydb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
security/selinux/ss/policydb.c +0 -1
index c0f4988..9c5cdc2 100644
@@ -3338,10 +3338,10 @@ static int filename_write_helper(void *key, void *data, void *ptr)
 	if (rc)
 		return rc;
 
-	buf[0] = ft->stype;

security/selinux/ss/policydb.c static int filename_write_helper(void *key, void *data, void *ptr) · line 3347

Quoted 10 lines
security/selinux/ss/policydb.c +4 -3
-	buf[1] = ft->ttype;
-	buf[2] = ft->tclass;
-	buf[3] = otype->otype;
+	buf[0] = cpu_to_le32(ft->stype);
+	buf[1] = cpu_to_le32(ft->ttype);
+	buf[2] = cpu_to_le32(ft->tclass);
+	buf[3] = cpu_to_le32(otype->otype);
 
 	rc = put_entry(buf, sizeof(u32), 4, fp);
 	if (rc)
Applied
#2 lore raw
Quoted 33 lines · Stephen Smalley
Quoted 32 lines · Eric Paris

When writing policy via /sys/fs/selinux/policy I wrote the type and class of filename trans rules in CPU endian instead of little endian. On x86_64 this works just fine, but it means that on big endian arch's like ppc64 and s390 userspace reads the policy and converts it from le32_to_cpu. So the values are all screwed up. Write the values in le format like it should have been to start.

---

 security/selinux/ss/policydb.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/security/selinux/ss/policydb.c index c0f4988..9c5cdc2 100644

security/selinux/ss/policydb.c +4 -4
@@ -3338,10 +3338,10 @@ static int filename_write_helper(void *key, void
 *data, void *ptr)> 
 	if (rc)
 
 		return rc;
 
-	buf[0] = ft->stype;
-	buf[1] = ft->ttype;
-	buf[2] = ft->tclass;
-	buf[3] = otype->otype;
+	buf[0] = cpu_to_le32(ft->stype);
+	buf[1] = cpu_to_le32(ft->ttype);
+	buf[2] = cpu_to_le32(ft->tclass);
+	buf[3] = cpu_to_le32(otype->otype);
 
Quoted 4 lines

security/selinux/ss/policydb.c static int filename_write_helper(void *key, void *data, void *ptr) · line 3347

Quoted 2 lines
security/selinux/ss/policydb.c +0 -0
 	rc = put_entry(buf, sizeof(u32), 4, fp);
 	if (rc)

Applied, thanks.

Signature · 2 lines
paul moore
security and virtualization @ redhat