Add xfrm_userpolicy_info to netd compat structs
Netd has a 32-bit compatibility build flag for 32-bit userspace with a
64-bit kernel where some xfrm structs have different alignments. The
list of structs was missing xfrm_userpolicy_info which is used to set
the policy for a socket. The end result was that transformations were
not correctly applied for sockets as the kernel expected more data than
netd provided.
This adds xfrm_userpolicy_info to the list of compatibility structures
as well as static asserts to ensure that builds will fail if the
assumptions about the struct layout changes.
BUG: 80319713
Test: run cts -m CtsNetTestCases on 32-bit device with 64-bit kernel
Change-Id: I73d157db6beb1773c75c02431f50a05a55ef9c46
diff --git a/server/XfrmController.h b/server/XfrmController.h
index f21dfa1..908c63c 100644
--- a/server/XfrmController.h
+++ b/server/XfrmController.h
@@ -257,6 +257,8 @@
__u32 min;
__u32 max;
};
+ struct xfrm_userpolicy_info : ::xfrm_userpolicy_info {
+ } __attribute__((aligned(8)));
/*
* Anyone who encounters a failure when sending netlink messages should look here
@@ -280,6 +282,16 @@
static_assert(sizeof(::xfrm_userspi_info) - sizeof(::xfrm_usersa_info) ==
sizeof(xfrm_userspi_info) - sizeof(xfrm_usersa_info),
"struct xfrm_userspi_info has changed and does not match the kernel struct.");
+ static_assert(sizeof(::xfrm_userpolicy_info) % 8 != 0,
+ "struct xfrm_userpolicy_info has changed "
+ "alignment. Please consider whether this "
+ "patch is needed.");
+ static_assert(sizeof(xfrm_userpolicy_info) - offsetof(xfrm_userpolicy_info, share) == 5,
+ "struct xfrm_userpolicy_info probably misaligned with kernel struct.");
+ static_assert(sizeof(xfrm_userpolicy_info) % 8 == 0,
+ "struct xfrm_userpolicy_info is not 64-bit "
+ "aligned. Please consider whether this patch "
+ "is needed.");
#endif
// helper function for filling in the XfrmId (and XfrmSaInfo) structure