Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3819910ybi; Mon, 29 Jul 2019 13:15:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjQQCLUvHUr2S5dC0xoepXBTFh72QXW88cEGNWrbL4QFwRFfSKfrzlOuhqyKthCMOMEDn7 X-Received: by 2002:a63:4041:: with SMTP id n62mr34601598pga.312.1564431321775; Mon, 29 Jul 2019 13:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564431321; cv=none; d=google.com; s=arc-20160816; b=G5/4M+hH7JCHy8ygY81CmCcUwtUs7fRm7LdtwHV/FBx5wqiCghXGlpTHwsY+l4uge2 esiH/bjuyiDXExoviZ8oP4RpUl7MWpjtGuB8B69DAyoQT92rncV1Ru2/KIK0iMjWMv8x Wl1nceRWplF/uWHRVjKZpqV0LlaE3NeNQnEpzDBjiAdu4pHAO6pOVcp4lei6UZ1a/4jg UezdagHLj3rRO2JirIEN+WiH3I+qIjXXnh7pudHZAmU2K2/M2ZpVWe8gvaqXJzC+xEr/ 0tyXwF3xJ/Rl38uBg6iVTeeUdsM5lc+iZwClzaMZc4V1nEEDNAAa7hAZsKS9GtyIUtXR G1Aw== 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=sC3SDDqt4bAh2vvRFONdEKgSuZcCuEJs/gz+5W2LDBc=; b=VmkwcMsNqYT7y42KZ5HpUpU6h85f06nAu9yOYNQNzXjhf85F9iDQkKKFGIOgTzqcJu VBXRLPR7FNGD/rgqKlWr8JbVho1wD7hQmMOLXJL1TE43hB26CG7IxP4SXn8E+HXAiK+Y fwXFc8KZig+mw84ya49tXERgSsbc4piJTHQoTuvEPCct6QLEKkQvSZtKFEAOhMBZuOj/ l/4m54JJ8e8n+X4DEfPdoyrmlF5h7XQwpdx9ys/h5nNufBP5h7xcuEHgRWJNcs8QZja7 AviziblseUukodruMJVLcP24jTrnGRn7W80BEZgWZi4jzpyn+XH/h9wV1fQCzf0+wrfW upzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V9tAABjq; 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 e11si26360470pgt.119.2019.07.29.13.15.06; Mon, 29 Jul 2019 13:15:21 -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=V9tAABjq; 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 S1730074AbfG2T3I (ORCPT + 99 others); Mon, 29 Jul 2019 15:29:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:41772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728761AbfG2T3D (ORCPT ); Mon, 29 Jul 2019 15:29:03 -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 3E83D2171F; Mon, 29 Jul 2019 19:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428542; bh=IhgeI8U2YdsEyZ2+mAN0ghIqlK8ZxxXuToQe1m/0Yw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V9tAABjq79taWPXl5H2gNTq3bxTSeKee0JvOyolmuhs69JpAffHqH82FLvqGyU1FA LO3OegRwWYaFioJDD8J2Oo87Fxe0g50Cf/OgH0tnUmsPzXi89zRrMSRpri4H3Tqpw4 PHLPWNApZwWg+7FbS6Co7yRxmhwhPC0WjOqzSWjQ= 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 110/293] floppy: fix out-of-bounds read in copy_buffer Date: Mon, 29 Jul 2019 21:20:01 +0200 Message-Id: <20190729190833.083054087@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 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 b4051e251041..a9d1430fc5ee 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3239,8 +3239,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