Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1189459ybi; Fri, 2 Aug 2019 10:49:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyce/5Io46dRbNN4/g0WUkp5J+bn3wGB8U8RhLiNXgSZaLq7cDm4TKNcA5UC4Xwna95vwhB X-Received: by 2002:a62:b515:: with SMTP id y21mr62053402pfe.213.1564768144322; Fri, 02 Aug 2019 10:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564768144; cv=none; d=google.com; s=arc-20160816; b=RnBdU/qI9csKLXm+gp3fG1hbeHUXquisdsS7/94S13DbMsB+cRyyOk9DjWpYywGFxi ccg/g7ZL4S6tKgEHF/yM2kJR7TcA7F4PbH6CRlcxiAhL0HHi3qExv0ALuG7G5qwJoLi8 K5XX278EB9POmau7WeD+SgDqL3zCB1AmJfdZ72vR50JvAlA61rJH3x5JzCZSbBMoBa5d TPPKFtj615GWWA7IFVtzkeCzRkm4Q92/344jslY8NLRuEN9qoaIS7OHC/5Kiqg5DhQtM NsdMWFhJCe2TToZyA0lBzMbAEFU58Ual83I7iOmGOAplFBFHJFC+jBpykIM3Mk+FWzGz jlVA== 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=sWXJupwI55wolS9E3l9ybVzC3EbRwSbf4AeeuwKg5rQ=; b=CNAnZLeLTnNKUzTGri+T4eTDxGapLoEZZcm22i1/Z7OxFi77t6lN9ZsjRqECx52zsI fBBx+AdNv1MvbIiAIL5dtn8uMiJ4aSj8mcs6827vnZnynhfuJh7wNb+6+gkKA5Cv9Qeq l3czDEnUIyJXVkctz8cjAu2x4J8ZEx2xh5l86iBbISV5fQ4kM4qep4O0i17EoV5pde2W TJ9vi/VXu03sYd8/1gZoJO3HsktWYhTdUoU6PlCSQBnP28gsqWezbUn4w2RmlsJOfZT/ 4kpHv5ZpfwEXfSv9iB52FNMC43BUlLjxqz5TLwb5pAdI5cPJ2rHCarOqufCbsgaSsC81 KZgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="G5/O5LZh"; 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 6si36602103pld.293.2019.08.02.10.48.49; Fri, 02 Aug 2019 10:49:04 -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="G5/O5LZh"; 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 S2405776AbfHBJuw (ORCPT + 99 others); Fri, 2 Aug 2019 05:50:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:49042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391477AbfHBJpT (ORCPT ); Fri, 2 Aug 2019 05:45:19 -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 682782087E; Fri, 2 Aug 2019 09:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564739118; bh=3rJFkMkaF6i6+N+CP0PMLPJyRCQ20v0GyX5nZVhhU28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G5/O5LZhr8DI3kyUMypb2MFOY3WyXctE3UydQwgmVUaIyxwNKjhOB8P0/AavoIgvs 6UiLr8YmvX6OIRiHbvKR0LjM0cKYplybhVG7S7qoz+jxzhWqQwOJKqHFJzD0PkYW1Q vFj7F7iaKQnXeb6TwqN47mTF1fbpZe4b/NIpGWrc= 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.9 106/223] floppy: fix invalid pointer dereference in drive_name Date: Fri, 2 Aug 2019 11:35:31 +0200 Message-Id: <20190802092246.115916000@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092238.692035242@linuxfoundation.org> References: <20190802092238.692035242@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 9b04609b784027968348796a18f601aed9db3789 ] This fixes the invalid pointer dereference in the drive_name function of the floppy driver. The native_format field of the struct floppy_drive_params is used as floppy_type array index in the drive_name function. Thus, the field should be checked the same way as the autodetect field. To trigger the bug, one could use a value out of range and set the drive parameters with the FDSETDRVPRM ioctl. Next, FDGETDRVTYP ioctl should be used to call the drive_name. A floppy disk is not required to be inserted. CAP_SYS_ADMIN is required to call FDSETDRVPRM. The patch adds the check for a value of the native_format field to be in the '0 <= x < ARRAY_SIZE(floppy_type)' range of the floppy_type array indices. 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 Signed-off-by: Greg Kroah-Hartman --- drivers/block/floppy.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3384,7 +3384,8 @@ static int fd_getgeo(struct block_device return 0; } -static bool valid_floppy_drive_params(const short autodetect[8]) +static bool valid_floppy_drive_params(const short autodetect[8], + int native_format) { size_t floppy_type_size = ARRAY_SIZE(floppy_type); size_t i = 0; @@ -3395,6 +3396,9 @@ static bool valid_floppy_drive_params(co return false; } + if (native_format < 0 || native_format >= floppy_type_size) + return false; + return true; } @@ -3524,7 +3528,8 @@ static int fd_locked_ioctl(struct block_ SUPBOUND(size, strlen((const char *)outparam) + 1); break; case FDSETDRVPRM: - if (!valid_floppy_drive_params(inparam.dp.autodetect)) + if (!valid_floppy_drive_params(inparam.dp.autodetect, + inparam.dp.native_format)) return -EINVAL; *UDP = inparam.dp; break; @@ -3723,7 +3728,7 @@ static int compat_setdrvprm(int drive, return -EPERM; if (copy_from_user(&v, arg, sizeof(struct compat_floppy_drive_params))) return -EFAULT; - if (!valid_floppy_drive_params(v.autodetect)) + if (!valid_floppy_drive_params(v.autodetect, v.native_format)) return -EINVAL; mutex_lock(&floppy_mutex); UDP->cmos = v.cmos;