From: Matthew Wilcox Subject: Re: race with i_flock? Date: Wed, 17 Jul 2002 12:55:33 +0100 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20020717125533.Z27706@parcelfarce.linux.theplanet.co.uk> References: <3D34D5F4.2060008@us.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Matthew Wilcox , linux-fsdevel@vger.kernel.org, Stephen Rothwell Return-path: To: Dave Hansen Content-Disposition: inline In-Reply-To: <3D34D5F4.2060008@us.ibm.com>; from haveblue@us.ibm.com on Tue, Jul 16, 2002 at 07:27:00PM -0700 List-Id: linux-fsdevel.vger.kernel.org On Tue, Jul 16, 2002 at 07:27:00PM -0700, Dave Hansen wrote: > which is: > static inline int get_lease(struct inode *inode, unsigned int mode) > { > ------->if (inode->i_flock && (inode->i_flock->fl_flags & FL_LEASE)) > return __get_lease(inode, mode); > return 0; > } > > It appears that i_flock is NULL: Doh! That's entirely possible. open() could race with posix_lock_file and remove the first element of the i_flock list between the two tests. So... let's change get_lease() to be: static inline int get_lease(struct inode *inode, unsigned int mode) { if (inode->i_flock) return __get_lease(inode, mode); return 0; } __get_lease in 2.5.x has sufficient checks in it already; 2.4 does not and needs something like this: lock_kernel(); flock = inode->i_flock; + if (!flock || (flock->fl_flags & FL_LEASE) == 0) + goto out; if (flock->fl_type & F_INPROGRESS) { if ((mode & O_NONBLOCK) This must be a 1-insn wide race. I'm very impressed you managed to hit it ;-) -- Revolutions do not require corporate support.