From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28496C433ED for ; Mon, 20 Jul 2020 15:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0349D2065E for ; Mon, 20 Jul 2020 15:53:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595260423; bh=fsnnDiVTPQQbT2KVekUadP5jr9jJ91n2sCUXodLSEyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZPk3teiAsyBO8YUeuHDUtmrlms43OiGSe5Z1bVCiU0r8d5+bd7F8koDtWGS0V1o4T GUus3a1o7QMywLUKWtzgJRe+uEM8PaxJlmwbdQVhn9c660/05Tws1Agt6SO70uocW6 Z55VBWVzSntyaoc1/sFwrrzarucpXw88Df41iR/4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731493AbgGTPxl (ORCPT ); Mon, 20 Jul 2020 11:53:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:52142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731485AbgGTPxj (ORCPT ); Mon, 20 Jul 2020 11:53:39 -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 81E6C2064B; Mon, 20 Jul 2020 15:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595260419; bh=fsnnDiVTPQQbT2KVekUadP5jr9jJ91n2sCUXodLSEyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1+ABq2NGbcTYTEffMOqrqlH6ocCHNoCS41REyXJhneFnkGzrLGtgmj8tPfo38qCgY VO2gl/v4n87IEiOdo41P2qFhJzZLiuKxpmR+zUacPQtBtKOXAlNA5TIoCWjbPca+qk vmLMxZ3ejqO+nIw7nMoBJfOV+hLKIQ2sFkzDC9P4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 4.19 094/133] USB: serial: iuu_phoenix: fix memory corruption Date: Mon, 20 Jul 2020 17:37:21 +0200 Message-Id: <20200720152808.264804020@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200720152803.732195882@linuxfoundation.org> References: <20200720152803.732195882@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 From: Johan Hovold commit e7b931bee739e8a77ae216e613d3b99342b6dec0 upstream. The driver would happily overwrite its write buffer with user data in 256 byte increments due to a removed buffer-space sanity check. Fixes: 5fcf62b0f1f2 ("tty: iuu_phoenix: fix locking.") Cc: stable # 2.6.31 Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/iuu_phoenix.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/drivers/usb/serial/iuu_phoenix.c +++ b/drivers/usb/serial/iuu_phoenix.c @@ -697,14 +697,16 @@ static int iuu_uart_write(struct tty_str struct iuu_private *priv = usb_get_serial_port_data(port); unsigned long flags; - if (count > 256) - return -ENOMEM; - spin_lock_irqsave(&priv->lock, flags); + count = min(count, 256 - priv->writelen); + if (count == 0) + goto out; + /* fill the buffer */ memcpy(priv->writebuf + priv->writelen, buf, count); priv->writelen += count; +out: spin_unlock_irqrestore(&priv->lock, flags); return count;