From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752570AbbCXM7v (ORCPT ); Tue, 24 Mar 2015 08:59:51 -0400 Received: from mx0b-000f0801.pphosted.com ([67.231.152.113]:44367 "EHLO mx0b-000f0801.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752491AbbCXM7s (ORCPT ); Tue, 24 Mar 2015 08:59:48 -0400 Message-ID: <55115FAA.50800@brocade.com> Date: Tue, 24 Mar 2015 12:59:22 +0000 From: Brian Russell User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.5.0 MIME-Version: 1.0 To: Greg Kroah-Hartman , Brian Russell CC: "Hans J. Koch" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v9 2/2] uio: Fix uio driver to refcount device References: <550C34B4.6030703@brocade.com> <20150323204145.GA22203@kroah.com> In-Reply-To: <20150323204145.GA22203@kroah.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.13.68,1.0.33,0.0.0000 definitions=2015-03-24_04:2015-03-24,2015-03-24,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=2 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1503240133 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/03/15 20:41, Greg Kroah-Hartman wrote: > On Fri, Mar 20, 2015 at 02:54:44PM +0000, Brian Russell wrote: >> Protect uio driver from its owner being unplugged while there are open fds. >> Embed struct device in struct uio_device, use refcounting on device, free >> uio_device on release. >> info struct passed in uio_register_device can be freed on unregister, so null >> out the field in uio_unregister_device and check accesses. > > That's really not protecting anything except heavy-handed problems... > > Look at the code: > >> @@ -493,7 +499,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait) >> struct uio_listener *listener = filep->private_data; >> struct uio_device *idev = listener->dev; >> >> - if (!idev->info->irq) >> + if (!idev->info || !idev->info->irq) >> return -EIO; >> > > Great, you checked the irq value, but what if it changes the very next > line: > >> poll_wait(filep, &idev->wait, wait); > > Or any other line within this function? Or any other function that you > try to check the value for in the beginning... > > This really isn't protecting anything "properly", sorry. Either we > don't care about it (hint, I don't think we really do), or we need to > properly lock things and check, and protect, things that way. > The checks for irq value are already there. I added the checks for the idev->info ptr and deliberately nulled it in uio_unregister_device as the caller module may free uio_info after unregistering (dpdk's igb_uio does anyway) and then release will be called later when fds are closed. So I think I definitely need the check in uio_release. I didn't think it hurt to return early from poll/read/write if we know the device has been unregistered? Thanks, Brian > Please do the first one, as the reference count should be all that we > need to care about here. > > Sorry I missed this on the previous review, just realized it now this > time around. > > thanks, > > greg k-h >