Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2081566iob; Fri, 29 Apr 2022 21:58:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO3ArcfZOqEnE4m3iDQSJ7wjx2C+wqQNzFF4qCxniu//UGthlPwCSQXWd5eNWejndzB0f+ X-Received: by 2002:a17:902:e84b:b0:15d:5c31:8f8e with SMTP id t11-20020a170902e84b00b0015d5c318f8emr2322255plg.118.1651294689479; Fri, 29 Apr 2022 21:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651294689; cv=none; d=google.com; s=arc-20160816; b=EIfcNsoJybWsDh8DX0jlJFbR1QT8c9q9gp7Vzrbqz0YkljcTZKJsl6mnyY00COCt5A 5HI3TqL5CpH4wI3TdcYeeWx2GlvBCGKQZAfaXaVefshGSGzsoC4IMXCw4aDBSpP+UYer HkuNK0HsZ33HrUhlPuQCdy4YMI3urU6J9emOPuAanFKBLBG97QU7uDjkEQ+SKyOpGkpI IBeUkZrKlS2MjzY8Pia90uQG117ezgeyPhQqeeG9saF7M3STue0fHiwGzuBbyX0kTxEA JPmoACxEGckOXueAUXMg16YtoJP3DV0oWUAaqiU6ZI+bqvvjLtJ+PseRYX+9o5PrecR/ zzSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RaXYgCC2/JiCAaBOabgrM6WbZwv6XWAAG5nsQXVbjhM=; b=zqzgH9PqpmHpFODtnJAq3JMtVDbpIwT478/q7TI51/4sGl9Z0ckYwmeSwl0VJpsw8r YAoBFudLBBeLOz31X8AZOcxwE3TV+9itS6LfAo2mJ58HLmk6kdo53pWIADhgUu3nSMvA rQRAaTRx/ji3HBN5lTvSmaQlWm9CkBbAisvBapp1VkTQ0n7A6n3czK7rTw0MtYtoUblk thbRWWrByRpxn/1WWvkrDXqI/f2htFK2aCbmZoswwXWeHQJGhcZwAHyh/8UwovEbQCYF mHlNmi3tuJ0NjKecyOTbcfq20MMMtSNPACZOYmXmhFE7sMC52kTbQMvPkrdphlxwxU9L /QuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eCeF7Mgo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y192-20020a638ac9000000b003c165f258e9si6921810pgd.665.2022.04.29.21.57.33; Fri, 29 Apr 2022 21:58:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eCeF7Mgo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358044AbiD2Kt4 (ORCPT + 99 others); Fri, 29 Apr 2022 06:49:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358151AbiD2Ksz (ORCPT ); Fri, 29 Apr 2022 06:48:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CA32C8AB8; Fri, 29 Apr 2022 03:44:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CC64860C8E; Fri, 29 Apr 2022 10:44:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B57B8C385A4; Fri, 29 Apr 2022 10:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651229041; bh=SBKgIQI4y/NoN/43vWhJ0+9yEVbhLu4Z6iGuH4BhSzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eCeF7MgoX800KD6bWHEp4eSBoOHGo3umIUYYNIhdeQIOyiHF9ZLXHWKNfgSzVxDw4 XHOWGJIAZX45jOUKwc4m3n8uuMRaenG5XsrEem6p9hO8DVb/5zMcB0TPXamR/ZjBn2 2j9LF5h0rDENRD6ejozBl7+WuTfD64PnYP2ZYr78= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minh Yuan , syzbot+8e8958586909d62b6840@syzkaller.appspotmail.com, cruise k , Kyungtae Kim , Linus Torvalds , Denis Efremov , Willy Tarreau , Linus Torvalds Subject: [PATCH 5.15 01/33] floppy: disable FDRAWCMD by default Date: Fri, 29 Apr 2022 12:41:48 +0200 Message-Id: <20220429104052.388485935@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220429104052.345760505@linuxfoundation.org> References: <20220429104052.345760505@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Willy Tarreau commit 233087ca063686964a53c829d547c7571e3f67bf upstream. Minh Yuan reported a concurrency use-after-free issue in the floppy code between raw_cmd_ioctl and seek_interrupt. [ It turns out this has been around, and that others have reported the KASAN splats over the years, but Minh Yuan had a reproducer for it and so gets primary credit for reporting it for this fix - Linus ] The problem is, this driver tends to break very easily and nowadays, nobody is expected to use FDRAWCMD anyway since it was used to manipulate non-standard formats. The risk of breaking the driver is higher than the risk presented by this race, and accessing the device requires privileges anyway. Let's just add a config option to completely disable this ioctl and leave it disabled by default. Distros shouldn't use it, and only those running on antique hardware might need to enable it. Link: https://lore.kernel.org/all/000000000000b71cdd05d703f6bf@google.com/ Link: https://lore.kernel.org/lkml/CAKcFiNC=MfYVW-Jt9A3=FPJpTwCD2PL_ULNCpsCVE5s8ZeBQgQ@mail.gmail.com Link: https://lore.kernel.org/all/CAEAjamu1FRhz6StCe_55XY5s389ZP_xmCF69k987En+1z53=eg@mail.gmail.com Reported-by: Minh Yuan Reported-by: syzbot+8e8958586909d62b6840@syzkaller.appspotmail.com Reported-by: cruise k Reported-by: Kyungtae Kim Suggested-by: Linus Torvalds Tested-by: Denis Efremov Signed-off-by: Willy Tarreau Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/block/Kconfig | 16 ++++++++++++++++ drivers/block/floppy.c | 43 ++++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 11 deletions(-) --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -33,6 +33,22 @@ config BLK_DEV_FD To compile this driver as a module, choose M here: the module will be called floppy. +config BLK_DEV_FD_RAWCMD + bool "Support for raw floppy disk commands (DEPRECATED)" + depends on BLK_DEV_FD + help + If you want to use actual physical floppies and expect to do + special low-level hardware accesses to them (access and use + non-standard formats, for example), then enable this. + + Note that the code enabled by this option is rarely used and + might be unstable or insecure, and distros should not enable it. + + Note: FDRAWCMD is deprecated and will be removed from the kernel + in the near future. + + If unsure, say N. + config AMIGA_FLOPPY tristate "Amiga floppy support" depends on AMIGA --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -2984,6 +2984,8 @@ static const char *drive_name(int type, return "(null)"; } +#ifdef CONFIG_BLK_DEV_FD_RAWCMD + /* raw commands */ static void raw_cmd_done(int flag) { @@ -3183,6 +3185,35 @@ static int raw_cmd_ioctl(int cmd, void _ return ret; } +static int floppy_raw_cmd_ioctl(int type, int drive, int cmd, + void __user *param) +{ + int ret; + + pr_warn_once("Note: FDRAWCMD is deprecated and will be removed from the kernel in the near future.\n"); + + if (type) + return -EINVAL; + if (lock_fdc(drive)) + return -EINTR; + set_floppy(drive); + ret = raw_cmd_ioctl(cmd, param); + if (ret == -EINTR) + return -EINTR; + process_fd_request(); + return ret; +} + +#else /* CONFIG_BLK_DEV_FD_RAWCMD */ + +static int floppy_raw_cmd_ioctl(int type, int drive, int cmd, + void __user *param) +{ + return -EOPNOTSUPP; +} + +#endif + static int invalidate_drive(struct block_device *bdev) { /* invalidate the buffer track to force a reread */ @@ -3371,7 +3402,6 @@ static int fd_locked_ioctl(struct block_ { int drive = (long)bdev->bd_disk->private_data; int type = ITYPE(drive_state[drive].fd_device); - int i; int ret; int size; union inparam { @@ -3522,16 +3552,7 @@ static int fd_locked_ioctl(struct block_ outparam = &write_errors[drive]; break; case FDRAWCMD: - if (type) - return -EINVAL; - if (lock_fdc(drive)) - return -EINTR; - set_floppy(drive); - i = raw_cmd_ioctl(cmd, (void __user *)param); - if (i == -EINTR) - return -EINTR; - process_fd_request(); - return i; + return floppy_raw_cmd_ioctl(type, drive, cmd, (void __user *)param); case FDTWADDLE: if (lock_fdc(drive)) return -EINTR;