From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.linuxfoundation.org ([140.211.169.12]:41118 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756215AbeARNzM (ORCPT ); Thu, 18 Jan 2018 08:55:12 -0500 Date: Thu, 18 Jan 2018 14:55:09 +0100 From: Greg KH To: Bradley Bolen Cc: stable@vger.kernel.org Subject: Re: [PATCH] UBI: block: Fix locking for idr_alloc/idr_remove Message-ID: <20180118135509.GA24935@kroah.com> References: <1516283261-10968-1-git-send-email-bbolen@lexmark.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1516283261-10968-1-git-send-email-bbolen@lexmark.com> Sender: stable-owner@vger.kernel.org List-ID: On Thu, Jan 18, 2018 at 08:47:41AM -0500, Bradley Bolen wrote: > From: Bradley Bolen > > This fixes a race with idr_alloc where gd->first_minor can be set to the > same value for two simultaneous calls to ubiblock_create. Each instance > calls device_add_disk with the same first_minor. device_add_disk calls > bdi_register_owner which generates several warnings. > > WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31 > sysfs_warn_dup+0x68/0x88 > sysfs: cannot create duplicate filename '/devices/virtual/bdi/252:2' > > WARNING: CPU: 1 PID: 179 at kernel-source/lib/kobject.c:240 > kobject_add_internal+0x1ec/0x2f8 > kobject_add_internal failed for 252:2 with -EEXIST, don't try to > register things with the same name in the same directory > > WARNING: CPU: 1 PID: 179 at kernel-source/fs/sysfs/dir.c:31 > sysfs_warn_dup+0x68/0x88 > sysfs: cannot create duplicate filename '/dev/block/252:2' > > However, device_add_disk does not error out when bdi_register_owner > returns an error. Control continues until reaching blk_register_queue. > It then BUGs. > > kernel BUG at kernel-source/fs/sysfs/group.c:113! > [] (internal_create_group) from [] > (sysfs_create_group+0x20/0x24) > [] (sysfs_create_group) from [] > (blk_trace_init_sysfs+0x18/0x20) > [] (blk_trace_init_sysfs) from [] > (blk_register_queue+0xd8/0x154) > [] (blk_register_queue) from [] > (device_add_disk+0x194/0x44c) > [] (device_add_disk) from [] > (ubiblock_create+0x284/0x2e0) > [] (ubiblock_create) from [] > (vol_cdev_ioctl+0x450/0x554) > [] (vol_cdev_ioctl) from [] (vfs_ioctl+0x30/0x44) > [] (vfs_ioctl) from [] (do_vfs_ioctl+0xa0/0x790) > [] (do_vfs_ioctl) from [] (SyS_ioctl+0x44/0x68) > [] (SyS_ioctl) from [] (ret_fast_syscall+0x0/0x34) > > Locking idr_alloc/idr_remove removes the race and keeps gd->first_minor > unique. > > Fixes: 2bf50d42f3a4 ("UBI: block: Dynamically allocate minor numbers") > Cc: stable@vger.kernel.org > Signed-off-by: Bradley Bolen > --- > drivers/mtd/ubi/block.c | 42 ++++++++++++++++++++++++++---------------- > 1 file changed, 26 insertions(+), 16 deletions(-) This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read: https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html for how to do this properly. It's also not how you submit patches upstream, you have read Documentation/SubmittingPatches, right? thanks, greg k-h