Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10423788ybi; Wed, 24 Jul 2019 22:58:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtrIxPNnwcaIEul56K1ukLP+t+uv57xp+7Wo7+netSwu02HRDVHb5jyey1folWTB/aI3bP X-Received: by 2002:a17:902:403:: with SMTP id 3mr87657586ple.66.1564034332854; Wed, 24 Jul 2019 22:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564034332; cv=none; d=google.com; s=arc-20160816; b=E+MHRBLpqC0ZW+8mu5YZIuZXXwDCKoVyxmDOLbUHIsc5ubmywaSmNy5TwArJMIDN94 MrIJV/vRu/c8ZDNcWMG6x94Ut6naglMcN+dXtFnx4NKytnfiT4pwzKM5KLh1jno27Fry 2m27rEMfVOTNZmk4VOeTz6d8Z4+IyJ0DcrYj/4P//fNr1mq3wVofU0d1VRJYTtgyDlhL Cjf0T7mFtbH3oa1NiOd1h70kx7jcAk74yCGfVOwM/kRfskLD/EZX1QSfSoZkkS1cIDAC pZebvCfvRGyxgGllApi88GSDCP4ouVqVvSOdFhQpGKH/asRjKrDZ3rC2bkJZJPMHmFec HbDw== 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=YsoTRMPLf8hg9FyZCmSdbGoINnbayaNE80CG0tYQ5s0=; b=FraqJWomOPxl6vxDzlIdPDuGVWzsITCPbXly8XV9ymVG2alomkvfJnIrr3n8dat4pI jtu6MIpGC/pPNi2ZdvHbb4eQ0WN1d873tiH7fmq2zcJEQsoKvWg8ftM5ST4iMI+KBxiD /Yk/6uFrAsTqDF95O1ZYhGNjo3ozyth8rC1J0nxNBMdd/muC/owvUkTLOqCbKUWEDZwf fI42uMzm7OS0+u+JGr90Re50Q2fYMCjyZq5gAl01VxCw1jCcgUM4EGbM6N5wBEr+CZwf QW39RxcULItDDYTLy+kI2Eh4mGKwesRNdfTOYbUMG6w/hK9hsy2KzfowiVlhxPnEEpIU mxbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Tg9R/cuY"; 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 d67si17603443pgc.62.2019.07.24.22.58.37; Wed, 24 Jul 2019 22:58:52 -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="Tg9R/cuY"; 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 S2404769AbfGYFly (ORCPT + 99 others); Thu, 25 Jul 2019 01:41:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:56728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404736AbfGYFlw (ORCPT ); Thu, 25 Jul 2019 01:41:52 -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 80E5822CBA; Thu, 25 Jul 2019 05:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033312; bh=//PU4v4x92ikuyKxdA9mM5ufKcVAvDqzUpbbgYRw72Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tg9R/cuYCDWU5MC2YOXed6omXPEnGSRSrN8Lz0hNMz1Ir1uJ2xZqfVNFunrXFXJ9I 1bKMd53OJpjEPwhSomMjvsDk+NhX/dZSIeda/sEtLN7OS1wcBtzBCiZcSgXogT/xyf hJBGRxzSrueUUxA2rWXh5MfyGZ84u+kYvdC+tzwg= 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.19 163/271] floppy: fix out-of-bounds read in copy_buffer Date: Wed, 24 Jul 2019 21:20:32 +0200 Message-Id: <20190724191709.136938325@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@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 8d69a8af8b78..4a9a4d12721a 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3244,8 +3244,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