Skip to content

Commit 47733f9

Browse files
congwangdavem330
authored andcommitted
tipc: fix uninit skb->data in tipc_nl_compat_dumpit()
__tipc_nl_compat_dumpit() has two callers, and it expects them to pass a valid nlmsghdr via arg->data. This header is artificial and crafted just for __tipc_nl_compat_dumpit(). tipc_nl_compat_publ_dump() does so by putting a genlmsghdr as well as some nested attribute, TIPC_NLA_SOCK. But the other caller tipc_nl_compat_dumpit() does not, this leaves arg->data uninitialized on this call path. Fix this by just adding a similar nlmsghdr without any payload in tipc_nl_compat_dumpit(). This bug exists since day 1, but the recent commit 6ea6776 ("net: tipc: prepare attrs in __tipc_nl_compat_dumpit()") makes it easier to appear. Reported-and-tested-by: [email protected] Fixes: d0796d1 ("tipc: convert legacy nl bearer dump to nl compat") Cc: Jon Maloy <[email protected]> Cc: Ying Xue <[email protected]> Cc: Richard Alpe <[email protected]> Signed-off-by: Cong Wang <[email protected]> Acked-by: Ying Xue <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8c26544 commit 47733f9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

net/tipc/netlink_compat.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
275275
static int tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
276276
struct tipc_nl_compat_msg *msg)
277277
{
278-
int err;
278+
struct nlmsghdr *nlh;
279279
struct sk_buff *arg;
280+
int err;
280281

281282
if (msg->req_type && (!msg->req_size ||
282283
!TLV_CHECK_TYPE(msg->req, msg->req_type)))
@@ -305,6 +306,15 @@ static int tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
305306
return -ENOMEM;
306307
}
307308

309+
nlh = nlmsg_put(arg, 0, 0, tipc_genl_family.id, 0, NLM_F_MULTI);
310+
if (!nlh) {
311+
kfree_skb(arg);
312+
kfree_skb(msg->rep);
313+
msg->rep = NULL;
314+
return -EMSGSIZE;
315+
}
316+
nlmsg_end(arg, nlh);
317+
308318
err = __tipc_nl_compat_dumpit(cmd, msg, arg);
309319
if (err) {
310320
kfree_skb(msg->rep);

0 commit comments

Comments
 (0)