From owner-svn-src-head@freebsd.org Wed Aug 10 09:15:25 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A590FBB20A6; Wed, 10 Aug 2016 09:15:25 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (heidi.turbocat.net [88.198.202.214]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6FC351778; Wed, 10 Aug 2016 09:15:24 +0000 (UTC) (envelope-from hps@selasky.org) Received: from laptop015.home.selasky.org (unknown [62.141.129.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id F29F21FE024; Wed, 10 Aug 2016 11:15:21 +0200 (CEST) Subject: Re: svn commit: r303870 - head/sys/dev/mlx5/mlx5_en To: John Baldwin References: <201608090743.u797hF8l000216@repo.freebsd.org> <1815980.zoyFBGqzV5@ralph.baldwin.cx> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org From: Hans Petter Selasky Message-ID: <4c9444ab-2278-1ae2-d15b-bd9dd8bfe27d@selasky.org> Date: Wed, 10 Aug 2016 11:19:46 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <1815980.zoyFBGqzV5@ralph.baldwin.cx> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2016 09:15:25 -0000 On 08/09/16 19:25, John Baldwin wrote: > On Tuesday, August 09, 2016 07:43:15 AM Hans Petter Selasky wrote: >> Author: hselasky >> Date: Tue Aug 9 07:43:15 2016 >> New Revision: 303870 >> URL: https://svnweb.freebsd.org/changeset/base/303870 >> >> Log: >> Fix for use after free. >> >> Clear the device description to avoid use after free because the >> bsddev is not destroyed when the mlx5en module is unloaded. Only when >> the parent mlx5 module is unloaded the bsddev is destroyed. This fixes >> a panic on listing sysctls which refer strings in the bsddev after the >> mlx5en module has been unloaded. >> >> Sponsored by: Mellanox Technologies >> MFC after: 1 week > > Hmmm, this seems like it is working around a bug somewhere else. > device_detach() calls device_set_driver(dev, NULL) which in turn calls > device_set_desc(dev, NULL) which should be clearing the description. You can > only be leaking a desc pointer if you aren't detaching the device. Not > detaching a device but unloading the module containing part (but apparently > not all) of its driver would seem to be fraught with peril. Why are you not > detaching the mlx5en0 device when unloading this module? > Hi John, It is not a bug in the kernel. When mlx5en is unloaded, device_detach() is not called, and that is expected. The mlx5 and mlx4 family of drivers have their own one-level bus subsystem. mlx5.ko will call LINUXKPI's pci_register_driver() and then probe mlx5en internally. When mlx5en is detached, mlx5 will detach the mlx5en driver, but it will not call "pci_unregister_driver()" which calls the device_detach(). This will only happen when the mlx5.ko is unloaded. Because the mlx5, mlx5en and mlx5ib (coming) modules are separated we can end up in this situation. I hope you understand and that my explanation was not too complicated. For other in-kernel drivers, this is not a problem. Like you write device_detach() will take care of device_set_driver(dev, NULL) and that will clear the device description. --HPS