[PATCH net] net: openvswitch: free vport unless register_netdevice() succeeds

21 views
Skip to first unread message

Stefano Brivio

unread,
Oct 21, 2019, 6:02:35 AM10/21/19
to David Miller, Hillf Danton, Taehee Yoo, Greg Rose, Eric Dumazet, Marcelo Ricardo Leitner, Ying Xue, Andrey Konovalov, Pravin B Shelar, syzkall...@googlegroups.com, syzbot, Jiri Benc, Eelco Chaudron, net...@vger.kernel.org, d...@openvswitch.org
From: Hillf Danton <hda...@sina.com>

syzbot found the following crash on:

HEAD commit: 1e78030e Merge tag 'mmc-v5.3-rc1' of git://git.kernel.org/..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=148d3d1a600000
kernel config: https://syzkaller.appspot.com/x/.config?x=30cef20daf3e9977
dashboard link: https://syzkaller.appspot.com/bug?extid=13210896153522fe1ee5
compiler: gcc (GCC) 9.0.0 20181231 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=136aa8c4600000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=109ba792600000

=====================================================================
BUG: memory leak
unreferenced object 0xffff8881207e4100 (size 128):
comm "syz-executor032", pid 7014, jiffies 4294944027 (age 13.830s)
hex dump (first 32 bytes):
00 70 16 18 81 88 ff ff 80 af 8c 22 81 88 ff ff .p........."....
00 b6 23 17 81 88 ff ff 00 00 00 00 00 00 00 00 ..#.............
backtrace:
[<000000000eb78212>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline]
[<000000000eb78212>] slab_post_alloc_hook mm/slab.h:522 [inline]
[<000000000eb78212>] slab_alloc mm/slab.c:3319 [inline]
[<000000000eb78212>] kmem_cache_alloc_trace+0x145/0x2c0 mm/slab.c:3548
[<00000000006ea6c6>] kmalloc include/linux/slab.h:552 [inline]
[<00000000006ea6c6>] kzalloc include/linux/slab.h:748 [inline]
[<00000000006ea6c6>] ovs_vport_alloc+0x37/0xf0 net/openvswitch/vport.c:130
[<00000000f9a04a7d>] internal_dev_create+0x24/0x1d0 net/openvswitch/vport-internal_dev.c:164
[<0000000056ee7c13>] ovs_vport_add+0x81/0x190 net/openvswitch/vport.c:199
[<000000005434efc7>] new_vport+0x19/0x80 net/openvswitch/datapath.c:194
[<00000000b7b253f1>] ovs_dp_cmd_new+0x22f/0x410 net/openvswitch/datapath.c:1614
[<00000000e0988518>] genl_family_rcv_msg+0x2ab/0x5b0 net/netlink/genetlink.c:629
[<00000000d0cc9347>] genl_rcv_msg+0x54/0x9c net/netlink/genetlink.c:654
[<000000006694b647>] netlink_rcv_skb+0x61/0x170 net/netlink/af_netlink.c:2477
[<0000000088381f37>] genl_rcv+0x29/0x40 net/netlink/genetlink.c:665
[<00000000dad42a47>] netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
[<00000000dad42a47>] netlink_unicast+0x1ec/0x2d0 net/netlink/af_netlink.c:1328
[<0000000067e6b079>] netlink_sendmsg+0x270/0x480 net/netlink/af_netlink.c:1917
[<00000000aab08a47>] sock_sendmsg_nosec net/socket.c:637 [inline]
[<00000000aab08a47>] sock_sendmsg+0x54/0x70 net/socket.c:657
[<000000004cb7c11d>] ___sys_sendmsg+0x393/0x3c0 net/socket.c:2311
[<00000000c4901c63>] __sys_sendmsg+0x80/0xf0 net/socket.c:2356
[<00000000c10abb2d>] __do_sys_sendmsg net/socket.c:2365 [inline]
[<00000000c10abb2d>] __se_sys_sendmsg net/socket.c:2363 [inline]
[<00000000c10abb2d>] __x64_sys_sendmsg+0x23/0x30 net/socket.c:2363

BUG: memory leak
unreferenced object 0xffff88811723b600 (size 64):
comm "syz-executor032", pid 7014, jiffies 4294944027 (age 13.830s)
hex dump (first 32 bytes):
01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 02 00 00 00 05 35 82 c1 .............5..
backtrace:
[<00000000352f46d8>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline]
[<00000000352f46d8>] slab_post_alloc_hook mm/slab.h:522 [inline]
[<00000000352f46d8>] slab_alloc mm/slab.c:3319 [inline]
[<00000000352f46d8>] __do_kmalloc mm/slab.c:3653 [inline]
[<00000000352f46d8>] __kmalloc+0x169/0x300 mm/slab.c:3664
[<000000008e48f3d1>] kmalloc include/linux/slab.h:557 [inline]
[<000000008e48f3d1>] ovs_vport_set_upcall_portids+0x54/0xd0 net/openvswitch/vport.c:343
[<00000000541e4f4a>] ovs_vport_alloc+0x7f/0xf0 net/openvswitch/vport.c:139
[<00000000f9a04a7d>] internal_dev_create+0x24/0x1d0 net/openvswitch/vport-internal_dev.c:164
[<0000000056ee7c13>] ovs_vport_add+0x81/0x190 net/openvswitch/vport.c:199
[<000000005434efc7>] new_vport+0x19/0x80 net/openvswitch/datapath.c:194
[<00000000b7b253f1>] ovs_dp_cmd_new+0x22f/0x410 net/openvswitch/datapath.c:1614
[<00000000e0988518>] genl_family_rcv_msg+0x2ab/0x5b0 net/netlink/genetlink.c:629
[<00000000d0cc9347>] genl_rcv_msg+0x54/0x9c net/netlink/genetlink.c:654
[<000000006694b647>] netlink_rcv_skb+0x61/0x170 net/netlink/af_netlink.c:2477
[<0000000088381f37>] genl_rcv+0x29/0x40 net/netlink/genetlink.c:665
[<00000000dad42a47>] netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
[<00000000dad42a47>] netlink_unicast+0x1ec/0x2d0 net/netlink/af_netlink.c:1328
[<0000000067e6b079>] netlink_sendmsg+0x270/0x480 net/netlink/af_netlink.c:1917
[<00000000aab08a47>] sock_sendmsg_nosec net/socket.c:637 [inline]
[<00000000aab08a47>] sock_sendmsg+0x54/0x70 net/socket.c:657
[<000000004cb7c11d>] ___sys_sendmsg+0x393/0x3c0 net/socket.c:2311
[<00000000c4901c63>] __sys_sendmsg+0x80/0xf0 net/socket.c:2356

BUG: memory leak
unreferenced object 0xffff8881228ca500 (size 128):
comm "syz-executor032", pid 7015, jiffies 4294944622 (age 7.880s)
hex dump (first 32 bytes):
00 f0 27 18 81 88 ff ff 80 ac 8c 22 81 88 ff ff ..'........"....
40 b7 23 17 81 88 ff ff 00 00 00 00 00 00 00 00 @.#.............
backtrace:
[<000000000eb78212>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline]
[<000000000eb78212>] slab_post_alloc_hook mm/slab.h:522 [inline]
[<000000000eb78212>] slab_alloc mm/slab.c:3319 [inline]
[<000000000eb78212>] kmem_cache_alloc_trace+0x145/0x2c0 mm/slab.c:3548
[<00000000006ea6c6>] kmalloc include/linux/slab.h:552 [inline]
[<00000000006ea6c6>] kzalloc include/linux/slab.h:748 [inline]
[<00000000006ea6c6>] ovs_vport_alloc+0x37/0xf0 net/openvswitch/vport.c:130
[<00000000f9a04a7d>] internal_dev_create+0x24/0x1d0 net/openvswitch/vport-internal_dev.c:164
[<0000000056ee7c13>] ovs_vport_add+0x81/0x190 net/openvswitch/vport.c:199
[<000000005434efc7>] new_vport+0x19/0x80 net/openvswitch/datapath.c:194
[<00000000b7b253f1>] ovs_dp_cmd_new+0x22f/0x410 net/openvswitch/datapath.c:1614
[<00000000e0988518>] genl_family_rcv_msg+0x2ab/0x5b0 net/netlink/genetlink.c:629
[<00000000d0cc9347>] genl_rcv_msg+0x54/0x9c net/netlink/genetlink.c:654
[<000000006694b647>] netlink_rcv_skb+0x61/0x170 net/netlink/af_netlink.c:2477
[<0000000088381f37>] genl_rcv+0x29/0x40 net/netlink/genetlink.c:665
[<00000000dad42a47>] netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
[<00000000dad42a47>] netlink_unicast+0x1ec/0x2d0 net/netlink/af_netlink.c:1328
[<0000000067e6b079>] netlink_sendmsg+0x270/0x480 net/netlink/af_netlink.c:1917
[<00000000aab08a47>] sock_sendmsg_nosec net/socket.c:637 [inline]
[<00000000aab08a47>] sock_sendmsg+0x54/0x70 net/socket.c:657
[<000000004cb7c11d>] ___sys_sendmsg+0x393/0x3c0 net/socket.c:2311
[<00000000c4901c63>] __sys_sendmsg+0x80/0xf0 net/socket.c:2356
[<00000000c10abb2d>] __do_sys_sendmsg net/socket.c:2365 [inline]
[<00000000c10abb2d>] __se_sys_sendmsg net/socket.c:2363 [inline]
[<00000000c10abb2d>] __x64_sys_sendmsg+0x23/0x30 net/socket.c:2363
=====================================================================

The function in net core, register_netdevice(), may fail with vport's
destruction callback either invoked or not. After commit 309b66970ee2,
the duty to destroy vport is offloaded from the driver OTOH, which ends
up in the memory leak reported.

It is fixed by releasing vport unless device is registered successfully.
To do that, the callback assignment is defered until device is registered.

Reported-by: syzbot+132108...@syzkaller.appspotmail.com
Fixes: 309b66970ee2 ("net: openvswitch: do not free vport if register_netdevice() is failed.")
Cc: Taehee Yoo <ap42...@gmail.com>
Cc: Greg Rose <gvros...@gmail.com>
Cc: Eric Dumazet <eric.d...@gmail.com>
Cc: Marcelo Ricardo Leitner <marcelo...@gmail.com>
Cc: Ying Xue <ying...@windriver.com>
Cc: Andrey Konovalov <andre...@google.com>
Signed-off-by: Hillf Danton <hda...@sina.com>
Acked-by: Pravin B Shelar <psh...@ovn.org>
[sbrivio: this was sent to d...@openvswitch.org and never made its way
to netdev -- resending original patch]
Signed-off-by: Stefano Brivio <sbr...@redhat.com>
---
This patch was sent to d...@openvswitch.org and appeared on netdev
only as Pravin replied to it, giving his Acked-by. I contacted the
original author one month ago requesting to resend this to netdev,
but didn't get an answer, so I'm now resending the original patch.

net/openvswitch/vport-internal_dev.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
index 21c90d3a7ebf..58a7b8312c28 100644
--- a/net/openvswitch/vport-internal_dev.c
+++ b/net/openvswitch/vport-internal_dev.c
@@ -137,7 +137,7 @@ static void do_setup(struct net_device *netdev)
netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE | IFF_OPENVSWITCH |
IFF_NO_QUEUE;
netdev->needs_free_netdev = true;
- netdev->priv_destructor = internal_dev_destructor;
+ netdev->priv_destructor = NULL;
netdev->ethtool_ops = &internal_dev_ethtool_ops;
netdev->rtnl_link_ops = &internal_dev_link_ops;

@@ -159,7 +159,6 @@ static struct vport *internal_dev_create(const struct vport_parms *parms)
struct internal_dev *internal_dev;
struct net_device *dev;
int err;
- bool free_vport = true;

vport = ovs_vport_alloc(0, &ovs_internal_vport_ops, parms);
if (IS_ERR(vport)) {
@@ -190,10 +189,9 @@ static struct vport *internal_dev_create(const struct vport_parms *parms)

rtnl_lock();
err = register_netdevice(vport->dev);
- if (err) {
- free_vport = false;
+ if (err)
goto error_unlock;
- }
+ vport->dev->priv_destructor = internal_dev_destructor;

dev_set_promiscuity(vport->dev, 1);
rtnl_unlock();
@@ -207,8 +205,7 @@ static struct vport *internal_dev_create(const struct vport_parms *parms)
error_free_netdev:
free_netdev(dev);
error_free_vport:
- if (free_vport)
- ovs_vport_free(vport);
+ ovs_vport_free(vport);
error:
return ERR_PTR(err);
}
--
2.20.1

Hillf Danton

unread,
Oct 21, 2019, 7:08:23 AM10/21/19
to Stefano Brivio, David S . Miller, Hillf Danton, Taehee Yoo, Greg Rose, Eric Dumazet, Marcelo Ricardo Leitner, Ying Xue, Andrey Konovalov, Pravin B Shelar, syzkall...@googlegroups.com, syzbot, Jiri Benc, Eelco Chaudron, net...@vger.kernel.org, d...@openvswitch.org

Hey Stefano

On Mon, 21 Oct 2019 18:02:48 +0800 Stefano Brivio wrote:
>
> ---
> This patch was sent to d...@openvswitch.org and appeared on netdev
> only as Pravin replied to it, giving his Acked-by. I contacted the

Correct. I am unable to find the patches I sent to lkml on
https://lore.kernel.org/lkml/.

> original author one month ago requesting to resend this to netdev,
> but didn't get an answer, so I'm now resending the original patch.
>
Nor patches to <x...@vger.kernel.org>.
Say sorry to you for missing in action.
I sent a mail to <postm...@vger.kernel.org> sometime ago asking for
how to cure the pain, without a message echoed since.
That is my poor defend.

> net/openvswitch/vport-internal_dev.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)

And feel free to pick up the diff if they make sense, as you see,
they were sent usually without the Signed-off-by tag.

Thanks
Hillf

Stefano Brivio

unread,
Oct 21, 2019, 7:41:43 AM10/21/19
to Hillf Danton, David S . Miller, Taehee Yoo, Greg Rose, Eric Dumazet, Marcelo Ricardo Leitner, Ying Xue, Andrey Konovalov, Pravin B Shelar, syzkall...@googlegroups.com, syzbot, Jiri Benc, Eelco Chaudron, net...@vger.kernel.org, d...@openvswitch.org
On Mon, 21 Oct 2019 19:08:01 +0800
Hillf Danton <hda...@sina.com> wrote:

> Hey Stefano
>
> On Mon, 21 Oct 2019 18:02:48 +0800 Stefano Brivio wrote:
> >
> > ---
> > This patch was sent to d...@openvswitch.org and appeared on netdev
> > only as Pravin replied to it, giving his Acked-by. I contacted the
>
> Correct. I am unable to find the patches I sent to lkml on
> https://lore.kernel.org/lkml/.
>
> > original author one month ago requesting to resend this to netdev,
> > but didn't get an answer, so I'm now resending the original patch.
> >
> Nor patches to <x...@vger.kernel.org>.
> Say sorry to you for missing in action.
> I sent a mail to <postm...@vger.kernel.org> sometime ago asking for
> how to cure the pain, without a message echoed since.
> That is my poor defend.

Ouch, and also this reply didn't reach netdev. Looking at headers:

Received: from r3-20.sinamail.sina.com.cn (r3-20.sinamail.sina.com.cn [202.108.3.20])
by mx1.redhat.com (Postfix) with SMTP id 9868983F45
for <sbr...@redhat.com>; Mon, 21 Oct 2019 11:08:14 +0000 (UTC)
Received: from unknown (HELO localhost.localdomain)([222.131.66.83])
by sina.com with ESMTP
id 5DAD919A000082B3; Mon, 21 Oct 2019 19:08:12 +0800 (CST)

it's not in DNSRBL or anything, and looks similar enough to e.g.:

https://patchwork.kernel.org/patch/10663003/

that was received without issues by majo...@vger.kernel.org. The only
relevant difference seems to be the missing HELO from
r3-20.sinamail.sina.com.cn, I have no idea why that would be omitted.

Headers added by MTA delivering this to me:

X-Greylist: Sender passed SPF test, ACL 264 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 21 Oct 2019 11:08:19 +0000 (UTC)
X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 21 Oct 2019 11:08:19 +0000 (UTC) for IP:'202.108.3.20' DOMAIN:'r3-20.sinamail.sina.com.cn' HELO:'r3-20.sinamail.sina.com.cn' FROM:'hda...@sina.com' RCPT:''
X-RedHat-Spam-Score: 0.001 (FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS) 202.108.3.20 r3-20.sinamail.sina.com.cn 202.108.3.20 r3-20.sinamail.sina.com.cn <hda...@sina.com>

it even passes SPF. But maybe the missing HELO is a problem for SPF on
vger.kernel.org?

Checked against http://vger.kernel.org/majordomo-taboos.txt, also no
matches.

Sorry, I don't have any suggestions other than contacting
postm...@vger.kernel.org again -- perhaps from a different address.

> > net/openvswitch/vport-internal_dev.c | 11 ++++-------
> > 1 file changed, 4 insertions(+), 7 deletions(-)
>
> And feel free to pick up the diff if they make sense, as you see,
> they were sent usually without the Signed-off-by tag.

I think this submission should be fine, I added you as From: and kept
your original Signed-off-by -- thanks for fixing this by the way!

--
Stefano

Stefano Brivio

unread,
Oct 22, 2019, 8:21:29 PM10/22/19
to Jakub Kicinski, David Miller, Hillf Danton, Taehee Yoo, Greg Rose, Eric Dumazet, Marcelo Ricardo Leitner, Ying Xue, Andrey Konovalov, Pravin B Shelar, syzkall...@googlegroups.com, syzbot, Jiri Benc, Eelco Chaudron, net...@vger.kernel.org, d...@openvswitch.org
Hi Jakub,

On Tue, 22 Oct 2019 14:53:16 -0700
Jakub Kicinski <jakub.k...@netronome.com> wrote:

> On Mon, 21 Oct 2019 12:01:57 +0200, Stefano Brivio wrote:
> > From: Hillf Danton <hda...@sina.com>
> >
> > syzbot found the following crash on:
>
> > The function in net core, register_netdevice(), may fail with vport's
> > destruction callback either invoked or not. After commit 309b66970ee2,
>
> I've added the correct commit quote here, please heed checkpatch'es
> warnings.

I disregarded this warning as it looks redundant to me, given that the
full commit quote is already given in the Fixes: tag below.

In this specific case, I guess it doesn't really make a difference, but
sometimes one needs to mention the same commit multiple times in the
actual message, and while checkpatch would complain about every single
instance, I think that providing the full quote for each of them isn't
very useful and hinders readability.

> > Reported-by: syzbot+132108...@syzkaller.appspotmail.com
> > Fixes: 309b66970ee2 ("net: openvswitch: do not free vport if register_netdevice() is failed.")
> > Cc: Taehee Yoo <ap42...@gmail.com>
> > Cc: Greg Rose <gvros...@gmail.com>
> > Cc: Eric Dumazet <eric.d...@gmail.com>
> > Cc: Marcelo Ricardo Leitner <marcelo...@gmail.com>
> > Cc: Ying Xue <ying...@windriver.com>
> > Cc: Andrey Konovalov <andre...@google.com>
> > Signed-off-by: Hillf Danton <hda...@sina.com>
> > Acked-by: Pravin B Shelar <psh...@ovn.org>
> > [sbrivio: this was sent to d...@openvswitch.org and never made its way
> > to netdev -- resending original patch]
> > Signed-off-by: Stefano Brivio <sbr...@redhat.com>
> > ---
> > This patch was sent to d...@openvswitch.org and appeared on netdev
> > only as Pravin replied to it, giving his Acked-by. I contacted the
> > original author one month ago requesting to resend this to netdev,
> > but didn't get an answer, so I'm now resending the original patch.
>
> Applied and queued for 4.14+, thanks!

Thank you!

--
Stefano

Gregory Rose

unread,
Oct 24, 2019, 4:35:46 AM10/24/19
to Stefano Brivio, David Miller, Hillf Danton, Taehee Yoo, Eric Dumazet, Marcelo Ricardo Leitner, Ying Xue, Andrey Konovalov, Pravin B Shelar, syzkall...@googlegroups.com, syzbot, Jiri Benc, Eelco Chaudron, net...@vger.kernel.org, d...@openvswitch.org
Thanks Stefano and Hillf.  LGTM

Reviewed-by: Greg Rose <gvros...@gmail.com>

Jakub Kicinski

unread,
Oct 24, 2019, 4:35:46 AM10/24/19
to Stefano Brivio, David Miller, Hillf Danton, Taehee Yoo, Greg Rose, Eric Dumazet, Marcelo Ricardo Leitner, Ying Xue, Andrey Konovalov, Pravin B Shelar, syzkall...@googlegroups.com, syzbot, Jiri Benc, Eelco Chaudron, net...@vger.kernel.org, d...@openvswitch.org
On Mon, 21 Oct 2019 12:01:57 +0200, Stefano Brivio wrote:
> From: Hillf Danton <hda...@sina.com>
>
> syzbot found the following crash on:

> The function in net core, register_netdevice(), may fail with vport's
> destruction callback either invoked or not. After commit 309b66970ee2,

I've added the correct commit quote here, please heed checkpatch'es
warnings.

> the duty to destroy vport is offloaded from the driver OTOH, which ends
> up in the memory leak reported.
>
> It is fixed by releasing vport unless device is registered successfully.
> To do that, the callback assignment is defered until device is registered.
>
> Reported-by: syzbot+132108...@syzkaller.appspotmail.com
> Fixes: 309b66970ee2 ("net: openvswitch: do not free vport if register_netdevice() is failed.")
> Cc: Taehee Yoo <ap42...@gmail.com>
> Cc: Greg Rose <gvros...@gmail.com>
> Cc: Eric Dumazet <eric.d...@gmail.com>
> Cc: Marcelo Ricardo Leitner <marcelo...@gmail.com>
> Cc: Ying Xue <ying...@windriver.com>
> Cc: Andrey Konovalov <andre...@google.com>
> Signed-off-by: Hillf Danton <hda...@sina.com>
> Acked-by: Pravin B Shelar <psh...@ovn.org>
> [sbrivio: this was sent to d...@openvswitch.org and never made its way
> to netdev -- resending original patch]
> Signed-off-by: Stefano Brivio <sbr...@redhat.com>
> ---
> This patch was sent to d...@openvswitch.org and appeared on netdev
> only as Pravin replied to it, giving his Acked-by. I contacted the
> original author one month ago requesting to resend this to netdev,
> but didn't get an answer, so I'm now resending the original patch.

Reply all
Reply to author
Forward
0 new messages