From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Gunthorpe Subject: Re: [PATCH] tpm: don't destroy chip device prematurely Date: Wed, 5 Oct 2016 10:27:41 -0600 Message-ID: <20161005162741.GA18636@obsidianresearch.com> References: <1475393971-12715-1-git-send-email-tomas.winkler@intel.com> <20161002101755.GA25844@intel.com> <20161002102455.GA27464@intel.com> <20161002212126.GA25872@obsidianresearch.com> <5B8DA87D05A7694D9FA63FD143655C1B542F466B@hasmsx108.ger.corp.intel.com> <20161003124836.GE9990@intel.com> <20161004051946.GA10572@intel.com> <20161004164738.GA17149@obsidianresearch.com> <20161005100234.GA20851@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20161005100234.GA20851-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org To: Jarkko Sakkinen Cc: "tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org" , "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" List-Id: tpmdd-devel@lists.sourceforge.net On Wed, Oct 05, 2016 at 01:02:34PM +0300, Jarkko Sakkinen wrote: > I'll repeat my question: what worse can happen than returning -EPIPE? I > though the whole rw lock scheme was introduced just for this purpose. I thought I explained this, if device_del is moved after ops = null then if sysfs looses the race it will oops the kernel. device_del hard fences sysfs. > Why there's even that branch in tpm-dev.c if it's so bad to let it > happen? Because cdev_del and device_del do not guarentee that the cdev is fenced. They just prevent new calls into open(). So the branch in tpm-dev.c is necessary to avoid a kernel oops if user space holds the fd open across unregister. It is the same sitatuion you identified in the securityfs discussion - user space holding the fd open across a driver unregister. Jason ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752537AbcJEQ2A (ORCPT ); Wed, 5 Oct 2016 12:28:00 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:59209 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751404AbcJEQ17 (ORCPT ); Wed, 5 Oct 2016 12:27:59 -0400 Date: Wed, 5 Oct 2016 10:27:41 -0600 From: Jason Gunthorpe To: Jarkko Sakkinen Cc: "Winkler, Tomas" , "tpmdd-devel@lists.sourceforge.net" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] tpm: don't destroy chip device prematurely Message-ID: <20161005162741.GA18636@obsidianresearch.com> References: <1475393971-12715-1-git-send-email-tomas.winkler@intel.com> <20161002101755.GA25844@intel.com> <20161002102455.GA27464@intel.com> <20161002212126.GA25872@obsidianresearch.com> <5B8DA87D05A7694D9FA63FD143655C1B542F466B@hasmsx108.ger.corp.intel.com> <20161003124836.GE9990@intel.com> <20161004051946.GA10572@intel.com> <20161004164738.GA17149@obsidianresearch.com> <20161005100234.GA20851@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161005100234.GA20851@intel.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.151 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 05, 2016 at 01:02:34PM +0300, Jarkko Sakkinen wrote: > I'll repeat my question: what worse can happen than returning -EPIPE? I > though the whole rw lock scheme was introduced just for this purpose. I thought I explained this, if device_del is moved after ops = null then if sysfs looses the race it will oops the kernel. device_del hard fences sysfs. > Why there's even that branch in tpm-dev.c if it's so bad to let it > happen? Because cdev_del and device_del do not guarentee that the cdev is fenced. They just prevent new calls into open(). So the branch in tpm-dev.c is necessary to avoid a kernel oops if user space holds the fd open across unregister. It is the same sitatuion you identified in the securityfs discussion - user space holding the fd open across a driver unregister. Jason