Skip to contentSkip to conversation

apparmor: fix policy_unpack_test on big endian systems

PATCH In review Guenter Roeck 3 participants 4 messages Aug 8, 2024 – Aug 12, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 apparmor: fix policy_unpack_test on big endian systems

policy_unpack_test fails on big endian systems because data byte order is expected to be little endian but is generated in host byte order. This results in test failures such as:

# policy_unpack_test_unpack_array_with_null_name: EXPECTATION FAILED at security/apparmor/policy_unpack_test.c:150

    Expected array_size == (u16)16, but
        array_size == 4096 (0x1000)
        (u16)16 == 16 (0x10)
    # policy_unpack_test_unpack_array_with_null_name: pass:0 fail:1 skip:0 total:1
    not ok 3 policy_unpack_test_unpack_array_with_null_name
    # policy_unpack_test_unpack_array_with_name: EXPECTATION FAILED at security/apparmor/policy_unpack_test.c:164
    Expected array_size == (u16)16, but
        array_size == 4096 (0x1000)
        (u16)16 == 16 (0x10)
    # policy_unpack_test_unpack_array_with_name: pass:0 fail:1 skip:0 total:1

Add the missing endianness conversions when generating test data.

Fixes 4d944bcd4e73 ("apparmor: add AppArmor KUnit tests for policy unpack")
Cc Brendan Higgins <[email protected]>
Cc Kees Cook <[email protected]>
---
 security/apparmor/policy_unpack_test.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
security/apparmor/policy_unpack_test.c +3 -3
index 874fcf97794e..c64733d6c98f 100644
@@ -80,14 +80,14 @@ static struct aa_ext *build_aa_ext_struct(struct policy_unpack_fixture *puf,
 	*(buf + 1) = strlen(TEST_U32_NAME) + 1;
 	strscpy(buf + 3, TEST_U32_NAME, e->end - (void *)(buf + 3));
 	*(buf + 3 + strlen(TEST_U32_NAME) + 1) = AA_U32;
-	*((u32 *)(buf + 3 + strlen(TEST_U32_NAME) + 2)) = TEST_U32_DATA;
+	*((__le32 *)(buf + 3 + strlen(TEST_U32_NAME) + 2)) = cpu_to_le32(TEST_U32_DATA);
 
 	buf = e->start + TEST_NAMED_U64_BUF_OFFSET;
 	*buf = AA_NAME;
 	*(buf + 1) = strlen(TEST_U64_NAME) + 1;
 	strscpy(buf + 3, TEST_U64_NAME, e->end - (void *)(buf + 3));
 	*(buf + 3 + strlen(TEST_U64_NAME) + 1) = AA_U64;
-	*((u64 *)(buf + 3 + strlen(TEST_U64_NAME) + 2)) = TEST_U64_DATA;
+	*((__le64 *)(buf + 3 + strlen(TEST_U64_NAME) + 2)) = cpu_to_le64(TEST_U64_DATA);
 
 	buf = e->start + TEST_NAMED_BLOB_BUF_OFFSET;
 	*buf = AA_NAME;
@@ -103,7 +103,7 @@ static struct aa_ext *build_aa_ext_struct(struct policy_unpack_fixture *puf,
 	*(buf + 1) = strlen(TEST_ARRAY_NAME) + 1;
 	strscpy(buf + 3, TEST_ARRAY_NAME, e->end - (void *)(buf + 3));
 	*(buf + 3 + strlen(TEST_ARRAY_NAME) + 1) = AA_ARRAY;
-	*((u16 *)(buf + 3 + strlen(TEST_ARRAY_NAME) + 2)) = TEST_ARRAY_SIZE;
+	*((__le16 *)(buf + 3 + strlen(TEST_ARRAY_NAME) + 2)) = cpu_to_le16(TEST_ARRAY_SIZE);
 
 	return e;
 }
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Guenter Roeck

policy_unpack_test fails on big endian systems because data byte order is expected to be little endian but is generated in host byte order. This results in test failures such as:

# policy_unpack_test_unpack_array_with_null_name: EXPECTATION FAILED at security/apparmor/policy_unpack_test.c:150

    Expected array_size == (u16)16, but
        array_size == 4096 (0x1000)
        (u16)16 == 16 (0x10)
    # policy_unpack_test_unpack_array_with_null_name: pass:0 fail:1 skip:0 total:1
    not ok 3 policy_unpack_test_unpack_array_with_null_name
    # policy_unpack_test_unpack_array_with_name: EXPECTATION FAILED at security/apparmor/policy_unpack_test.c:164
    Expected array_size == (u16)16, but
        array_size == 4096 (0x1000)
        (u16)16 == 16 (0x10)
    # policy_unpack_test_unpack_array_with_name: pass:0 fail:1 skip:0 total:1
Quoted 6 lines

Add the missing endianness conversions when generating test data.

Fixes 4d944bcd4e73 ("apparmor: add AppArmor KUnit tests for policy unpack")
Cc Brendan Higgins <[email protected]>
Cc Kees Cook <[email protected]>
Signature · 1 line
Kees Cook
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Guenter Roeck
Quoted 16 lines · Guenter Roeck

policy_unpack_test fails on big endian systems because data byte order is expected to be little endian but is generated in host byte order. This results in test failures such as:

# policy_unpack_test_unpack_array_with_null_name: EXPECTATION FAILED at security/apparmor/policy_unpack_test.c:150

     Expected array_size == (u16)16, but
         array_size == 4096 (0x1000)
         (u16)16 == 16 (0x10)
     # policy_unpack_test_unpack_array_with_null_name: pass:0 fail:1 skip:0 total:1
     not ok 3 policy_unpack_test_unpack_array_with_null_name
     # policy_unpack_test_unpack_array_with_name: EXPECTATION FAILED at security/apparmor/policy_unpack_test.c:164
     Expected array_size == (u16)16, but
         array_size == 4096 (0x1000)
         (u16)16 == 16 (0x10)
     # policy_unpack_test_unpack_array_with_name: pass:0 fail:1 skip:0 total:1
Quoted 6 lines

Add the missing endianness conversions when generating test data.

Fixes 4d944bcd4e73 ("apparmor: add AppArmor KUnit tests for policy unpack")
Cc Brendan Higgins <[email protected]>
Cc Kees Cook <[email protected]>

Looks good

I will pull this into my tree

Quoted 34 lines
---
  security/apparmor/policy_unpack_test.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
security/apparmor/policy_unpack_test.c +3 -3
index 874fcf97794e..c64733d6c98f 100644
@@ -80,14 +80,14 @@ static struct aa_ext *build_aa_ext_struct(struct policy_unpack_fixture *puf,
  	*(buf + 1) = strlen(TEST_U32_NAME) + 1;
  	strscpy(buf + 3, TEST_U32_NAME, e->end - (void *)(buf + 3));
  	*(buf + 3 + strlen(TEST_U32_NAME) + 1) = AA_U32;
-	*((u32 *)(buf + 3 + strlen(TEST_U32_NAME) + 2)) = TEST_U32_DATA;
+	*((__le32 *)(buf + 3 + strlen(TEST_U32_NAME) + 2)) = cpu_to_le32(TEST_U32_DATA);
 
  	buf = e->start + TEST_NAMED_U64_BUF_OFFSET;
  	*buf = AA_NAME;
  	*(buf + 1) = strlen(TEST_U64_NAME) + 1;
  	strscpy(buf + 3, TEST_U64_NAME, e->end - (void *)(buf + 3));
  	*(buf + 3 + strlen(TEST_U64_NAME) + 1) = AA_U64;
-	*((u64 *)(buf + 3 + strlen(TEST_U64_NAME) + 2)) = TEST_U64_DATA;
+	*((__le64 *)(buf + 3 + strlen(TEST_U64_NAME) + 2)) = cpu_to_le64(TEST_U64_DATA);
 
  	buf = e->start + TEST_NAMED_BLOB_BUF_OFFSET;
  	*buf = AA_NAME;
@@ -103,7 +103,7 @@ static struct aa_ext *build_aa_ext_struct(struct policy_unpack_fixture *puf,
  	*(buf + 1) = strlen(TEST_ARRAY_NAME) + 1;
  	strscpy(buf + 3, TEST_ARRAY_NAME, e->end - (void *)(buf + 3));
  	*(buf + 3 + strlen(TEST_ARRAY_NAME) + 1) = AA_ARRAY;
-	*((u16 *)(buf + 3 + strlen(TEST_ARRAY_NAME) + 2)) = TEST_ARRAY_SIZE;
+	*((__le16 *)(buf + 3 + strlen(TEST_ARRAY_NAME) + 2)) = cpu_to_le16(TEST_ARRAY_SIZE);
 
  	return e;
  }
#3 lore raw
Quoted 24 lines · John Johansen
Quoted 16 lines · Guenter Roeck

policy_unpack_test fails on big endian systems because data byte order is expected to be little endian but is generated in host byte order. This results in test failures such as:

  # policy_unpack_test_unpack_array_with_null_name: EXPECTATION FAILED at security/apparmor/policy_unpack_test.c:150 Expected array_size == (u16)16, but
         array_size == 4096 (0x1000)
         (u16)16 == 16 (0x10)
     # policy_unpack_test_unpack_array_with_null_name: pass:0 fail:1 skip:0 total:1
     not ok 3 policy_unpack_test_unpack_array_with_null_name
     # policy_unpack_test_unpack_array_with_name: EXPECTATION FAILED at security/apparmor/policy_unpack_test.c:164 Expected array_size == (u16)16, but
         array_size == 4096 (0x1000)
         (u16)16 == 16 (0x10)
     # policy_unpack_test_unpack_array_with_name: pass:0 fail:1 skip:0 total:1

Quoted 6 lines

Add the missing endianness conversions when generating test data.

Fixes 4d944bcd4e73 ("apparmor: add AppArmor KUnit tests for policy unpack")
Cc Brendan Higgins <[email protected]>
Cc Kees Cook <[email protected]>
Quoted 6 lines

Looks good

I will pull this into my tree

Thanks!

Guenter