Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9934356ybi; Wed, 24 Jul 2019 12:36:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcahC1qG3btPdtPjdVK5OAdPkcZq2PcHvYGTR9vbJoaih3TNVRMZUPFO69Q1/WHxhoopLC X-Received: by 2002:a17:90a:3086:: with SMTP id h6mr90890919pjb.14.1563996976049; Wed, 24 Jul 2019 12:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563996976; cv=none; d=google.com; s=arc-20160816; b=XvxX/ZAqbfQFJOrdVfQoKmkcc+02R7kRUjKLtoy71/EOFHndRMZFYZO8mTTqJLilwq q65JBkSeFz1182guGVkmWJghKBVNo79Vb9aLh4BhYk+LfA8d94IVTbk6o+SzsDHM5v/H ZpPa4Z8E0DVbFKduOLLJMNmX6B430t8tfJnt9iCal9vp6SxTZK4vQvHNjslGFk8+9kCO x38pNSH2qooUl140dBk4wujdsFlMqVo5/064EqHKBYkBT/3qWuZZHmcwm4jUn0A4LmxZ 6mV5VSW3m9DwL2TsBr7H8aTZsZKhEKxR6d6hwyMIz1YM7saBi1GDa3HOg27TlDYNgvrS bicA== 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=RF3sVefh8PHGjK+qtRsSOQgGziftwriA2/Ng6C1CGc4=; b=B7Yw3OgXfNXzq4o68NR6fIyjk5SHeuC3z6aBR2Lj+iOD6w6l83XGdtol3MhHqFKOmr +IeCTYMgFxCyOfK0v1ysDuktZSctKp6cR1x3fklRtNyE2NUzawsI3WD8785VoehlhHgU W6reox7FfbroZm4vgLq8ju+8C8dB2+P5GOxOJcb50wFWtntj7mejvwc7/xOXcB9JrhKO wCEu7uCdGepgQmoQYrjjS8T5taxNizODl1CEcRKAKG0X04oyZ3b9sycGEG8e1PRcCaPc bzP0jgg3z48kiLscw4RZbTt/CrLZeZWn9472CxB43i4c3n/EXFM9komKE2jrFCdwrtgJ nrTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JlRI4dPU; 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 64si15418390plk.87.2019.07.24.12.36.01; Wed, 24 Jul 2019 12:36:16 -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=JlRI4dPU; 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 S2389112AbfGXTer (ORCPT + 99 others); Wed, 24 Jul 2019 15:34:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:57388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388566AbfGXTep (ORCPT ); Wed, 24 Jul 2019 15:34:45 -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 7C8A520659; Wed, 24 Jul 2019 19:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996885; bh=Nkas8Jif7pWemiGlAUKYyku8WRki+sdH/VZpZLAoFuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JlRI4dPUfn9Waioctaovko/17KsxG+8jHOAhlrwhILX0HBcf94Zk2SJGx0oJYxBO3 kzWkIaC23kqQUJnZjmySwnc1naTxDF+BEWtht4DfVgESOF3LH9BMRfa7MDKuPvLYok XbGOCVGKOsVGdl2F4wQEsrBKqEGYmVblBRSdMGoE= 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 5.2 248/413] floppy: fix div-by-zero in setup_format_params Date: Wed, 24 Jul 2019 21:18:59 +0200 Message-Id: <20190724191753.333671252@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@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 9fb9b312ab6b..51246bc9709a 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -2120,6 +2120,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; @@ -3232,6 +3235,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