Gustavo A. R. Silva
db243b7964
net/ipv4/ipv6: Replace one-element arraya with flexible-array members
...
There is a regular need in the kernel to provide a way to declare having
a dynamically sized set of trailing elements in a structure. Kernel code
should always use “flexible array members”[1] for these cases. The older
style of one-element or zero-length arrays should no longer be used[2].
Use an anonymous union with a couple of anonymous structs in order to
keep userspace unchanged and refactor the related code accordingly:
$ pahole -C group_filter net/ipv4/ip_sockglue.o
struct group_filter {
union {
struct {
__u32 gf_interface_aux; /* 0 4 */
/* XXX 4 bytes hole, try to pack */
struct __kernel_sockaddr_storage gf_group_aux; /* 8 128 */
/* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */
__u32 gf_fmode_aux; /* 136 4 */
__u32 gf_numsrc_aux; /* 140 4 */
struct __kernel_sockaddr_storage gf_slist[1]; /* 144 128 */
}; /* 0 272 */
struct {
__u32 gf_interface; /* 0 4 */
/* XXX 4 bytes hole, try to pack */
struct __kernel_sockaddr_storage gf_group; /* 8 128 */
/* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */
__u32 gf_fmode; /* 136 4 */
__u32 gf_numsrc; /* 140 4 */
struct __kernel_sockaddr_storage gf_slist_flex[0]; /* 144 0 */
}; /* 0 144 */
}; /* 0 272 */
/* size: 272, cachelines: 5, members: 1 */
/* last cacheline: 16 bytes */
};
$ pahole -C compat_group_filter net/ipv4/ip_sockglue.o
struct compat_group_filter {
union {
struct {
__u32 gf_interface_aux; /* 0 4 */
struct __kernel_sockaddr_storage gf_group_aux __attribute__((__aligned__(4))); /* 4 128 */
/* --- cacheline 2 boundary (128 bytes) was 4 bytes ago --- */
__u32 gf_fmode_aux; /* 132 4 */
__u32 gf_numsrc_aux; /* 136 4 */
struct __kernel_sockaddr_storage gf_slist[1] __attribute__((__aligned__(4))); /* 140 128 */
} __attribute__((__packed__)) __attribute__((__aligned__(4))); /* 0 268 */
struct {
__u32 gf_interface; /* 0 4 */
struct __kernel_sockaddr_storage gf_group __attribute__((__aligned__(4))); /* 4 128 */
/* --- cacheline 2 boundary (128 bytes) was 4 bytes ago --- */
__u32 gf_fmode; /* 132 4 */
__u32 gf_numsrc; /* 136 4 */
struct __kernel_sockaddr_storage gf_slist_flex[0] __attribute__((__aligned__(4))); /* 140 0 */
} __attribute__((__packed__)) __attribute__((__aligned__(4))); /* 0 140 */
} __attribute__((__aligned__(1))); /* 0 268 */
/* size: 268, cachelines: 5, members: 1 */
/* forced alignments: 1 */
/* last cacheline: 12 bytes */
} __attribute__((__packed__));
This helps with the ongoing efforts to globally enable -Warray-bounds
and get us closer to being able to tighten the FORTIFY_SOURCE routines
on memcpy().
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arrays
Link: https://github.com/KSPP/linux/issues/79
Link: https://github.com/KSPP/linux/issues/109
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-08-05 11:46:42 +01:00
..
2021-06-02 14:01:55 -07:00
2021-07-01 11:21:57 -07:00
2021-07-27 20:11:45 +01:00
2021-07-23 14:20:25 +01:00
2021-06-10 14:08:09 -07:00
2021-08-03 11:21:39 +01:00
2021-06-18 19:47:02 -07:00
2021-07-05 14:08:24 -07:00
2021-07-31 11:23:26 -07:00
2021-06-25 13:13:50 +02:00
2021-08-05 11:36:59 +01:00
2021-07-15 11:08:33 -07:00
2021-08-04 12:11:52 +02:00
2021-06-30 15:51:09 -07:00
2021-08-05 11:36:59 +01:00
2021-06-01 17:01:33 -07:00
2021-07-20 06:00:38 -07:00
2021-08-03 14:23:22 -07:00
2021-08-05 11:05:48 +01:00
2021-08-03 13:05:26 +01:00
2021-08-03 12:58:22 +01:00
2021-06-16 12:13:01 -07:00
2021-07-23 14:20:25 +01:00
2021-08-05 11:46:42 +01:00
2021-08-05 11:46:42 +01:00
2021-07-01 15:54:01 -07:00
2021-06-29 11:28:21 -07:00
2021-05-26 07:03:39 +02:00
2021-06-07 14:08:30 -07:00
2021-06-08 16:31:25 -07:00
2021-07-27 13:05:56 +01:00
2021-07-23 10:34:13 +02:00
2021-04-06 22:42:16 +02:00
2021-08-05 10:56:01 +01:00
2021-07-23 17:17:56 +01:00
2021-07-13 09:28:29 -07:00
2021-07-08 14:16:39 -07:00
2021-07-31 09:14:46 -07:00
2021-07-27 20:58:30 +01:00
2021-07-30 18:35:47 +02:00
2021-07-18 09:48:59 -07:00
2021-08-02 15:11:37 +01:00
2021-07-27 11:48:43 +01:00
2021-06-30 15:51:09 -07:00
2021-07-27 20:11:43 +01:00
2021-07-31 09:14:46 -07:00
2021-06-30 15:51:09 -07:00
2021-04-20 16:44:04 -07:00
2021-06-30 15:51:09 -07:00
2021-08-02 10:24:38 +01:00
2021-07-28 09:25:18 +01:00
2021-06-29 11:28:21 -07:00
2021-06-29 11:28:21 -07:00
2021-07-09 09:43:57 -07:00
2021-08-04 12:35:07 +01:00
2021-07-31 09:14:46 -07:00
2021-06-29 15:45:27 -07:00
2021-08-04 09:55:52 +01:00
2021-06-30 15:51:09 -07:00
2021-07-23 10:38:18 +02:00
2021-06-10 14:08:09 -07:00
2021-06-29 15:45:27 -07:00
2021-06-30 15:51:09 -07:00
2021-06-03 15:13:56 -07:00
2021-06-11 12:55:28 -07:00
2021-07-29 15:06:49 +01:00
2021-07-29 15:06:49 +01:00
2021-07-29 15:06:49 +01:00
2021-04-12 13:27:11 -07:00