From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mukesh Ojha Subject: Re: [PATCH v2] Input: uinput: Avoid Object-Already-Free with a global lock Date: Wed, 24 Apr 2019 17:40:40 +0530 Message-ID: <5614f04f-827d-1668-9ed0-60d93e110b8e@codeaurora.org> References: <1554883176-24318-1-git-send-email-mojha@codeaurora.org> <7299a6db-38b7-75c7-633a-00d2257eba45@codeaurora.org> <20190418014321.dptin7tpxpldhsns@penguin> <20190419071152.x5ghvbybjhv76uxt@penguin> <20190423032839.xvbldglrmjxkdntj@penguin> <17f4a0be-ab04-8537-9197-32fbca807f3f@codeaurora.org> <20190423084944.gj2boxfcg7lp4zad@penguin> <20190423110611.GL2217@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Return-path: In-Reply-To: <20190423110611.GL2217@ZenIV.linux.org.uk> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Al Viro , "dmitry.torokhov@gmail.com" Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Gaurav Kohli , Peter Hutterer , Martin Kepplinger , "Paul E. McKenney" List-Id: linux-input@vger.kernel.org On 4/23/2019 4:36 PM, Al Viro wrote: > On Tue, Apr 23, 2019 at 08:49:44AM +0000, dmitry.torokhov@gmail.com wrote: >> On Tue, Apr 23, 2019 at 12:51:13PM +0530, Mukesh Ojha wrote: >>> I have taken care this case from ioctl and release point of view. >>> >>> Even if the release gets called first it will make the >>> file->private_data=NULL. >>> and further call to ioctl will not be a problem as the check is already >>> there. >> Al, do we have any protections in VFS layer from userspace hanging onto >> a file descriptor and calling ioctl() on it even as another thread >> calls close() on the same fd? >> >> Should the issue be solved by individual drivers, or more careful >> accounting for currently running operations is needed at VFS layer? > Neither. An overlap of ->release() and ->ioctl() is possible only > if you've got memory corruption somewhere. > > close() overlapping ioctl() is certainly possible, and won't trigger > that at all - sys_ioctl() holds onto reference to struct file, so > its refcount won't reach zero until we are done with it. Al, i tried to put traceprintk inside ioctl after fdget and fdput on a simple call of open  => ioctl => close on /dev/uinput.           uinput-532   [002] ....    45.312044: SYSC_ioctl: 2     <= f_count >