ipv4: Check attribute length for RTA_GATEWAY
Subsystems (3)
David Ahern
maintainerPATCH 1/1 ipv4: Check attribute length for RTA_GATEWAY
syzbot reported uninit-value:
============================================================
BUG: KMSAN: uninit-value in fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_create_info+0x2411/0x4870 net/ipv4/fib_semantics.c:1453 fib_table_insert+0x45c/0x3a10 net/ipv4/fib_trie.c:1224 inet_rtm_newroute+0x289/0x420 net/ipv4/fib_frontend.c:886
Add length checking before using the attribute.
---
I do not have KMSAN setup, so this is based on a code analysis. Before 4e902c57417c fib_get_attr32 was checking the attribute length; the switch to nla_get_u32 does not.
net/ipv4/fib_semantics.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv4/fib_semantics.c +4 -0
@@ -704,6 +704,10 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,return -EINVAL ; }if (nla) { +if (nla_len (nla) <sizeof (__be32)) { +NL_SET_ERR_MSG (extack,"Invalid IPv4 address in RTA_GATEWAY" ); +return -EINVAL ; + } fib_cfg.fc_gw4 =nla_get_in_addr (nla);if (fib_cfg.fc_gw4) fib_cfg.fc_gw_family =AF_INET ;
Signature · 1 line
2.24.3 (Apple Git-128)
Quoted 9 lines · David Ahern
syzbot reported uninit-value:
============================================================BUG: KMSAN: uninit-value in fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_create_info+0x2411/0x4870 net/ipv4/fib_semantics.c:1453 fib_table_insert+0x45c/0x3a10 net/ipv4/fib_trie.c:1224 inet_rtm_newroute+0x289/0x420 net/ipv4/fib_frontend.c:886
Quoted 8 lines
Add length checking before using the attribute.
Fixes 4e902c57417c ("[IPv4]: FIB configuration using struct fib_config")Reported-by [email protected]Signed-off-by David Ahern <[email protected]>Cc Thomas Graf <[email protected]>---
I do not have KMSAN setup, so this is based on a code analysis. Before
Was using this in the past:
https://github.com/google/syzkaller/blob/master/docs/syzbot.md#kmsan-bugs
Quoted 11 lines
4e902c57417cfib_get_attr32was checking the attribute length; the switch tonla_get_u32does not.net/ipv4/fib_semantics.c | 4 ++++ 1 file changed, 4 insertions(+)net/ipv4/fib_semantics.c +0
-0
net/ipv4/fib_semantics.c static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, · line 710
Quoted 7 lines
net/ipv4/fib_semantics.c +4
-0@@ -704,6 +704,10 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,return -EINVAL ; }if (nla) { +if (nla_len (nla) <sizeof (__be32)) { +NL_SET_ERR_MSG (extack,"Invalid IPv4 address in RTA_GATEWAY" ); +return -EINVAL ; + }
Isn't the problem more general than that? It seems that there is no minimum length validation to any of the attributes inside RTA_MULTIPATH. Except maybe RTA_VIA
Quoted 6 lines
net/ipv4/fib_semantics.c +0
-0fib_cfg.fc_gw4 =nla_get_in_addr (nla);if (fib_cfg.fc_gw4) fib_cfg.fc_gw_family =AF_INET ;Signature · 1 line
2.24.3 (Apple Git-128)
Quoted 19 lines · Ido Schimmel
Quoted 9 lines · David Ahern
syzbot reported uninit-value:
============================================================BUG: KMSAN: uninit-value in fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_create_info+0x2411/0x4870 net/ipv4/fib_semantics.c:1453 fib_table_insert+0x45c/0x3a10 net/ipv4/fib_trie.c:1224 inet_rtm_newroute+0x289/0x420 net/ipv4/fib_frontend.c:886Quoted 8 lines
Add length checking before using the attribute.
Fixes 4e902c57417c ("[IPv4]: FIB configuration using struct fib_config")Reported-by [email protected]Signed-off-by David Ahern <[email protected]>Cc Thomas Graf <[email protected]>---
I do not have KMSAN setup, so this is based on a code analysis. Before
Quoted 2 lines
Was using this in the past:
https://github.com/google/syzkaller/blob/master/docs/syzbot.md#kmsan-bugs
thanks for the pointer. I am a bit hardware challenged at the moment for out of tree features.
Quoted 7 lines
Quoted 7 lines
4e902c57417cfib_get_attr32was checking the attribute length; the switch tonla_get_u32does not.net/ipv4/fib_semantics.c | 4 ++++ 1 file changed, 4 insertions(+)
Quoted 17 lines
net/ipv4/fib_semantics.c static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, · line 710
Quoted 12 lines
net/ipv4/fib_semantics.c +4
-0@@ -704,6 +704,10 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,return -EINVAL ; }if (nla) { +if (nla_len (nla) <sizeof (__be32)) { +NL_SET_ERR_MSG (extack,"Invalid IPv4 address in RTA_GATEWAY" ); +return -EINVAL ; + }Isn't the problem more general than that? It seems that there is no minimum length validation to any of the attributes inside
RTA_MULTIPATH. Except maybeRTA_VIA
A follow up commit is needed for RTA_FLOW.
Quoted 51 lines · David Ahern
Quoted 19 lines · Ido Schimmel
Quoted 9 lines · David Ahern
syzbot reported uninit-value:
============================================================BUG: KMSAN: uninit-value in fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_get_nhs+0xac4/0x1f80 net/ipv4/fib_semantics.c:708 fib_create_info+0x2411/0x4870 net/ipv4/fib_semantics.c:1453 fib_table_insert+0x45c/0x3a10 net/ipv4/fib_trie.c:1224 inet_rtm_newroute+0x289/0x420 net/ipv4/fib_frontend.c:886Quoted 8 lines
Add length checking before using the attribute.
Fixes 4e902c57417c ("[IPv4]: FIB configuration using struct fib_config")Reported-by [email protected]Signed-off-by David Ahern <[email protected]>Cc Thomas Graf <[email protected]>---
I do not have KMSAN setup, so this is based on a code analysis. BeforeQuoted 2 lines
Was using this in the past:
https://github.com/google/syzkaller/blob/master/docs/syzbot.md#kmsan-bugsthanks for the pointer. I am a bit hardware challenged at the moment for out of tree features.
Quoted 7 lines
Quoted 7 lines
4e902c57417cfib_get_attr32was checking the attribute length; the switch tonla_get_u32does not.net/ipv4/fib_semantics.c | 4 ++++ 1 file changed, 4 insertions(+)Quoted 17 lines
net/ipv4/fib_semantics.c static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, · line 710
Quoted 12 lines
net/ipv4/fib_semantics.c +4
-0@@ -704,6 +704,10 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,return -EINVAL ; }if (nla) { +if (nla_len (nla) <sizeof (__be32)) { +NL_SET_ERR_MSG (extack,"Invalid IPv4 address in RTA_GATEWAY" ); +return -EINVAL ; + }Isn't the problem more general than that? It seems that there is no minimum length validation to any of the attributes inside
RTA_MULTIPATH. Except maybeRTA_VIA
Quoted 1 line
A follow up commit is needed for
RTA_FLOW.
The same problem seems to exists in the delete path and IPv6. See fib_nh_match() and ip6_route_multipath_add(), for example.