Fix attribute list size in do_get_nl_link()
PATCH 1/1 Fix attribute list size in do_get_nl_link()
From: Wang Xin <[email protected]>
The function do_get_nl_link() retrieves attributes from the response RTM_NEWLINK. But it calculates the attribute list size with the wrong structure struct ifaddrmsg. According to man 7 rtnetlink, RTM_NEWLINK message uses struct ifinfomsg instead of struct ifaddrmsg. This causes that additional 8 bytes are parsed and garbage attributes might be retrieved. One of consequences is that the message will be dropped if the garbage attribute is IFLA_IFNAME and contains an invalid interface name.
To fix this issue, use struct ifinfomsg to calculate the size of attribute list for RTM_NEWLINK.
--- src/libsocketcan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/libsocketcan.c +1 -1
@@ -411,7 +411,7 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)struct rtattr *tb[IFLA_MAX +1 ]; len = - nl_msg->nlmsg_len -NLMSG_LENGTH (sizeof (struct ifaddrmsg )); + nl_msg->nlmsg_len -NLMSG_LENGTH (sizeof (struct ifinfomsg ));parse_rtattr (tb,IFLA_MAX ,IFLA_RTA (ifi), len);/* Finish process if the reply message is matched */
Signature · 1 line
2.17.1
Quoted 11 lines · Mark Jonas
From: Wang Xin <[email protected]>
The function
do_get_nl_link()retrieves attributes from the responseRTM_NEWLINK. But it calculates the attribute list size with the wrong structure struct ifaddrmsg. According to man 7 rtnetlink,RTM_NEWLINKmessage uses struct ifinfomsg instead of struct ifaddrmsg. This causes that additional 8 bytes are parsed and garbage attributes might be retrieved. One of consequences is that the message will be dropped if the garbage attribute isIFLA_IFNAMEand contains an invalid interface name.
Quoted 5 lines
To fix this issue, use struct ifinfomsg to calculate the size of attribute list for
RTM_NEWLINK.Signed-off-by Wang Xin <[email protected]>Signed-off-by Mark Jonas <[email protected]>
Applied to master.
Tnx,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi Marc,
Quoted 12 lines · Mark Jonas
Quoted 11 lines
From: Wang Xin <[email protected]>
The function
do_get_nl_link()retrieves attributes from the responseRTM_NEWLINK. But it calculates the attribute list size with the wrong structure struct ifaddrmsg. According to man 7 rtnetlink,RTM_NEWLINKmessage uses struct ifinfomsg instead of struct ifaddrmsg. This causes that additional 8 bytes are parsed and garbage attributes might be retrieved. One of consequences is that the message will be dropped if the garbage attribute isIFLA_IFNAMEand contains an invalid interface name.
Quoted 7 lines
Quoted 5 lines
To fix this issue, use struct ifinfomsg to calculate the size of attribute list for
RTM_NEWLINK.Signed-off-by Wang Xin <[email protected]>Signed-off-by Mark Jonas <[email protected]>Applied to master.
I plan to either add the patch to the libsocketcan recipe in meta-openembedded or to upgrade the recipe to a new version of libsocketcan. I would prefer upgrading the recipe to a new version.
Do you plan to release a new version of libsocketcan soon?
Greetings,
Mark
Marc Kleine-Budde
maintainerQuoted 20 lines · On 11/17/20 4:28 PM, Jonas Mark (BT-FIR/ENG1-Grb) wrote:
Hi Marc,
Quoted 18 lines · Mark Jonas
Quoted 16 lines
From: Wang Xin <[email protected]>
The function
do_get_nl_link()retrieves attributes from the responseRTM_NEWLINK. But it calculates the attribute list size with the wrong structure struct ifaddrmsg. According to man 7 rtnetlink,RTM_NEWLINKmessage uses struct ifinfomsg instead of struct ifaddrmsg. This causes that additional 8 bytes are parsed and garbage attributes might be retrieved. One of consequences is that the message will be dropped if the garbage attribute isIFLA_IFNAMEand contains an invalid interface name.To fix this issue, use struct ifinfomsg to calculate the size of attribute list for
RTM_NEWLINK.Signed-off-by Wang Xin <[email protected]>Signed-off-by Mark Jonas <[email protected]>
Quoted 7 lines
Quoted 1 line
Applied to master.
I plan to either add the patch to the libsocketcan recipe in meta-openembedded or to upgrade the recipe to a new version of libsocketcan. I would prefer upgrading the recipe to a new version.
Do you plan to release a new version of libsocketcan soon?
here you are:
https://git.pengutronix.de/cgit/tools/libsocketcan/tag/?h=v0.0.12
https://public.pengutronix.de/software/libsocketcan/libsocketcan-0.0.12.tar.bz2
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |