Netdev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH net] netlink: Fix nlmsg_parse as a wrapper for strict message parsing
@ 2019-08-12 20:07 David Ahern
  2019-08-13 11:31 ` Eric Dumazet
  2019-08-14  3:43 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: David Ahern @ 2019-08-12 20:07 UTC (permalink / raw)
  To: davem; +Cc: netdev, johannes.berg, edumazet, David Ahern

From: David Ahern <dsahern@gmail.com>

Eric reported a syzbot warning:

BUG: KMSAN: uninit-value in nh_valid_get_del_req+0x6f1/0x8c0 net/ipv4/nexthop.c:1510
CPU: 0 PID: 11812 Comm: syz-executor444 Not tainted 5.3.0-rc3+ #17
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x191/0x1f0 lib/dump_stack.c:113
 kmsan_report+0x162/0x2d0 mm/kmsan/kmsan_report.c:109
 __msan_warning+0x75/0xe0 mm/kmsan/kmsan_instr.c:294
 nh_valid_get_del_req+0x6f1/0x8c0 net/ipv4/nexthop.c:1510
 rtm_del_nexthop+0x1b1/0x610 net/ipv4/nexthop.c:1543
 rtnetlink_rcv_msg+0x115a/0x1580 net/core/rtnetlink.c:5223
 netlink_rcv_skb+0x431/0x620 net/netlink/af_netlink.c:2477
 rtnetlink_rcv+0x50/0x60 net/core/rtnetlink.c:5241
 netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
 netlink_unicast+0xf6c/0x1050 net/netlink/af_netlink.c:1328
 netlink_sendmsg+0x110f/0x1330 net/netlink/af_netlink.c:1917
 sock_sendmsg_nosec net/socket.c:637 [inline]
 sock_sendmsg net/socket.c:657 [inline]
 ___sys_sendmsg+0x14ff/0x1590 net/socket.c:2311
 __sys_sendmmsg+0x53a/0xae0 net/socket.c:2413
 __do_sys_sendmmsg net/socket.c:2442 [inline]
 __se_sys_sendmmsg+0xbd/0xe0 net/socket.c:2439
 __x64_sys_sendmmsg+0x56/0x70 net/socket.c:2439
 do_syscall_64+0xbc/0xf0 arch/x86/entry/common.c:297
 entry_SYSCALL_64_after_hwframe+0x63/0xe7

The root cause is nlmsg_parse calling __nla_parse which means the
header struct size is not checked.

nlmsg_parse should be a wrapper around __nlmsg_parse with
NL_VALIDATE_STRICT for the validate argument very much like
nlmsg_parse_deprecated is for NL_VALIDATE_LIBERAL.

Fixes: 3de6440354465 ("netlink: re-add parse/validate functions in strict mode")
Reported-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
---
 include/net/netlink.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/net/netlink.h b/include/net/netlink.h
index e4650e5b64a1..b140c8f1be22 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -684,9 +684,8 @@ static inline int nlmsg_parse(const struct nlmsghdr *nlh, int hdrlen,
 			      const struct nla_policy *policy,
 			      struct netlink_ext_ack *extack)
 {
-	return __nla_parse(tb, maxtype, nlmsg_attrdata(nlh, hdrlen),
-			   nlmsg_attrlen(nlh, hdrlen), policy,
-			   NL_VALIDATE_STRICT, extack);
+	return __nlmsg_parse(nlh, hdrlen, tb, maxtype, policy,
+			     NL_VALIDATE_STRICT, extack);
 }
 
 /**
-- 
2.11.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] netlink: Fix nlmsg_parse as a wrapper for strict message parsing
  2019-08-12 20:07 [PATCH net] netlink: Fix nlmsg_parse as a wrapper for strict message parsing David Ahern
@ 2019-08-13 11:31 ` Eric Dumazet
  2019-08-14  3:43 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2019-08-13 11:31 UTC (permalink / raw)
  To: David Ahern, davem; +Cc: netdev, johannes.berg, edumazet, David Ahern



On 8/12/19 10:07 PM, David Ahern wrote:
> From: David Ahern <dsahern@gmail.com>
> 
> Eric reported a syzbot warning:
> 
> 
> The root cause is nlmsg_parse calling __nla_parse which means the
> header struct size is not checked.
> 
> nlmsg_parse should be a wrapper around __nlmsg_parse with
> NL_VALIDATE_STRICT for the validate argument very much like
> nlmsg_parse_deprecated is for NL_VALIDATE_LIBERAL.
> 
> Fixes: 3de6440354465 ("netlink: re-add parse/validate functions in strict mode")
> Reported-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: David Ahern <dsahern@gmail.com>
> ---

Reviewed-by: Eric Dumazet <edumazet@google.com>

Thanks !


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] netlink: Fix nlmsg_parse as a wrapper for strict message parsing
  2019-08-12 20:07 [PATCH net] netlink: Fix nlmsg_parse as a wrapper for strict message parsing David Ahern
  2019-08-13 11:31 ` Eric Dumazet
@ 2019-08-14  3:43 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2019-08-14  3:43 UTC (permalink / raw)
  To: David Ahern; +Cc: davem, netdev, johannes.berg, edumazet, David Ahern

On Mon, 12 Aug 2019 13:07:07 -0700, David Ahern wrote:
> From: David Ahern <dsahern@gmail.com>
> 
> Eric reported a syzbot warning:
> 
> BUG: KMSAN: uninit-value in nh_valid_get_del_req+0x6f1/0x8c0 net/ipv4/nexthop.c:1510
> CPU: 0 PID: 11812 Comm: syz-executor444 Not tainted 5.3.0-rc3+ #17
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
> Call Trace:
>  __dump_stack lib/dump_stack.c:77 [inline]
>  dump_stack+0x191/0x1f0 lib/dump_stack.c:113
>  kmsan_report+0x162/0x2d0 mm/kmsan/kmsan_report.c:109
>  __msan_warning+0x75/0xe0 mm/kmsan/kmsan_instr.c:294
>  nh_valid_get_del_req+0x6f1/0x8c0 net/ipv4/nexthop.c:1510
>  rtm_del_nexthop+0x1b1/0x610 net/ipv4/nexthop.c:1543
>  rtnetlink_rcv_msg+0x115a/0x1580 net/core/rtnetlink.c:5223
>  netlink_rcv_skb+0x431/0x620 net/netlink/af_netlink.c:2477
>  rtnetlink_rcv+0x50/0x60 net/core/rtnetlink.c:5241
>  netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
>  netlink_unicast+0xf6c/0x1050 net/netlink/af_netlink.c:1328
>  netlink_sendmsg+0x110f/0x1330 net/netlink/af_netlink.c:1917
>  sock_sendmsg_nosec net/socket.c:637 [inline]
>  sock_sendmsg net/socket.c:657 [inline]
>  ___sys_sendmsg+0x14ff/0x1590 net/socket.c:2311
>  __sys_sendmmsg+0x53a/0xae0 net/socket.c:2413
>  __do_sys_sendmmsg net/socket.c:2442 [inline]
>  __se_sys_sendmmsg+0xbd/0xe0 net/socket.c:2439
>  __x64_sys_sendmmsg+0x56/0x70 net/socket.c:2439
>  do_syscall_64+0xbc/0xf0 arch/x86/entry/common.c:297
>  entry_SYSCALL_64_after_hwframe+0x63/0xe7
> 
> The root cause is nlmsg_parse calling __nla_parse which means the
> header struct size is not checked.
> 
> nlmsg_parse should be a wrapper around __nlmsg_parse with
> NL_VALIDATE_STRICT for the validate argument very much like
> nlmsg_parse_deprecated is for NL_VALIDATE_LIBERAL.
> 
> Fixes: 3de6440354465 ("netlink: re-add parse/validate functions in strict mode")
> Reported-by: Eric Dumazet <edumazet@google.com>
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: David Ahern <dsahern@gmail.com>

Applied, thank you!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 20:07 [PATCH net] netlink: Fix nlmsg_parse as a wrapper for strict message parsing David Ahern
2019-08-13 11:31 ` Eric Dumazet
2019-08-14  3:43 ` Jakub Kicinski

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org netdev@archiver.kernel.org
	public-inbox-index netdev


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox