All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Phillip Potter <phil@philpotter.co.uk>
Cc: davem@davemloft.net, kuba@kernel.org, yhs@fb.com, ast@kernel.org,
	johannes.berg@intel.com, rdunlap@infradead.org,
	0x7f454c46@gmail.com, yangyingliang@huawei.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] netlink: netlink_sendmsg: memset unused tail bytes in skb
Date: Sun, 9 May 2021 15:10:51 +0200	[thread overview]
Message-ID: <20210509131051.GD4038@breakpoint.cc> (raw)
In-Reply-To: <20210509121858.1232583-1-phil@philpotter.co.uk>

Phillip Potter <phil@philpotter.co.uk> wrote:
> When allocating the skb within netlink_sendmsg, with certain supplied
> len arguments, extra bytes are allocated at the end of the data buffer,
> due to SKB_DATA_ALIGN giving a larger size within __alloc_skb for
> alignment reasons. This means that after using skb_put with the same
> len value and then copying data into the skb, the skb tail area is
> non-zero in size and contains uninitialised bytes. Wiping this area
> (if it exists) fixes a KMSAN-found uninit-value bug reported by syzbot at:
> https://syzkaller.appspot.com/bug?id=3e63bcec536b7136b54c72e06adeb87dc6519f69

This patch papers over the real bug.

Please fix TIPC instead.
Incomplete patch as a starting point:

diff --git a/net/tipc/node.c b/net/tipc/node.c
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -2481,7 +2481,6 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
 	struct net *net = genl_info_net(info);
 	struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
 	struct tipc_nl_msg msg;
-	char *name;
 	int err;
 
 	msg.portid = info->snd_portid;
@@ -2499,13 +2498,11 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
 	if (!attrs[TIPC_NLA_LINK_NAME])
 		return -EINVAL;
 
-	name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
-
 	msg.skb = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
 	if (!msg.skb)
 		return -ENOMEM;
 
-	if (strcmp(name, tipc_bclink_name) == 0) {
+	if (nla_strcmp(attrs[TIPC_NLA_LINK_NAME], tipc_bclink_name) == 0) {
 		err = tipc_nl_add_bc_link(net, &msg, tipc_net(net)->bcl);
 		if (err)
 			goto err_free;


You will also need to change tipc_node_find_by_name() to pass the nla
attr.

Alternatively TIPC_NLA_LINK_NAME policy can be changed:

diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -88,7 +88,7 @@ const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = {
 
 const struct nla_policy tipc_nl_link_policy[TIPC_NLA_LINK_MAX + 1] = {
        [TIPC_NLA_LINK_UNSPEC]          = { .type = NLA_UNSPEC },
-       [TIPC_NLA_LINK_NAME]            = { .type = NLA_STRING,
+       [TIPC_NLA_LINK_NAME]            = { .type = NLA_NUL_STRING,


... which makes it safe to treat the raw attribute payload as a c-string,
but this might break existing userspace applications.

Its probably a good idea to audit all NLA_STRING attributes in tipc for
similar problems.

  reply	other threads:[~2021-05-09 13:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-09 12:18 [PATCH] netlink: netlink_sendmsg: memset unused tail bytes in skb Phillip Potter
2021-05-09 13:10 ` Florian Westphal [this message]
2021-05-11 22:17   ` Phillip Potter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210509131051.GD4038@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=0x7f454c46@gmail.com \
    --cc=ast@kernel.org \
    --cc=davem@davemloft.net \
    --cc=johannes.berg@intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=phil@philpotter.co.uk \
    --cc=rdunlap@infradead.org \
    --cc=yangyingliang@huawei.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.