Bump version to v1.5 and start work on adding 4.19 kernel suppot
[librecmc/librecmc.git] / package / utils / busybox / patches / 302-netlink-alignment.patch
1 From a843f09a4d4428cf11ca02307e60058251b05743 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Fri, 16 Sep 2016 21:52:03 +0200
4 Subject: [PATCH] libnetlink: fix alignment of netlink messages
5
6 An padding to align a message should not only be added between
7 different attributes of a netlink message, but also at the end of the
8 message to pad it to the correct size.
9
10 Without this patch the following command does not work and returns an
11 error code:
12 ip link add type nlmon
13
14 Without this ip from busybox sends this:
15 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=45, type=0x10 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK|0x600, seq=1474057401, pid=0}, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon"}, iov_len=45}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 45
16 return value: 2
17
18 The normal ip utile from iproute2 sends this:
19 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=48, type=0x10 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK|0x600, seq=1473716938, pid=0}, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon\0\0\0"}, iov_len=48}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48
20 return value: 0
21
22 With this patch ip from busybox sends this:
23 sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base={{len=48, type=0x10 /* NLMSG_??? */, flags=NLM_F_REQUEST|NLM_F_ACK|0x600, seq=1473716908, pid=0}, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon\0\0\0"}, iov_len=48}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48
24 return value: 0
25
26 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
27 ---
28  networking/libiproute/libnetlink.c | 16 ++++++++--------
29  1 file changed, 8 insertions(+), 8 deletions(-)
30
31 --- a/networking/libiproute/libnetlink.c
32 +++ b/networking/libiproute/libnetlink.c
33 @@ -338,14 +338,14 @@ int FAST_FUNC addattr32(struct nlmsghdr
34         int len = RTA_LENGTH(4);
35         struct rtattr *rta;
36  
37 -       if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) {
38 +       if ((int)(NLMSG_ALIGN(n->nlmsg_len + len)) > maxlen) {
39                 return -1;
40         }
41         rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len));
42         rta->rta_type = type;
43         rta->rta_len = len;
44         move_to_unaligned32(RTA_DATA(rta), data);
45 -       n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
46 +       n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len + len);
47         return 0;
48  }
49  
50 @@ -354,14 +354,14 @@ int FAST_FUNC addattr_l(struct nlmsghdr
51         int len = RTA_LENGTH(alen);
52         struct rtattr *rta;
53  
54 -       if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) {
55 +       if ((int)(NLMSG_ALIGN(n->nlmsg_len + len)) > maxlen) {
56                 return -1;
57         }
58         rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len));
59         rta->rta_type = type;
60         rta->rta_len = len;
61         memcpy(RTA_DATA(rta), data, alen);
62 -       n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len;
63 +       n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len + len);
64         return 0;
65  }
66  
67 @@ -370,14 +370,14 @@ int FAST_FUNC rta_addattr32(struct rtatt
68         int len = RTA_LENGTH(4);
69         struct rtattr *subrta;
70  
71 -       if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
72 +       if (RTA_ALIGN(rta->rta_len + len) > maxlen) {
73                 return -1;
74         }
75         subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
76         subrta->rta_type = type;
77         subrta->rta_len = len;
78         move_to_unaligned32(RTA_DATA(subrta), data);
79 -       rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
80 +       rta->rta_len = NLMSG_ALIGN(rta->rta_len + len);
81         return 0;
82  }
83  
84 @@ -386,14 +386,14 @@ int FAST_FUNC rta_addattr_l(struct rtatt
85         struct rtattr *subrta;
86         int len = RTA_LENGTH(alen);
87  
88 -       if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
89 +       if (RTA_ALIGN(rta->rta_len + len) > maxlen) {
90                 return -1;
91         }
92         subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
93         subrta->rta_type = type;
94         subrta->rta_len = len;
95         memcpy(RTA_DATA(subrta), data, alen);
96 -       rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
97 +       rta->rta_len = NLMSG_ALIGN(rta->rta_len + len);
98         return 0;
99  }
100