netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] rtnetlink: allocate more memory for dev_set_mac_address()
@ 2017-07-20 18:27 Cong Wang
  2017-07-20 18:27 ` [Patch net] net: check mac address length " Cong Wang
  2017-07-20 22:23 ` [Patch net] rtnetlink: allocate more memory " David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Cong Wang @ 2017-07-20 18:27 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, Cong Wang

virtnet_set_mac_address() interprets mac address as struct
sockaddr, but upper layer only allocates dev->addr_len
which is ETH_ALEN + sizeof(sa_family_t) in this case.

We lack a unified definition for mac address, so just fix
the upper layer, this also allows drivers to interpret it
to struct sockaddr freely.

Reported-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/core/rtnetlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index d1ba90980be1..ebaa26cf777f 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2031,7 +2031,8 @@ static int do_setlink(const struct sk_buff *skb,
 		struct sockaddr *sa;
 		int len;
 
-		len = sizeof(sa_family_t) + dev->addr_len;
+		len = sizeof(sa_family_t) + max_t(size_t, dev->addr_len,
+						  sizeof(*sa));
 		sa = kmalloc(len, GFP_KERNEL);
 		if (!sa) {
 			err = -ENOMEM;
-- 
2.13.0

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

end of thread, other threads:[~2017-07-21 18:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-20 18:27 [Patch net] rtnetlink: allocate more memory for dev_set_mac_address() Cong Wang
2017-07-20 18:27 ` [Patch net] net: check mac address length " Cong Wang
2017-07-20 23:39   ` Cong Wang
2017-07-21 18:50   ` Cong Wang
2017-07-20 22:23 ` [Patch net] rtnetlink: allocate more memory " 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).