Skip to content

Commit a9fb96f

Browse files
hdellergregkh
authored andcommitted
apparmor: Fix unaligned memory accesses in KUnit test
[ Upstream commit c688041 ] The testcase triggers some unnecessary unaligned memory accesses on the parisc architecture: Kernel: unaligned access to 0x12f28e27 in policy_unpack_test_init+0x180/0x374 (iir 0x0cdc1280) Kernel: unaligned access to 0x12f28e67 in policy_unpack_test_init+0x270/0x374 (iir 0x64dc00ce) Use the existing helper functions put_unaligned_le32() and put_unaligned_le16() to avoid such warnings on architectures which prefer aligned memory accesses. Signed-off-by: Helge Deller <[email protected]> Fixes: 98c0cc4 ("apparmor: fix policy_unpack_test on big endian systems") Signed-off-by: John Johansen <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 937385e commit a9fb96f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

security/apparmor/policy_unpack_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "include/policy.h"
1010
#include "include/policy_unpack.h"
1111

12+
#include <linux/unaligned.h>
13+
1214
#define TEST_STRING_NAME "TEST_STRING"
1315
#define TEST_STRING_DATA "testing"
1416
#define TEST_STRING_BUF_OFFSET \
@@ -80,7 +82,7 @@ static struct aa_ext *build_aa_ext_struct(struct policy_unpack_fixture *puf,
8082
*(buf + 1) = strlen(TEST_U32_NAME) + 1;
8183
strscpy(buf + 3, TEST_U32_NAME, e->end - (void *)(buf + 3));
8284
*(buf + 3 + strlen(TEST_U32_NAME) + 1) = AA_U32;
83-
*((__le32 *)(buf + 3 + strlen(TEST_U32_NAME) + 2)) = cpu_to_le32(TEST_U32_DATA);
85+
put_unaligned_le32(TEST_U32_DATA, buf + 3 + strlen(TEST_U32_NAME) + 2);
8486

8587
buf = e->start + TEST_NAMED_U64_BUF_OFFSET;
8688
*buf = AA_NAME;
@@ -103,7 +105,7 @@ static struct aa_ext *build_aa_ext_struct(struct policy_unpack_fixture *puf,
103105
*(buf + 1) = strlen(TEST_ARRAY_NAME) + 1;
104106
strscpy(buf + 3, TEST_ARRAY_NAME, e->end - (void *)(buf + 3));
105107
*(buf + 3 + strlen(TEST_ARRAY_NAME) + 1) = AA_ARRAY;
106-
*((__le16 *)(buf + 3 + strlen(TEST_ARRAY_NAME) + 2)) = cpu_to_le16(TEST_ARRAY_SIZE);
108+
put_unaligned_le16(TEST_ARRAY_SIZE, buf + 3 + strlen(TEST_ARRAY_NAME) + 2);
107109

108110
return e;
109111
}

0 commit comments

Comments
 (0)