Skip to content

Commit 4f07b80

Browse files
lxindavem330
authored andcommitted
tipc: check msg->req data len in tipc_nl_compat_bearer_disable
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(). v1->v2: - add the missing Fixes tags per Eric's request. Fixes: 0762216 ("tipc: fix uninit-value in tipc_nl_compat_bearer_enable") Fixes: 8b66fee ("tipc: fix uninit-value in tipc_nl_compat_link_reset_stats") Reported-by: [email protected] Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2bf4ecb commit 4f07b80

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

net/tipc/netlink_compat.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,11 @@ static int tipc_nl_compat_bearer_disable(struct tipc_nl_compat_cmd_doit *cmd,
445445
if (!bearer)
446446
return -EMSGSIZE;
447447

448-
len = min_t(int, TLV_GET_DATA_LEN(msg->req), TIPC_MAX_BEARER_NAME);
448+
len = TLV_GET_DATA_LEN(msg->req);
449+
if (len <= 0)
450+
return -EINVAL;
451+
452+
len = min_t(int, len, TIPC_MAX_BEARER_NAME);
449453
if (!string_is_valid(name, len))
450454
return -EINVAL;
451455

@@ -539,7 +543,11 @@ static int tipc_nl_compat_link_stat_dump(struct tipc_nl_compat_msg *msg,
539543

540544
name = (char *)TLV_DATA(msg->req);
541545

542-
len = min_t(int, TLV_GET_DATA_LEN(msg->req), TIPC_MAX_LINK_NAME);
546+
len = TLV_GET_DATA_LEN(msg->req);
547+
if (len <= 0)
548+
return -EINVAL;
549+
550+
len = min_t(int, len, TIPC_MAX_BEARER_NAME);
543551
if (!string_is_valid(name, len))
544552
return -EINVAL;
545553

@@ -817,7 +825,11 @@ static int tipc_nl_compat_link_reset_stats(struct tipc_nl_compat_cmd_doit *cmd,
817825
if (!link)
818826
return -EMSGSIZE;
819827

820-
len = min_t(int, TLV_GET_DATA_LEN(msg->req), TIPC_MAX_LINK_NAME);
828+
len = TLV_GET_DATA_LEN(msg->req);
829+
if (len <= 0)
830+
return -EINVAL;
831+
832+
len = min_t(int, len, TIPC_MAX_BEARER_NAME);
821833
if (!string_is_valid(name, len))
822834
return -EINVAL;
823835

0 commit comments

Comments
 (0)