Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5972018ybh; Wed, 7 Aug 2019 14:49:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzx8kI9OI9/5c0Sv7PZTkMjLNro+AM6pURcILl1+gBxN4HdbBcFW1ErCK9T8oPwaC3q5WG9 X-Received: by 2002:a17:90a:214e:: with SMTP id a72mr598747pje.0.1565214544713; Wed, 07 Aug 2019 14:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565214544; cv=none; d=google.com; s=arc-20160816; b=Es6vEohd2Jln7a3DEvqZYzeZJvoNvcJ5HeqXwyN4LoUC91TkdEQmRpW4G5Lwk2q1sj GjFafCBY9rKujClxtSj91tlQjo+ga3M9eCD/KXl9fjxfNZDh2kEfNbfgziKYUWD+yx7W r+LpELdhi31k6O7djIrCkEogLeX1Vs2JiTuz1ZTPkSnGak15+yU8jojVOe0prX6luIHq WZQzuOdmzGrMv2Jwj2y5EQXSO+0f0QvI5GTyxA7rAGCP+0fyiPTKZcj9mfFYnxMDdvys JC1yx+PTgL8pZsl+M4xiDiEikE/gg5ecUeyuB+0+X+MCoxSRaJQosYXwxlIL5H/YbL02 S4+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=Fo2K992owVwofdisK+b+UsT9DsYGg6LW0lrcslyjMZk=; b=P66XfuKXT7RpJq64RddGHUNNBRMEG5WEZQSgYjOOpY3G8BS3VCltBnzR5VW/DvcrcA w0oSbiDjIiorJUil0FvHZ5A34y8KDPNU/2P1QccKK5Z7UttUSJbAektvnmFdKZ6kxM8K HB0hA8iKI55vv7UqxCizAD5idfqbcRV6D/VMsw1ngwHlP5zsP9+fVXlxG6xc8Nu7iHTP /epbG2rBRjXskW+4wJEQ62V2No4BJ3wb7hXsQ32J9RwugnBPAlR3cjccbomKeFb4GVyM tyOoFovOkxBTl+7OnuDBRb6hgq9auXtMOSBO4Y/KVU3+s70rvb806TPHJBZCslhJerEP ozKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l62si48521670pgd.24.2019.08.07.14.48.48; Wed, 07 Aug 2019 14:49:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389403AbfHGUbe (ORCPT + 99 others); Wed, 7 Aug 2019 16:31:34 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:37119 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389079AbfHGUbd (ORCPT ); Wed, 7 Aug 2019 16:31:33 -0400 X-Originating-IP: 209.85.221.174 Received: from mail-vk1-f174.google.com (mail-vk1-f174.google.com [209.85.221.174]) (Authenticated sender: pshelar@ovn.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id EE93D240002; Wed, 7 Aug 2019 20:31:30 +0000 (UTC) Received: by mail-vk1-f174.google.com with SMTP id m17so18329110vkl.2; Wed, 07 Aug 2019 13:31:30 -0700 (PDT) X-Gm-Message-State: APjAAAVcbxDHPtqhuDkWbLqHoK3XDZu04v1gyrYrlluhTdtNG3BHxSTq bj0SpekyJqwIQsqViBmgJ3wq/PU92/YGoLSyMfU= X-Received: by 2002:a1f:1b0a:: with SMTP id b10mr4289060vkb.19.1565209889563; Wed, 07 Aug 2019 13:31:29 -0700 (PDT) MIME-Version: 1.0 References: <20190806115932.3044-1-hdanton@sina.com> In-Reply-To: <20190806115932.3044-1-hdanton@sina.com> From: Pravin Shelar Date: Wed, 7 Aug 2019 13:32:40 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: memory leak in internal_dev_create To: Hillf Danton Cc: syzbot , "David S. Miller" , ovs dev , linux-kernel@vger.kernel.org, Linux Kernel Network Developers , syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 6, 2019 at 5:00 AM Hillf Danton wrote: > > > On Tue, 06 Aug 2019 01:58:05 -0700 > > Hello, > > > > syzbot found the following crash on: > > ... > > 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 > > > Always free vport manually unless register_netdevice() succeeds. > > --- 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->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 > 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 > > rtnl_lock(); > err = register_netdevice(vport->dev); > - if (err) { > - free_vport = false; > + if (err) > goto error_unlock; > - } > + vport->dev->priv_destructor = internal_dev_destructor; > I am not sure why have you moved this assignment out of do_setup(). Otherwise patch looks good to me. Thanks. > dev_set_promiscuity(vport->dev, 1); > rtnl_unlock(); > @@ -207,8 +205,7 @@ error_unlock: > 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); > } > -- >