From patchwork Fri Nov 9 14:33:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kleber Sacilotto de Souza X-Patchwork-Id: 995572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42s2hQ4y3Bz9sD4; Sat, 10 Nov 2018 01:33:42 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1gL7qr-0001GT-Ih; Fri, 09 Nov 2018 14:33:37 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1gL7qq-0001Fx-4P for kernel-team@lists.ubuntu.com; Fri, 09 Nov 2018 14:33:36 +0000 Received: from mail-wm1-f71.google.com ([209.85.128.71]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1gL7qp-00069B-T1 for kernel-team@lists.ubuntu.com; Fri, 09 Nov 2018 14:33:35 +0000 Received: by mail-wm1-f71.google.com with SMTP id f196-v6so1808876wme.8 for ; Fri, 09 Nov 2018 06:33:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=WpHG+7Hph5X4aNZLcXYNoQ+45pHQRoT4rA8YEUTHLxw=; b=e7m1aRVZ5GkgRfu8a6wkGzKQcjwkDPwmr0JWs9XU3XJLp1KV+V/6HwJqHGHcX5zaEB 206+IzHSXdPvv7gOShOgTSaK7H5DJDrkERwQTh0jJ4N/W8pNpAdidrswen2wpE3ieJzS xLGsrTzA89oNdKepE1ehmMLdAuhD1TFGcKnIjzISz4hOdOADU+qC1zHpLT/yqUDFAYL4 UHBt2OFoJ1kt0J8dd72LCaX9Z2jr54X6VFNlxj5Xygzq7HORkI2+DuoBWOELZhboPMNU ED7RSxwIeLidc+7agQJ5q9GcYo47ZWpkDeVVL4jKkZ8qFd1nUlaFPX08TUlFfehCmzbZ 42RQ== X-Gm-Message-State: AGRZ1gJbD+u1rWeEh9W29URf1eblhlTMzEgfNbSgSsCSb637eRJjEwpN CnNcTJ0SIhPGu/E4WWoyGQfebRR9MftOlz89KqrGK1P4tcjEOGCGdGE8bYv8A8SoDROuYl294fW WqpYTZv+0eYpSct4nVddpIZCwpng3HudQ2K3D5YANEA== X-Received: by 2002:a1c:5585:: with SMTP id j127-v6mr1637764wmb.127.1541774015186; Fri, 09 Nov 2018 06:33:35 -0800 (PST) X-Google-Smtp-Source: AJdET5fpmGH9C/2pVm038NdUf3UtgU5UAeqMxR+1+rIMuscp4b0qLYTnSJ/WgRP8/Pg79zuXkzqlyg== X-Received: by 2002:a1c:5585:: with SMTP id j127-v6mr1637748wmb.127.1541774014861; Fri, 09 Nov 2018 06:33:34 -0800 (PST) Received: from localhost ([2a02:8109:98c0:1604:d18b:fdaf:4fb2:4856]) by smtp.gmail.com with ESMTPSA id h16-v6sm7726056wrb.73.2018.11.09.06.33.33 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Nov 2018 06:33:34 -0800 (PST) From: Kleber Sacilotto de Souza To: kernel-team@lists.ubuntu.com Subject: [SRU][Bionic][PATCH 1/1] USB: yurex: fix out-of-bounds uaccess in read handler Date: Fri, 9 Nov 2018 15:33:26 +0100 Message-Id: <20181109143326.31048-3-kleber.souza@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181109143326.31048-1-kleber.souza@canonical.com> References: <20181109143326.31048-1-kleber.souza@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jann Horn 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 CVE-2018-16276 (cherry picked from commit f1e255d60ae66a9f672ff9a207ee6cd8e33d2679) Signed-off-by: Kleber Sacilotto de Souza --- drivers/usb/misc/yurex.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c index 8abb6cbbd98a..3be40eaa1ac9 100644 --- a/drivers/usb/misc/yurex.c +++ b/drivers/usb/misc/yurex.c @@ -396,8 +396,7 @@ static ssize_t yurex_read(struct file *file, char __user *buffer, size_t count, 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 *file, char __user *buffer, size_t count, 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,