Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3820209ybi; Mon, 29 Jul 2019 13:15:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhteX8LFpeSgd+faT6LVBWagIYIvQUMK++kzTnGeAhuwa6dHomucZiEkVS0kV7yn99G2ju X-Received: by 2002:a17:902:8649:: with SMTP id y9mr109912754plt.289.1564431338420; Mon, 29 Jul 2019 13:15:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564431338; cv=none; d=google.com; s=arc-20160816; b=alKNJ29XwBM/MAeMT+pHuMbs+P4DEE3xTinfFXvPucP53Et4MK9UnmKS+SJ/wSa4eu LWiUZU/BoJ2AyYsTTG5FAWy5B06g6VY7uAY3p+ULeLoCruENVTEJzk3gg2zDeRP8XDb1 rFhVK9QA1r9T7fuvpAK++1YtewZq6QN/z5WNL0AdofcpjYPkXtd+vWq1oKt6w68ApJ/k oSQa2ewfxAv2ZRAHEDA6/wLkGu1aYFiEzmIGy9LoF+OH+ghoUnUs59RNFhmk3aPwP9ro vt3Q7u2erPG9mPUgoC5eJzTSpIia4c3ztft/8l9uck+EvxmBXN+Tv4Q/d0lWavWfDHsk XDFg== 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=51Q3r36dk2nT4tLcFJNYvdsqfOfwS9Ra1fUhSsr7Edg=; b=HPSr5SA4qtOLrAPzZCO78tyQBakP6fBfD5khrbv6YZ3uSNrWVKsN9uZ5dVfmJDhQkp Vq50aeWPpJ0RFyLW0wSxmrThy/i2fk+e4FaYw1nrhrzSJ7y/PgWxNwOdztYReCAGHTGM 3UCRuQjkhFqZKoyvBlGthrY+vjYufDow8HPw+t8F14PC0/HlYWDB+ZytMdRlHcZUG0hX zeuEpDYGzHDWYpkya4OF+yEqCByGHogL1jYBAL8lmZ+TQBs7N/P6/nI2xf+JyS9f7AOc gviF4ZO7oklPisGW/E6eNOYSBhC+M9uG0v2kCa5YP9ZXpB9klp5SHU56xWHHeJBgubZH Nm3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=o7JzUzS3; 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 y8si27321732plp.96.2019.07.29.13.15.23; Mon, 29 Jul 2019 13:15:38 -0700 (PDT) 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=o7JzUzS3; 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 S1730457AbfG2UNG (ORCPT + 99 others); Mon, 29 Jul 2019 16:13:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:43770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727991AbfG2TbE (ORCPT ); Mon, 29 Jul 2019 15:31:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 1B75521655; Mon, 29 Jul 2019 19:31:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428663; bh=LTQwQTfiiLnS5uelwWGDIANmNycufdFERodD5wZg9xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o7JzUzS3c1Afp2EItF9T3yAtuzahUtJPxYHKsIct1B4lDyXaVr6mtWnf5wjlqyoyv toOROVWo7U9nfAbnMx5va03Hhsh4MQlKQZjJuXFa+9TqaIULRXimSBSDM3x6K/wIJQ +hlpdu2DYsQTFqMnVartbi09TtvQ7t+Y9kdhjnLs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Denis Efremov , Willy Tarreau , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 107/293] floppy: fix div-by-zero in setup_format_params Date: Mon, 29 Jul 2019 21:19:58 +0200 Message-Id: <20190729190832.857547616@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit f3554aeb991214cbfafd17d55e2bfddb50282e32 ] This fixes a divide by zero error in the setup_format_params function of the floppy driver. Two consecutive ioctls can trigger the bug: The first one should set the drive geometry with such .sect and .rate values for the F_SECT_PER_TRACK to become zero. Next, the floppy format operation should be called. A floppy disk is not required to be inserted. An unprivileged user could trigger the bug if the device is accessible. The patch checks F_SECT_PER_TRACK for a non-zero value in the set_geometry function. The proper check should involve a reasonable upper limit for the .sect and .rate fields, but it could change the UAPI. The patch also checks F_SECT_PER_TRACK in the setup_format_params, and cancels the formatting operation in case of zero. The bug was found by syzkaller. Signed-off-by: Denis Efremov Tested-by: Willy Tarreau Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- drivers/block/floppy.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 3ea9c3e9acb3..4c6c20376a83 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -2114,6 +2114,9 @@ static void setup_format_params(int track) raw_cmd->kernel_data = floppy_track_buffer; raw_cmd->length = 4 * F_SECT_PER_TRACK; + if (!F_SECT_PER_TRACK) + return; + /* allow for about 30ms for data transport per track */ head_shift = (F_SECT_PER_TRACK + 5) / 6; @@ -3238,6 +3241,8 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g, /* sanity checking for parameters. */ if (g->sect <= 0 || g->head <= 0 || + /* check for zero in F_SECT_PER_TRACK */ + (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 || g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) || /* check if reserved bits are set */ (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0) -- 2.20.1