Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9934401ybi; Wed, 24 Jul 2019 12:36:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzW6YEDd/iSqYPHFcs7Texj4Wz44csdf8Y8L4UhNGnl474XSxfASV41dl4JUWYZu7eoSzv6 X-Received: by 2002:a63:bf01:: with SMTP id v1mr81130917pgf.278.1563996979424; Wed, 24 Jul 2019 12:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563996979; cv=none; d=google.com; s=arc-20160816; b=a2i9+QE7AmkHgawGCMFRbnJcsbZ7GgZLeQ77u9PADAhEt/4gLtWtsfqXcibig4mzUg IU/pA/A1THgwtdL/0tgYqfiYl+YyP4hSdVjcBuKc6xR+wGt39CUNFptlgMdJaS3vBDbo tv0fJXRkCUVZ+cWYs8e+/JeDAG6ndPKAv7hymEPl1fl9iyC46nqfARhJJCz4jQ277Y0J 9hXarlDi449n/AGkIRNIYGc8exckJxt91SMNdh+PE/O5nj8tcACbkLFy1boNKYy/imWK yUnBSwnk1d3DGJN4mCG2Om8Qz6g97f/i8hgTIzVrg5hemCa4QfkK8vEhgymABPPLSigR 1+qw== 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=2F5BOt7kJ7oW42tgY4tI7hZWJ4grduVZPyBZ/nEmnr4=; b=VzsP1PUfnq9fAMsig7uTquSr3yTwgnTGh/Ux8ClWx56zoJhBGWsA4QgHm4GWZVh5F0 4msE+xc6MJyE7uYTYUepc1XpofUeuQXGl4nfejj3IiEfOU/0Qpl9rAkL6u0GpRHHi8jT 37/6zzUWSXMC1ECHXK0R1jYVIgQVDlR8qPqVHR7rAi8z7qk0YINkk3EUehk0Bfg32x8j AskB5s+FiB0oBPUaGG3cXvVIo/9tS+bfrcHKYY7hbPMRSccM7wApXYRPe6WF+UMXdwxK x2NPo7gSZp0WwVcIq8sf52XkcEeiO1HcZ9/YWVMw06cmiq58cAX+qx1+YMEvDqq2nujn ZobQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rUcEEJXr; 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 s19si14839725pgm.291.2019.07.24.12.36.04; Wed, 24 Jul 2019 12:36:19 -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=rUcEEJXr; 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 S2388478AbfGXTfC (ORCPT + 99 others); Wed, 24 Jul 2019 15:35:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:57740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389115AbfGXTey (ORCPT ); Wed, 24 Jul 2019 15:34:54 -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 5106F22ADA; Wed, 24 Jul 2019 19:34:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996893; bh=944oLU8GpRyQbzpH+RUQfTMKBma6bQ/q/t6IGuiHXc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rUcEEJXrCXHpdzBg1L0XJuNPQfzfCT6uSGofn+zykgn4oyUHAGYbRlYvE59ZIlgrt y3noWLl4vb/WI1M6FOi/5JIMuer7JTDodzyTlT/xHgGiBxWKRKEhOHjq+b7FUrotNI Fk1IXu7jYtAQ77hEVDma2xyBY5Dv7GsyCT2GbpZk= 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 251/413] floppy: fix out-of-bounds read in copy_buffer Date: Wed, 24 Jul 2019 21:19:02 +0200 Message-Id: <20190724191753.696056411@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 da99466ac243f15fbba65bd261bfc75ffa1532b6 ] This fixes a global out-of-bounds read access in the copy_buffer function of the floppy driver. The FDDEFPRM ioctl allows one to set the geometry of a disk. The sect and head fields (unsigned int) of the floppy_drive structure are used to compute the max_sector (int) in the make_raw_rw_request function. It is possible to overflow the max_sector. Next, max_sector is passed to the copy_buffer function and used in one of the memcpy calls. An unprivileged user could trigger the bug if the device is accessible, but requires a floppy disk to be inserted. The patch adds the check for the .sect * .head multiplication for not overflowing in the set_geometry function. 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 671a0ae434b4..fee57f7f3821 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3233,8 +3233,10 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g, int cnt; /* sanity checking for parameters. */ - if (g->sect <= 0 || - g->head <= 0 || + if ((int)g->sect <= 0 || + (int)g->head <= 0 || + /* check for overflow in max_sector */ + (int)(g->sect * 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) || -- 2.20.1