All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 net] rtnetlink: Fix memory(net_device) leak when ->newlink fails
@ 2020-07-15  1:49 Weilong Chen
  2020-07-15  5:45 ` Cong Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Weilong Chen @ 2020-07-15  1:49 UTC (permalink / raw)
  To: davem, kuba, jiri, edumazet, chenweilong; +Cc: netdev, linux-kernel

When vlan_newlink call register_vlan_dev fails, it might return error
with dev->reg_state = NETREG_UNREGISTERED. The rtnl_newlink should
free the memory. But currently rtnl_newlink only free the memory which
state is NETREG_UNINITIALIZED.

BUG: memory leak
unreferenced object 0xffff8881051de000 (size 4096):
  comm "syz-executor139", pid 560, jiffies 4294745346 (age 32.445s)
  hex dump (first 32 bytes):
    76 6c 61 6e 32 00 00 00 00 00 00 00 00 00 00 00  vlan2...........
    00 45 28 03 81 88 ff ff 00 00 00 00 00 00 00 00  .E(.............
  backtrace:
    [<0000000047527e31>] kmalloc_node include/linux/slab.h:578 [inline]
    [<0000000047527e31>] kvmalloc_node+0x33/0xd0 mm/util.c:574
    [<000000002b59e3bc>] kvmalloc include/linux/mm.h:753 [inline]
    [<000000002b59e3bc>] kvzalloc include/linux/mm.h:761 [inline]
    [<000000002b59e3bc>] alloc_netdev_mqs+0x83/0xd90 net/core/dev.c:9929
    [<000000006076752a>] rtnl_create_link+0x2c0/0xa20 net/core/rtnetlink.c:3067
    [<00000000572b3be5>] __rtnl_newlink+0xc9c/0x1330 net/core/rtnetlink.c:3329
    [<00000000e84ea553>] rtnl_newlink+0x66/0x90 net/core/rtnetlink.c:3397
    [<0000000052c7c0a9>] rtnetlink_rcv_msg+0x540/0x990 net/core/rtnetlink.c:5460
    [<000000004b5cb379>] netlink_rcv_skb+0x12b/0x3a0 net/netlink/af_netlink.c:2469
    [<00000000c71c20d3>] netlink_unicast_kernel net/netlink/af_netlink.c:1303 [inline]
    [<00000000c71c20d3>] netlink_unicast+0x4c6/0x690 net/netlink/af_netlink.c:1329
    [<00000000cca72fa9>] netlink_sendmsg+0x735/0xcc0 net/netlink/af_netlink.c:1918
    [<000000009221ebf7>] sock_sendmsg_nosec net/socket.c:652 [inline]
    [<000000009221ebf7>] sock_sendmsg+0x109/0x140 net/socket.c:672
    [<000000001c30ffe4>] ____sys_sendmsg+0x5f5/0x780 net/socket.c:2352
    [<00000000b71ca6f3>] ___sys_sendmsg+0x11d/0x1a0 net/socket.c:2406
    [<0000000007297384>] __sys_sendmsg+0xeb/0x1b0 net/socket.c:2439
    [<000000000eb29b11>] do_syscall_64+0x56/0xa0 arch/x86/entry/common.c:359
    [<000000006839b4d0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9

Fixes: e51fb152318ee6 ("rtnetlink: fix a memory leak when ->newlink fails")
Reported-by: Hulk Robot <hulkci@huawei.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Weilong Chen <chenweilong@huawei.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 9aedc15736ad..85a4b0101f76 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3343,7 +3343,8 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 		 */
 		if (err < 0) {
 			/* If device is not registered at all, free it now */
-			if (dev->reg_state == NETREG_UNINITIALIZED)
+			if (dev->reg_state == NETREG_UNINITIALIZED ||
+			    dev->reg_state == NETREG_UNREGISTERED)
 				free_netdev(dev);
 			goto out;
 		}
-- 
2.17.1


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

* Re: [PATCH v4 net] rtnetlink: Fix memory(net_device) leak when ->newlink fails
  2020-07-15  1:49 [PATCH v4 net] rtnetlink: Fix memory(net_device) leak when ->newlink fails Weilong Chen
@ 2020-07-15  5:45 ` Cong Wang
  2020-07-15  7:11   ` Weilong Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Cong Wang @ 2020-07-15  5:45 UTC (permalink / raw)
  To: Weilong Chen
  Cc: David Miller, Jakub Kicinski, Jiri Pirko, Eric Dumazet,
	Linux Kernel Network Developers, LKML

On Tue, Jul 14, 2020 at 6:27 PM Weilong Chen <chenweilong@huawei.com> wrote:
>
> When vlan_newlink call register_vlan_dev fails, it might return error
> with dev->reg_state = NETREG_UNREGISTERED. The rtnl_newlink should
> free the memory. But currently rtnl_newlink only free the memory which
> state is NETREG_UNINITIALIZED.
>
> BUG: memory leak
> unreferenced object 0xffff8881051de000 (size 4096):
>   comm "syz-executor139", pid 560, jiffies 4294745346 (age 32.445s)
>   hex dump (first 32 bytes):
>     76 6c 61 6e 32 00 00 00 00 00 00 00 00 00 00 00  vlan2...........
>     00 45 28 03 81 88 ff ff 00 00 00 00 00 00 00 00  .E(.............
>   backtrace:
>     [<0000000047527e31>] kmalloc_node include/linux/slab.h:578 [inline]
>     [<0000000047527e31>] kvmalloc_node+0x33/0xd0 mm/util.c:574
>     [<000000002b59e3bc>] kvmalloc include/linux/mm.h:753 [inline]
>     [<000000002b59e3bc>] kvzalloc include/linux/mm.h:761 [inline]
>     [<000000002b59e3bc>] alloc_netdev_mqs+0x83/0xd90 net/core/dev.c:9929
>     [<000000006076752a>] rtnl_create_link+0x2c0/0xa20 net/core/rtnetlink.c:3067
>     [<00000000572b3be5>] __rtnl_newlink+0xc9c/0x1330 net/core/rtnetlink.c:3329
>     [<00000000e84ea553>] rtnl_newlink+0x66/0x90 net/core/rtnetlink.c:3397
>     [<0000000052c7c0a9>] rtnetlink_rcv_msg+0x540/0x990 net/core/rtnetlink.c:5460
>     [<000000004b5cb379>] netlink_rcv_skb+0x12b/0x3a0 net/netlink/af_netlink.c:2469
>     [<00000000c71c20d3>] netlink_unicast_kernel net/netlink/af_netlink.c:1303 [inline]
>     [<00000000c71c20d3>] netlink_unicast+0x4c6/0x690 net/netlink/af_netlink.c:1329
>     [<00000000cca72fa9>] netlink_sendmsg+0x735/0xcc0 net/netlink/af_netlink.c:1918
>     [<000000009221ebf7>] sock_sendmsg_nosec net/socket.c:652 [inline]
>     [<000000009221ebf7>] sock_sendmsg+0x109/0x140 net/socket.c:672
>     [<000000001c30ffe4>] ____sys_sendmsg+0x5f5/0x780 net/socket.c:2352
>     [<00000000b71ca6f3>] ___sys_sendmsg+0x11d/0x1a0 net/socket.c:2406
>     [<0000000007297384>] __sys_sendmsg+0xeb/0x1b0 net/socket.c:2439
>     [<000000000eb29b11>] do_syscall_64+0x56/0xa0 arch/x86/entry/common.c:359
>     [<000000006839b4d0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
>
> Fixes: e51fb152318ee6 ("rtnetlink: fix a memory leak when ->newlink fails")

This bug is apparently not introduced by my commit above.

It should be commit cb626bf566eb4433318d35681286c494f0,
right? That commit introduced NETREG_UNREGISTERED on the path.

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

* Re: [PATCH v4 net] rtnetlink: Fix memory(net_device) leak when ->newlink fails
  2020-07-15  5:45 ` Cong Wang
@ 2020-07-15  7:11   ` Weilong Chen
  0 siblings, 0 replies; 3+ messages in thread
From: Weilong Chen @ 2020-07-15  7:11 UTC (permalink / raw)
  To: Cong Wang
  Cc: David Miller, Jakub Kicinski, Jiri Pirko, Eric Dumazet,
	Linux Kernel Network Developers, LKML

On 2020/7/15 13:45, Cong Wang wrote:
> On Tue, Jul 14, 2020 at 6:27 PM Weilong Chen <chenweilong@huawei.com> wrote:
>>
>> When vlan_newlink call register_vlan_dev fails, it might return error
>> with dev->reg_state = NETREG_UNREGISTERED. The rtnl_newlink should
>> free the memory. But currently rtnl_newlink only free the memory which
>> state is NETREG_UNINITIALIZED.
>>
>> BUG: memory leak
>> unreferenced object 0xffff8881051de000 (size 4096):
>>   comm "syz-executor139", pid 560, jiffies 4294745346 (age 32.445s)
>>   hex dump (first 32 bytes):
>>     76 6c 61 6e 32 00 00 00 00 00 00 00 00 00 00 00  vlan2...........
>>     00 45 28 03 81 88 ff ff 00 00 00 00 00 00 00 00  .E(.............
>>   backtrace:
>>     [<0000000047527e31>] kmalloc_node include/linux/slab.h:578 [inline]
>>     [<0000000047527e31>] kvmalloc_node+0x33/0xd0 mm/util.c:574
>>     [<000000002b59e3bc>] kvmalloc include/linux/mm.h:753 [inline]
>>     [<000000002b59e3bc>] kvzalloc include/linux/mm.h:761 [inline]
>>     [<000000002b59e3bc>] alloc_netdev_mqs+0x83/0xd90 net/core/dev.c:9929
>>     [<000000006076752a>] rtnl_create_link+0x2c0/0xa20 net/core/rtnetlink.c:3067
>>     [<00000000572b3be5>] __rtnl_newlink+0xc9c/0x1330 net/core/rtnetlink.c:3329
>>     [<00000000e84ea553>] rtnl_newlink+0x66/0x90 net/core/rtnetlink.c:3397
>>     [<0000000052c7c0a9>] rtnetlink_rcv_msg+0x540/0x990 net/core/rtnetlink.c:5460
>>     [<000000004b5cb379>] netlink_rcv_skb+0x12b/0x3a0 net/netlink/af_netlink.c:2469
>>     [<00000000c71c20d3>] netlink_unicast_kernel net/netlink/af_netlink.c:1303 [inline]
>>     [<00000000c71c20d3>] netlink_unicast+0x4c6/0x690 net/netlink/af_netlink.c:1329
>>     [<00000000cca72fa9>] netlink_sendmsg+0x735/0xcc0 net/netlink/af_netlink.c:1918
>>     [<000000009221ebf7>] sock_sendmsg_nosec net/socket.c:652 [inline]
>>     [<000000009221ebf7>] sock_sendmsg+0x109/0x140 net/socket.c:672
>>     [<000000001c30ffe4>] ____sys_sendmsg+0x5f5/0x780 net/socket.c:2352
>>     [<00000000b71ca6f3>] ___sys_sendmsg+0x11d/0x1a0 net/socket.c:2406
>>     [<0000000007297384>] __sys_sendmsg+0xeb/0x1b0 net/socket.c:2439
>>     [<000000000eb29b11>] do_syscall_64+0x56/0xa0 arch/x86/entry/common.c:359
>>     [<000000006839b4d0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
>>
>> Fixes: e51fb152318ee6 ("rtnetlink: fix a memory leak when ->newlink fails")
> 
> This bug is apparently not introduced by my commit above.
> 
> It should be commit cb626bf566eb4433318d35681286c494f0,
> right? That commit introduced NETREG_UNREGISTERED on the path.
> 
Yes, you'er right, I'll resubmit.
Thanks.
> .
> 


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

end of thread, other threads:[~2020-07-15  7:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-15  1:49 [PATCH v4 net] rtnetlink: Fix memory(net_device) leak when ->newlink fails Weilong Chen
2020-07-15  5:45 ` Cong Wang
2020-07-15  7:11   ` Weilong Chen

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.