Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2038375imm; Mon, 16 Jul 2018 00:38:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcl/tpbHMrXcIETEgsgzevYJ7lVm5229sCy1ciTLTOmibt+Ok7VC7wKaVqP3rdfNDKtYaNQ X-Received: by 2002:a17:902:3e3:: with SMTP id d90-v6mr15644156pld.12.1531726731589; Mon, 16 Jul 2018 00:38:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531726731; cv=none; d=google.com; s=arc-20160816; b=C+2PLfb3GptYK39XoPKkSG9lpGhQh4A3m5tlRzA/Dx+SKBln48iVUcoeKUY4IysNLw 2Znark51b0Qm2u6yONmaaQqwtYg2g5ehaxH3vhyRBWmVAbNL3WE3yiNqZfQ4lYGwNrW6 ZRDAfUuCWASyAXf73a72BcbDMtB9Ga9NjocO8bl9Za41yovAYlpozGkEr4Wlyct86+bw pGvod5HfV3Fl/gmVzoDkIiNLZaYARa9GqnSczZUXRVHjF+GOaBSLJEr0Ljo54mle5Ybd HR2tTBkgw2QfNlG3jbzIESLCVrT7gmV4itO2l1/Hs9UCt3BhtQzGpxMG/q0sMfePIfiu tniw== 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=7CdpqTvzu5XdDeWU+q1hGzJ+T2G7VisD2mq+xRvs4dM=; b=aqFChQkBMEBZH0lGJUw3PkNIjxG6zzS9OEENUzAjEfhrC0m6ygN7OnH3ZX0lwFiAGa u0xgLTAq4t6EVE2ZFBQCoWOWKYk3Jb9hdvO+lxYtOXTEITj9d+IeHPAw0fUzBV5vi8wJ BUV3SWMLmtr9aS97qAYPAPy2ATO8auHK0ReNkj4OC49le1C4UnvhbwTDmEHZvZJJMrA6 ONu5F90wpLBuMzEOFJrxMRYKMkCk8d73HTnejUoH9C5PQLcDH/pdHTJRg+Bs3UHMcu+j mhu2LDXhewjg1PpSZ8EIdGGa/kih48WQGe+LWivP/yXCq7/zkGabcDONbWmgPS5ULziG akFQ== 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 c7-v6si31247979pfg.308.2018.07.16.00.38.36; Mon, 16 Jul 2018 00:38:51 -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 S1731571AbeGPIDZ (ORCPT + 99 others); Mon, 16 Jul 2018 04:03:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46704 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728460AbeGPIDZ (ORCPT ); Mon, 16 Jul 2018 04:03:25 -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 A68BFCA0; Mon, 16 Jul 2018 07:37:23 +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.17 27/67] USB: yurex: fix out-of-bounds uaccess in read handler Date: Mon, 16 Jul 2018 09:34:56 +0200 Message-Id: <20180716073447.439942608@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073443.294323458@linuxfoundation.org> References: <20180716073443.294323458@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.17-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 @@ -396,8 +396,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; @@ -405,26 +404,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,