Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp7518894ybh; Thu, 8 Aug 2019 17:47:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqycmoPQ3DIPoDqYaRiaBE+6gO3p7B5HLcrwMi2l7XYwostaz+qKWEtRqXaOz0l9Gd2om66T X-Received: by 2002:a17:90a:2343:: with SMTP id f61mr6852640pje.130.1565311677929; Thu, 08 Aug 2019 17:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565311677; cv=none; d=google.com; s=arc-20160816; b=hulDy8p9YwKr0ZtdJIeL3GThqNScuXBVTWLwbt3CL6cqHAa6oF2MfftNh+uz86j8Re yVjZ2X0kE5gviHB0WWBHeDPctvtgV68JDF9DsBCVuvVDuaLJWznXeLS6rD2LObb3f1j1 ko8RLX7s39pCvugIRTMAuuKvHx0WlpstQ8kKPyeJi+YZO6mErTqMMRF1gu6sX837I7Rq xxN4qDr+SHAbQhD2vkyxIMFYyfuGI1KK6tKR2OhU4Un9Xq6pB/Er8aDuZV/Zps4pXw1l ACNwZuYnnuP6HqIluNNcdwm/LpmTLlfKuhw3enYflj1dwujKqlsktVoLCRk37eP0obSg XmTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YbIEMZbtzCXpq/MNUh4eWzpCyaArIiGShovNn2U+vxo=; b=dJaOzOYzQO821jQ+QVxoPI52I+g4wfExqEQSim8CepsYeFiWQ+g2gZ8by0Gpx6IDvi v7r/xj8xRmvlY162KRD/EubudF7WjOMNLmFx5tEcRuFGMa1sc8/jUqL4dujWzLEodNpU GRlyEZnw2RF3Bsa8PKCMLko2tWjPYiQOIJ28MeZ5UVVPfm8jq3F3dzRDZ7Dvb65BYnIs SPqjTPQDotkr85TlBK3cTGbhyBWriEbq87nhVq3/pbW3AyE1L+smQuNwlv9YVyHXd4Xi wVN7CyxlWg9xj0G+DeVO2PairAeMJWzpb6w4sOZI+NmJb0wKUeSQok2tEk6ue56E0uTz kdaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TWTRQBLM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h18si3164038pjt.9.2019.08.08.17.47.42; Thu, 08 Aug 2019 17:47:57 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TWTRQBLM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405031AbfHIApX (ORCPT + 99 others); Thu, 8 Aug 2019 20:45:23 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:39996 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729419AbfHIApX (ORCPT ); Thu, 8 Aug 2019 20:45:23 -0400 Received: by mail-qt1-f194.google.com with SMTP id a15so94176221qtn.7; Thu, 08 Aug 2019 17:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YbIEMZbtzCXpq/MNUh4eWzpCyaArIiGShovNn2U+vxo=; b=TWTRQBLMTs6ciccZhps1ttQ4fZK9Xg7OiSrrrWfMirmK8xJ1bxCJPHElOVKTZbV9RG tBqrG87zGb1uf/pCL70VCfLQUaV9UwEDQzySbKg44Z7P3vA/7dQxpQ10LZ/q4sWzxlwi pZxeveZiN9a81X1gWRWphTmCjhVyP6ng0hbBx/JxMfw2wKacH6NVuG4BuGsHNmtOfliw yVaAgLeRYgonkZA4hfrwFGL+jVXjGWXhJpBIaJTsu2lzloJmYm4GB0bkxJ+fWK28VZ50 pTGVkcKndbe6jXzjGwipjRuXIb862pi2AMKyNrwoQbBDuP4lww3krG4YPtjwkj1RkPV5 woDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YbIEMZbtzCXpq/MNUh4eWzpCyaArIiGShovNn2U+vxo=; b=aQZAeiXij5WITWInYo064129NMTHLkJjvjVjkVd6DdZKgK/3EYxNO8Y0sDEzWdgP+Y ITW3kkdttwVicIjzUl2trJc7ASGbK0nUmyc/acFfPV3q3ZdWOkdYSCabm0Ad5c1Jz4HZ quyvsAqP1TNvpHkq1JcSG6J/1yak3lMW3V24nfBM2Vzf7u3moq4HmQ1FvKY3O3c980Ze iFkXeNvfHr/OEvewERL9CAYmn2+ZS1nnGkec7fwXeH4WEJtF41XWdC9wpwJy+3SU+IOd BJO6Pha+8pKC2yD9yR7aWdiI5JLIzLfF7Jl1zOYijDMTyoPiDLVgRbPTpXJ/US4w8OE+ Vndw== X-Gm-Message-State: APjAAAWFToEWfnbvgUSMk14m/CVtGeIBlVv9yvOpjHockrfcas+KyGeG 7F0G7DdexIYy6l1IKQa4KTQ= X-Received: by 2002:a0c:e1cd:: with SMTP id v13mr15727930qvl.245.1565311521542; Thu, 08 Aug 2019 17:45:21 -0700 (PDT) Received: from localhost.localdomain ([177.220.172.117]) by smtp.gmail.com with ESMTPSA id w62sm38405674qkd.30.2019.08.08.17.45.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 17:45:20 -0700 (PDT) Received: by localhost.localdomain (Postfix, from userid 1000) id DF7E2C0ABC; Thu, 8 Aug 2019 21:45:17 -0300 (-03) Date: Thu, 8 Aug 2019 21:45:17 -0300 From: Marcelo Ricardo Leitner To: Pravin Shelar Cc: Hillf Danton , syzbot , "David S. Miller" , ovs dev , linux-kernel@vger.kernel.org, Linux Kernel Network Developers , syzkaller-bugs@googlegroups.com Subject: Re: memory leak in internal_dev_create Message-ID: <20190809004517.GD4063@localhost.localdomain> References: <20190806115932.3044-1-hdanton@sina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 07, 2019 at 01:32:40PM -0700, Pravin Shelar wrote: > 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. Seems it's to avoid re-introducing the issue that was fixed by: commit 309b66970ee2abf721ecd0876a48940fa0b99a35 Author: Taehee Yoo Date: Sun Jun 9 23:26:21 2019 +0900 net: openvswitch: do not free vport if register_netdevice() is failed. A Fixes: 309b66970ee2a is welcomed then. > > 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); > > } > > -- > > >