netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] tipc: check msg->req data len in tipc_nl_compat_bearer_disable
@ 2019-06-24  7:59 Xin Long
  2019-06-24  8:33 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Xin Long @ 2019-06-24  7:59 UTC (permalink / raw)
  To: network dev; +Cc: davem, Jon Maloy, Ying Xue, tipc-discussion, syzkaller-bugs

This patch is to fix an uninit-value issue, reported by syzbot:

  BUG: KMSAN: uninit-value in memchr+0xce/0x110 lib/string.c:981
  Call Trace:
    __dump_stack lib/dump_stack.c:77 [inline]
    dump_stack+0x191/0x1f0 lib/dump_stack.c:113
    kmsan_report+0x130/0x2a0 mm/kmsan/kmsan.c:622
    __msan_warning+0x75/0xe0 mm/kmsan/kmsan_instr.c:310
    memchr+0xce/0x110 lib/string.c:981
    string_is_valid net/tipc/netlink_compat.c:176 [inline]
    tipc_nl_compat_bearer_disable+0x2a1/0x480 net/tipc/netlink_compat.c:449
    __tipc_nl_compat_doit net/tipc/netlink_compat.c:327 [inline]
    tipc_nl_compat_doit+0x3ac/0xb00 net/tipc/netlink_compat.c:360
    tipc_nl_compat_handle net/tipc/netlink_compat.c:1178 [inline]
    tipc_nl_compat_recv+0x1b1b/0x27b0 net/tipc/netlink_compat.c:1281

TLV_GET_DATA_LEN() may return a negtive int value, which will be
used as size_t (becoming a big unsigned long) passed into memchr,
cause this issue.

Similar to what it does in tipc_nl_compat_bearer_enable(), this
fix is to return -EINVAL when TLV_GET_DATA_LEN() is negtive in
tipc_nl_compat_bearer_disable(), as well as in
tipc_nl_compat_link_stat_dump() and tipc_nl_compat_link_reset_stats().

Reported-by: syzbot+30eaa8bf392f7fafffaf@syzkaller.appspotmail.com
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/tipc/netlink_compat.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c
index c6a04c0..cf15506 100644
--- a/net/tipc/netlink_compat.c
+++ b/net/tipc/netlink_compat.c
@@ -445,7 +445,11 @@ static int tipc_nl_compat_bearer_disable(struct tipc_nl_compat_cmd_doit *cmd,
 	if (!bearer)
 		return -EMSGSIZE;
 
-	len = min_t(int, TLV_GET_DATA_LEN(msg->req), TIPC_MAX_BEARER_NAME);
+	len = TLV_GET_DATA_LEN(msg->req);
+	if (len <= 0)
+		return -EINVAL;
+
+	len = min_t(int, len, TIPC_MAX_BEARER_NAME);
 	if (!string_is_valid(name, len))
 		return -EINVAL;
 
@@ -539,7 +543,11 @@ static int tipc_nl_compat_link_stat_dump(struct tipc_nl_compat_msg *msg,
 
 	name = (char *)TLV_DATA(msg->req);
 
-	len = min_t(int, TLV_GET_DATA_LEN(msg->req), TIPC_MAX_LINK_NAME);
+	len = TLV_GET_DATA_LEN(msg->req);
+	if (len <= 0)
+		return -EINVAL;
+
+	len = min_t(int, len, TIPC_MAX_BEARER_NAME);
 	if (!string_is_valid(name, len))
 		return -EINVAL;
 
@@ -817,7 +825,11 @@ static int tipc_nl_compat_link_reset_stats(struct tipc_nl_compat_cmd_doit *cmd,
 	if (!link)
 		return -EMSGSIZE;
 
-	len = min_t(int, TLV_GET_DATA_LEN(msg->req), TIPC_MAX_LINK_NAME);
+	len = TLV_GET_DATA_LEN(msg->req);
+	if (len <= 0)
+		return -EINVAL;
+
+	len = min_t(int, len, TIPC_MAX_BEARER_NAME);
 	if (!string_is_valid(name, len))
 		return -EINVAL;
 
-- 
2.1.0


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

* Re: [PATCH net] tipc: check msg->req data len in tipc_nl_compat_bearer_disable
  2019-06-24  7:59 [PATCH net] tipc: check msg->req data len in tipc_nl_compat_bearer_disable Xin Long
@ 2019-06-24  8:33 ` Eric Dumazet
  2019-06-24 16:00   ` Xin Long
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2019-06-24  8:33 UTC (permalink / raw)
  To: Xin Long, network dev
  Cc: davem, Jon Maloy, Ying Xue, tipc-discussion, syzkaller-bugs



On 6/24/19 12:59 AM, Xin Long wrote:
> This patch is to fix an uninit-value issue, reported by syzbot:
> 
>   BUG: KMSAN: uninit-value in memchr+0xce/0x110 lib/string.c:981
>   Call Trace:
>     __dump_stack lib/dump_stack.c:77 [inline]
>     dump_stack+0x191/0x1f0 lib/dump_stack.c:113
>     kmsan_report+0x130/0x2a0 mm/kmsan/kmsan.c:622
>     __msan_warning+0x75/0xe0 mm/kmsan/kmsan_instr.c:310
>     memchr+0xce/0x110 lib/string.c:981
>     string_is_valid net/tipc/netlink_compat.c:176 [inline]
>     tipc_nl_compat_bearer_disable+0x2a1/0x480 net/tipc/netlink_compat.c:449
>     __tipc_nl_compat_doit net/tipc/netlink_compat.c:327 [inline]
>     tipc_nl_compat_doit+0x3ac/0xb00 net/tipc/netlink_compat.c:360
>     tipc_nl_compat_handle net/tipc/netlink_compat.c:1178 [inline]
>     tipc_nl_compat_recv+0x1b1b/0x27b0 net/tipc/netlink_compat.c:1281
> 
> TLV_GET_DATA_LEN() may return a negtive int value, which will be
> used as size_t (becoming a big unsigned long) passed into memchr,
> cause this issue.
> 
> Similar to what it does in tipc_nl_compat_bearer_enable(), this
> fix is to return -EINVAL when TLV_GET_DATA_LEN() is negtive in
> tipc_nl_compat_bearer_disable(), as well as in
> tipc_nl_compat_link_stat_dump() and tipc_nl_compat_link_reset_stats().
> 
> Reported-by: syzbot+30eaa8bf392f7fafffaf@syzkaller.appspotmail.com
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Please add an appropriate Fixes: tag, thanks !


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

* Re: [PATCH net] tipc: check msg->req data len in tipc_nl_compat_bearer_disable
  2019-06-24  8:33 ` Eric Dumazet
@ 2019-06-24 16:00   ` Xin Long
  2019-06-24 16:21     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Xin Long @ 2019-06-24 16:00 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: network dev, davem, Jon Maloy, Ying Xue, tipc-discussion, syzkaller-bugs

On Mon, Jun 24, 2019 at 4:33 PM Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
>
>
> On 6/24/19 12:59 AM, Xin Long wrote:
> > This patch is to fix an uninit-value issue, reported by syzbot:
> >
> >   BUG: KMSAN: uninit-value in memchr+0xce/0x110 lib/string.c:981
> >   Call Trace:
> >     __dump_stack lib/dump_stack.c:77 [inline]
> >     dump_stack+0x191/0x1f0 lib/dump_stack.c:113
> >     kmsan_report+0x130/0x2a0 mm/kmsan/kmsan.c:622
> >     __msan_warning+0x75/0xe0 mm/kmsan/kmsan_instr.c:310
> >     memchr+0xce/0x110 lib/string.c:981
> >     string_is_valid net/tipc/netlink_compat.c:176 [inline]
> >     tipc_nl_compat_bearer_disable+0x2a1/0x480 net/tipc/netlink_compat.c:449
> >     __tipc_nl_compat_doit net/tipc/netlink_compat.c:327 [inline]
> >     tipc_nl_compat_doit+0x3ac/0xb00 net/tipc/netlink_compat.c:360
> >     tipc_nl_compat_handle net/tipc/netlink_compat.c:1178 [inline]
> >     tipc_nl_compat_recv+0x1b1b/0x27b0 net/tipc/netlink_compat.c:1281
> >
> > TLV_GET_DATA_LEN() may return a negtive int value, which will be
> > used as size_t (becoming a big unsigned long) passed into memchr,
> > cause this issue.
> >
> > Similar to what it does in tipc_nl_compat_bearer_enable(), this
> > fix is to return -EINVAL when TLV_GET_DATA_LEN() is negtive in
> > tipc_nl_compat_bearer_disable(), as well as in
> > tipc_nl_compat_link_stat_dump() and tipc_nl_compat_link_reset_stats().
> >
> > Reported-by: syzbot+30eaa8bf392f7fafffaf@syzkaller.appspotmail.com
> > Signed-off-by: Xin Long <lucien.xin@gmail.com>
>
> Please add an appropriate Fixes: tag, thanks !
>
Fixes: 0762216c0ad2 ("tipc: fix uninit-value in tipc_nl_compat_bearer_enable")
Fixes: 8b66fee7f8ee (:tipc: fix uninit-value in
tipc_nl_compat_link_reset_stats")

Sorry, David, do I need to resend this one?

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

* Re: [PATCH net] tipc: check msg->req data len in tipc_nl_compat_bearer_disable
  2019-06-24 16:00   ` Xin Long
@ 2019-06-24 16:21     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-06-24 16:21 UTC (permalink / raw)
  To: lucien.xin
  Cc: eric.dumazet, netdev, jon.maloy, ying.xue, tipc-discussion,
	syzkaller-bugs

From: Xin Long <lucien.xin@gmail.com>
Date: Tue, 25 Jun 2019 00:00:39 +0800

> Sorry, David, do I need to resend this one?

Yes, please, that helps me a lot.

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

end of thread, other threads:[~2019-06-24 16:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24  7:59 [PATCH net] tipc: check msg->req data len in tipc_nl_compat_bearer_disable Xin Long
2019-06-24  8:33 ` Eric Dumazet
2019-06-24 16:00   ` Xin Long
2019-06-24 16:21     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).