Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4595070iob; Sun, 8 May 2022 18:36:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztdPBTr7yNJrl/oTcnUMjeWM3Y9yZHa1zrNFO/GJKPOxVGG+cSruZITQ7bjTdeE0Fhprri X-Received: by 2002:a17:90b:3b84:b0:1dc:970d:bc1b with SMTP id pc4-20020a17090b3b8400b001dc970dbc1bmr15316783pjb.147.1652060204472; Sun, 08 May 2022 18:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652060204; cv=none; d=google.com; s=arc-20160816; b=z8es/TN4HwOO3hx+r1VgJNmXtgJSUv3GbYKfttQ4R8gWQrPOeZwDRKQ1cDSI/eYQUK jJPPGk9yTZAqB4UqO1I1Q1x5eg3iBlEI7/+2vd7ahbSKLcas12+kpRkgzKLBdAOODsv+ RQd6NrbgVepoBbFy44AGMQjEcNLTxLcJi2NB2CpaEpiEJjxtcwdjrqOccN4YGghkBWYS EXX9aFNbGDfS2GH60Jn20lAsMAcJVyxrvQzp93Sh5fZOAFJuWp0YpBs7GCEAdTFYibuy ohBzGWX/ydRvbpENBveIc4ZyiA9kiitzEP/qrSyd0GUaoAvaV6OI91RYKsUjXZfDVA56 I3Ww== 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=HETNToRl0AojhW+VBrbcXG6myyhb9tHE48uM5ykk678=; b=B0s2q2vyycL0FLtkB39NMS9ez5hH86bRnxg1CjwQUiojz1GirAynp4U0zy152nIVNt Cn2nnAfLDni7jeAS97l5ax9DMBdPijbNLyRt4VYw5hDbLzYH365OqQAQ1ITHJnSry+8K tLigsdlru5KyR9Sy3X+KKVur5gcDSvqBu0VYM9vzFXvnYXcpyr0ZE6EpQrQSD12L9vM9 8SiFOlfBHfMBtrFv0gpwhhwo9o29uqaYirvrYhChb+LGKNAFNUv+YRai/dqBxs7IjFCC Lm/f515feTD15JwQR5i8JIzj5fEtDfLpLwGwlPEWS78ne2ma2KR5s+uz5GRCUyzVeAol UoXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MOVA92uG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k186-20020a6384c3000000b003c642b43d4fsi9670678pgd.520.2022.05.08.18.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 18:36:44 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MOVA92uG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 67B833206F; Sun, 8 May 2022 18:35:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353618AbiEDQvu (ORCPT + 99 others); Wed, 4 May 2022 12:51:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353097AbiEDQvs (ORCPT ); Wed, 4 May 2022 12:51:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD28EFD2B; Wed, 4 May 2022 09:48:11 -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 4FFE161744; Wed, 4 May 2022 16:48:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E261C385A5; Wed, 4 May 2022 16:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651682890; bh=5HKhrFqmSPIq+BqSgu30j1FGtY9X74eIt1QMhVbVH1Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOVA92uGzbYzpUeLxSA2E/ONONQ72c8UUb2IxEoWMH1O7dbGD3Pwe4au9egZn9rlO CdZxIP5lOtE5ZJgKaaWxd/uyilRr8RjKw0REBMj6snbqoNbnwhaeyLApdrJQl4AVMD wql8TXnlNtkBZFBBXi/aYGyiXKm6D30d6Df0mwbE= 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.4 01/84] floppy: disable FDRAWCMD by default Date: Wed, 4 May 2022 18:43:42 +0200 Message-Id: <20220504152927.867768825@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504152927.744120418@linuxfoundation.org> References: <20220504152927.744120418@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=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 @@ -39,6 +39,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 @@ -3012,6 +3012,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) { @@ -3223,6 +3225,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 */ @@ -3410,7 +3441,6 @@ static int fd_locked_ioctl(struct block_ { int drive = (long)bdev->bd_disk->private_data; int type = ITYPE(UDRS->fd_device); - int i; int ret; int size; union inparam { @@ -3561,16 +3591,7 @@ static int fd_locked_ioctl(struct block_ outparam = UDRWE; 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;