Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2042159imm; Mon, 16 Jul 2018 00:44:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeSTI54aET8NCwd41gVZKu8VtHYe6PIMKiTh+KeXYolXZxOtJOLt94oYAfc+PiQUKjz9IJC X-Received: by 2002:a63:6e08:: with SMTP id j8-v6mr14500824pgc.428.1531727061966; Mon, 16 Jul 2018 00:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531727061; cv=none; d=google.com; s=arc-20160816; b=jJO47KdUtvsVoEk89PSI6+gtVZUbukxY1Q9wpQtuhgFzEe7aUplApADtsfhvJurRqW LpVLTKmbcEG9TxTuZmaxAM25844ZIfIKB1ae5pqPuWKMsGfc/ZVJwdKavkE4kAFQ788y P32FneFLYTzrY8HTzDmWCKPL9I/13V0uKR3YAnF2QwjsJAEmXuI8XQT+cOegBiabXiv0 5l7WiiEtWzUyvrVDyBP+sLm13oqklYg+j79y70b323lBstIYBes8Lh+tWbseAZSb+cxw J6UEVn0WpRRp50FLmNx3ueScO8Hh6WD5wQ/WTsQIMhi1TUT5cm7bx54wDIgiGudKO6Aa izkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=1JknJolAVoXC7OcbJwfjWm8NAIvNCqbx69tGVQFAVFc=; b=M+5D1SqXu6G56yNP2FJ9+gdvMi4w2j2eGez1QnrfZaC4BwAjI55QlnNYcK2YJbwegN qKMhRRzpLvQ0AWl7uB1kil50usVQd9RxSCZpIx1wCH5PZ5dtJMKtZc3OcFr+zpn0mgef S+OYzgeaFc07PnH/94/IFvK7pTnaBfK/LnBlqu7Pf8D+ezsYVQCcfpKSBqS2CGnsfIne rmSWfwnaZJDh8RMAXt0lCu2xnaBuyxLZA5NNtopT15tXLKk5zuWwrWlkSryiX3kh10Q3 6k/nIvy5rmc126xetWvBIlNDhNc9VlDqAs68xr6Q6CEtLCo9Ox8wJblLI5+hD1DacfPq 5+Ug== ARC-Authentication-Results: i=1; mx.google.com; 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 p84-v6si26900030pfl.17.2018.07.16.00.44.07; Mon, 16 Jul 2018 00:44: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; 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 S2389088AbeGPIJh (ORCPT + 99 others); Mon, 16 Jul 2018 04:09:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48022 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389078AbeGPIJg (ORCPT ); Mon, 16 Jul 2018 04:09:36 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6FC30C03; Mon, 16 Jul 2018 07:43:33 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn Subject: [PATCH 4.9 14/32] USB: yurex: fix out-of-bounds uaccess in read handler Date: Mon, 16 Jul 2018 09:36:22 +0200 Message-Id: <20180716073506.120084210@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073504.433996952@linuxfoundation.org> References: <20180716073504.433996952@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn commit f1e255d60ae66a9f672ff9a207ee6cd8e33d2679 upstream. In general, accessing userspace memory beyond the length of the supplied buffer in VFS read/write handlers can lead to both kernel memory corruption (via kernel_read()/kernel_write(), which can e.g. be triggered via sys_splice()) and privilege escalation inside userspace. Fix it by using simple_read_from_buffer() instead of custom logic. Fixes: 6bc235a2e24a ("USB: add driver for Meywa-Denki & Kayac YUREX") Signed-off-by: Jann Horn Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/yurex.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) --- a/drivers/usb/misc/yurex.c +++ b/drivers/usb/misc/yurex.c @@ -406,8 +406,7 @@ static ssize_t yurex_read(struct file *f loff_t *ppos) { struct usb_yurex *dev; - int retval = 0; - int bytes_read = 0; + int len = 0; char in_buffer[20]; unsigned long flags; @@ -415,26 +414,16 @@ static ssize_t yurex_read(struct file *f mutex_lock(&dev->io_mutex); if (!dev->interface) { /* already disconnected */ - retval = -ENODEV; - goto exit; + mutex_unlock(&dev->io_mutex); + return -ENODEV; } spin_lock_irqsave(&dev->lock, flags); - bytes_read = snprintf(in_buffer, 20, "%lld\n", dev->bbu); + len = snprintf(in_buffer, 20, "%lld\n", dev->bbu); spin_unlock_irqrestore(&dev->lock, flags); - - if (*ppos < bytes_read) { - if (copy_to_user(buffer, in_buffer + *ppos, bytes_read - *ppos)) - retval = -EFAULT; - else { - retval = bytes_read - *ppos; - *ppos += bytes_read; - } - } - -exit: mutex_unlock(&dev->io_mutex); - return retval; + + return simple_read_from_buffer(buffer, count, ppos, in_buffer, len); } static ssize_t yurex_write(struct file *file, const char __user *user_buffer,