Gustavo A. R. Silva
415edd2d66
net/ipv4/ipv6: Replace one-element arraya with flexible-array members
...
[ Upstream commit db243b7964
]
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 >
Stable-dep-of: 5c3be3e0eb
("ipmr: fix incorrect parameter validation in the ip_mroute_getsockopt() function")
Signed-off-by: Sasha Levin <sashal@kernel.org >
2024-03-26 18:21:53 -04:00
..
2023-03-17 08:45:10 +01:00
2023-10-10 21:53:29 +02:00
2024-02-23 08:42:17 +01:00
2024-03-06 14:37:48 +00:00
2022-11-16 09:57:11 +01:00
2024-02-23 08:41:56 +01:00
2021-04-14 08:42:05 +02:00
2021-03-17 17:06:15 +01:00
2023-02-22 12:55:58 +01:00
2023-06-28 10:28:11 +02:00
2023-10-25 11:54:19 +02:00
2023-05-30 12:57:58 +01:00
2023-06-14 11:09:42 +02:00
2024-03-26 18:21:52 -04:00
2023-07-27 08:44:21 +02:00
2022-06-09 10:21:09 +02:00
2022-08-21 15:15:51 +02:00
2023-12-13 18:26:58 +01:00
2022-02-23 12:01:01 +01:00
2023-07-27 08:44:40 +02:00
2021-03-04 11:38:46 +01:00
2022-11-10 18:14:26 +01:00
2022-03-02 11:42:49 +01:00
2023-11-20 11:06:46 +01:00
2024-02-23 08:42:16 +01:00
2023-08-26 15:26:52 +02:00
2023-08-11 11:57:50 +02:00
2024-03-26 18:21:53 -04:00
2020-09-18 17:45:04 -07:00
2021-05-14 09:50:44 +02:00
2021-06-03 09:00:48 +02:00
2023-10-25 11:54:14 +02:00
2020-10-30 12:57:39 +01:00
2021-07-19 09:44:44 +02:00
2023-06-21 15:45:38 +02:00
2023-06-05 09:07:04 +02:00
2021-06-03 09:00:50 +02:00
2024-03-15 10:48:15 -04:00
2023-04-26 11:27:36 +02:00
2022-07-07 17:52:17 +02:00
2022-07-21 21:20:11 +02:00
2022-07-21 21:20:11 +02:00
2024-03-01 13:16:50 +01:00
2023-05-17 11:48:10 +02:00
2023-11-20 11:06:55 +01:00
2020-09-02 15:44:53 -07:00
2023-07-27 08:44:40 +02:00
2023-04-26 11:27:41 +02:00
2021-02-10 09:29:23 +01:00
2023-09-19 12:20:08 +02:00
2023-05-30 12:57:57 +01:00
2023-06-28 10:28:10 +02:00
2022-04-08 14:39:47 +02:00
2023-10-25 11:54:26 +02:00
2020-10-09 12:29:48 +02:00