From: Arnd Bergmann Subject: Re: [RFC PATCH] fs code: Push the BKL down into the file system ioctl handlers Date: Wed, 4 Jun 2008 18:43:20 +0200 Message-ID: <200806041843.20965.arnd@arndb.de> References: <20080522231524.52e21eb8@core> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jens Axboe To: Alan Cox Return-path: In-Reply-To: <20080522231524.52e21eb8@core> Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Friday 23 May 2008, Alan Cox wrote: > --- a/drivers/char/raw.c > +++ b/drivers/char/raw.c > @@ -116,13 +116,15 @@ static int raw_release(struct inode *inode, str= uct file *filp) > =A0/* > =A0 * Forward ioctls to the underlying block device. > =A0 */ > -static int > -raw_ioctl(struct inode *inode, struct file *filp, > -=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0unsigned int comman= d, unsigned long arg) > +static long raw_ioctl(struct file *filp, unsigned int command, > +=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= unsigned long arg) > =A0{ > +=A0=A0=A0=A0=A0=A0=A0long ret; > =A0=A0=A0=A0=A0=A0=A0=A0struct block_device *bdev =3D filp->private_d= ata; > - > -=A0=A0=A0=A0=A0=A0=A0return blkdev_ioctl(bdev->bd_inode, NULL, comma= nd, arg); > +=A0=A0=A0=A0=A0=A0=A0lock_kernel(); > +=A0=A0=A0=A0=A0=A0=A0ret =3D blkdev_ioctl(bdev->bd_inode, NULL, comm= and, arg); > +=A0=A0=A0=A0=A0=A0=A0unlock_kernel(); > +=A0=A0=A0=A0=A0=A0=A0return ret; > =A0} > =A0 > =A0static void bind_device(struct raw_config_request *rq) blkdev_ioctl and compat_blkdev_ioctl are converted already (they take the BKL in all places of doubt), so you can call these directly without calling lock_kernel() again. However, reading through that code again, I noticed two nastybits: * there is no compat_raw_ioctl function, so any user space program trying 32 bit block ioctl calls on a raw device has been broken ever since my patch that moved the block compat_ioctl handlers into the block/compat_ioctl.c file. The same problem seems to exist on pktcdvd.c. * If any block driver had implemented unlocked_ioctl, it would be even worse: The raw driver passes filp->private_data->bd_inode as the inode and NULL as the file. blkdev_ioctl drops the inode argument when calling into a driver and only passes filp, so=20 if a driver then tries to access filp->f_mapping->host, it gets a NULL pointer dereference. =46ortunately, no block driver to date implements unlocked_ioctl, and compat_ioctl was protected from this bug by the missing compat_raw_ioctl. I suppose the right fix for this will be to make the blkdev unlocked_ioctl and compat_ioctl take a bdev argument instead of file and inode. Arnd <><