Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2561559imu; Thu, 29 Nov 2018 06:56:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/XrZi3fV1DuvIZIGZafVcVRsKx3JGbjInKjRm6ra1gsaZZ9lQu/09eKrUcxbqMHvdx3hEDg X-Received: by 2002:a17:902:583:: with SMTP id f3mr1831924plf.202.1543503405228; Thu, 29 Nov 2018 06:56:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543503405; cv=none; d=google.com; s=arc-20160816; b=YySDCYEytf/sT3RqRL0y/Gw17JyP6Ead2LTtXUDmFA5xv8yyYWnqMkItNcPaYg2xU7 Lv0e1kDDtPpFxRKASSUhfYM/qaDz6dm2DRQ1z8T22LBeyYShob7jnubzEpxQjolO3+ed iwDFJdV/h50rYfcTdnq2pjaHDvA+d+A2xjcxanuSR9mEMZZQQ18H+VqtAlH7HQ7MbxG7 cFMi92E9Ty9HBc+OBiOSFfVHD1S8M0Pui4fHW4BTTEkd+h0l/BGfGH/eP80WimM2vwSR +2ciOcpy0tET60cSD2OS46sXSfU9gVJ04GHU8+zuWQr9iBDFyLSEWZdXehuGxVulpgSI SPGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9tnTamsf4vxM+gDG7DCodyM9suTn0pX39BeoSUtM0Ps=; b=XjT+S84TzxIygONs8fUjdYK+gVU1NNCKxMq1XM939M6Uno5k47azFJ5Yl2ZA6Gbx5o swNYL/w3y4fj5oq/unRfzxrHdaUqxxtP5Sm4dGgi16dQQ8ZCE9e0lC21nKn+S2pp+6lR Yk5gEdVfYlCgr/GBqfGOeGG9y7EjFOHNbmhEBE3/yjTkGEx/AeruxlC37afJ3D+eV9BP vUCjui9GD4ql7lnEZxYyOsBVSaJIDmvLDEaOq07hKqWGI+7VPPyUiwTGs+//3BeleZxz BoO0wdrqTlyVaccKNbQNFA3VeoUADnX3O6Bq7pL+RS+KShbU1RH5YFyCC6nNvGjnRq/o 6+kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KalMCxCi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u6si2520534pfb.92.2018.11.29.06.56.30; Thu, 29 Nov 2018 06:56:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KalMCxCi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731704AbeK3B1H (ORCPT + 99 others); Thu, 29 Nov 2018 20:27:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:51740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730358AbeK3B1G (ORCPT ); Thu, 29 Nov 2018 20:27:06 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B8E3620868; Thu, 29 Nov 2018 14:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501295; bh=1V0JGKy+ZoVZ9y8xmwxsTtq1g4XOYykw1Jsw89Z07nM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KalMCxCi6kWErKOqNECUg0Z29O4hpy4wLTK77Y8o+u+sBIFIN0i5vHWvW+/5CKzMO wySQb/Pvy+S3OHhz2JRGlMH9ea02mJ2NjnUNX1/VJ4QiXoELETmv5YdteGoQt6/KUD p7/UBbjNgLBvLZ3CNcBBvKD5f5XJwuGU6EDxFF1M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Omar Sandoval , Jens Axboe , Sasha Levin Subject: [PATCH 4.9 32/92] floppy: fix race condition in __floppy_read_block_0() Date: Thu, 29 Nov 2018 15:12:01 +0100 Message-Id: <20181129140109.015425101@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140106.520639693@linuxfoundation.org> References: <20181129140106.520639693@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit de7b75d82f70c5469675b99ad632983c50b6f7e7 ] LKP recently reported a hang at bootup in the floppy code: [ 245.678853] INFO: task mount:580 blocked for more than 120 seconds. [ 245.679906] Tainted: G T 4.19.0-rc6-00172-ga9f38e1 #1 [ 245.680959] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 245.682181] mount D 6372 580 1 0x00000004 [ 245.683023] Call Trace: [ 245.683425] __schedule+0x2df/0x570 [ 245.683975] schedule+0x2d/0x80 [ 245.684476] schedule_timeout+0x19d/0x330 [ 245.685090] ? wait_for_common+0xa5/0x170 [ 245.685735] wait_for_common+0xac/0x170 [ 245.686339] ? do_sched_yield+0x90/0x90 [ 245.686935] wait_for_completion+0x12/0x20 [ 245.687571] __floppy_read_block_0+0xfb/0x150 [ 245.688244] ? floppy_resume+0x40/0x40 [ 245.688844] floppy_revalidate+0x20f/0x240 [ 245.689486] check_disk_change+0x43/0x60 [ 245.690087] floppy_open+0x1ea/0x360 [ 245.690653] __blkdev_get+0xb4/0x4d0 [ 245.691212] ? blkdev_get+0x1db/0x370 [ 245.691777] blkdev_get+0x1f3/0x370 [ 245.692351] ? path_put+0x15/0x20 [ 245.692871] ? lookup_bdev+0x4b/0x90 [ 245.693539] blkdev_get_by_path+0x3d/0x80 [ 245.694165] mount_bdev+0x2a/0x190 [ 245.694695] squashfs_mount+0x10/0x20 [ 245.695271] ? squashfs_alloc_inode+0x30/0x30 [ 245.695960] mount_fs+0xf/0x90 [ 245.696451] vfs_kern_mount+0x43/0x130 [ 245.697036] do_mount+0x187/0xc40 [ 245.697563] ? memdup_user+0x28/0x50 [ 245.698124] ksys_mount+0x60/0xc0 [ 245.698639] sys_mount+0x19/0x20 [ 245.699167] do_int80_syscall_32+0x61/0x130 [ 245.699813] entry_INT80_32+0xc7/0xc7 showing that we never complete that read request. The reason is that the completion setup is racy - it initializes the completion event AFTER submitting the IO, which means that the IO could complete before/during the init. If it does, we are passing garbage to complete() and we may sleep forever waiting for the event to occur. Fixes: 7b7b68bba5ef ("floppy: bail out in open() if drive is not responding to block0 read") Reviewed-by: Omar Sandoval Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/floppy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index a321d7d849c6..326b9ba4518e 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3823,10 +3823,11 @@ static int __floppy_read_block_0(struct block_device *bdev, int drive) bio.bi_end_io = floppy_rb0_cb; bio_set_op_attrs(&bio, REQ_OP_READ, 0); + init_completion(&cbdata.complete); + submit_bio(&bio); process_fd_request(); - init_completion(&cbdata.complete); wait_for_completion(&cbdata.complete); __free_page(page); -- 2.17.1