Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp434991pxj; Thu, 20 May 2021 12:49:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzibN0svPcs5k2j/ZXYmBH0hapMj0e4PilIC20hFYkKRXOu15/CTyH8WYQfMizZssHPqet6 X-Received: by 2002:a05:6402:424c:: with SMTP id g12mr2658002edb.145.1621540195943; Thu, 20 May 2021 12:49:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621540195; cv=none; d=google.com; s=arc-20160816; b=FH1WCrKCf5rdwAFNKMvpbtQOGwPXnHqLj2QjEO01StM0DOG3yUuzmeCZuZY6s0+nMF gldpTfuP4LBS+KftcgWqa2qsQ0KE/UITKtS2d3wTJAJOaGm8Pwl/VtqXdO5xInldvF9r ZhqeqoM3ZtPA5bOgbig+OEaSpCsRUXKRRmv95Y8MaoEgfGQ6hyEYycK0T25D4UCKkypa 7BKhl5jmc/HL3mHKqDcta6nNYiw52rPVH+Q/p85VUR5RcO9J/b1bOvgZeyVFk6mcMCWI 0Hn9U605K5IHEXDskE3ctTHLmlQBVxI+z2SeQOCKj8AHg1z+n97X2N3+Qa1MHpkPAqeL V9vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zB0/URdG1KwXQ/tN1YmsNmgAQGYGnPf+fRNuEz6L/eI=; b=MioTATP1r9hiUl2AauooJ2MU6Jaz1GfsGQbltX8Q8H9Ojcp3OMXAAALHeFBoV0X4k4 vLrYzJxwFw/6Gmmfz0fLZvI2TRidvU3FtG7kcnHQ73dQZSu7jUsvJ/0eUP4RTDiad+ge rjMLg8URaC4i8BrXcw0z2242z7RIeEd4ETyH07e7xU450V2vYPGy/ToVYWxC647wyEFf 2f5LN9P4v6APCmbgINTA7Lszi29xlgar1k9QYbuy/z/BOcAND5M3VIZKjxuTiAZ8Ab/D 1ZQRSriBPTmJUoCTC9AtVhVeU04SWJWYgRUINAhs1Ygu/QIZUj2x0HWelLN8iw3zhnto hJvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ngBQCaAa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si3543294edy.550.2021.05.20.12.49.32; Thu, 20 May 2021 12:49:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ngBQCaAa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237551AbhETKoB (ORCPT + 99 others); Thu, 20 May 2021 06:44:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:55694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235366AbhETK1n (ORCPT ); Thu, 20 May 2021 06:27:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 488FC6148E; Thu, 20 May 2021 09:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504239; bh=ZIc94EMqkcuLuXABTiZV+DtZ32oFzvSevuNJeutMsao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ngBQCaAa7JAx55jNKib0qWEOWMkdwLU+8fgFqQpjP6S+At/t6k3viSqnyrajm/iSm fv5kaQvhLPYoGodp0SXmCijRVKb2tDcnm3oAOGrDlDVZ4/79uZSyKy18n9ujp5KI/J yx+dNvgzjL8GGJ4qMLhiZGeE5mu3hDYfIqTa3HV4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fabian Vogt , Sasha Levin Subject: [PATCH 4.14 155/323] fotg210-udc: Dont DMA more than the buffer can take Date: Thu, 20 May 2021 11:20:47 +0200 Message-Id: <20210520092125.416291777@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fabian Vogt [ Upstream commit 3e7c2510bdfe89a9ec223dd7acd6bfc8bb1cbeb6 ] Before this, it wrote as much as available into the buffer, even if it didn't fit. Fixes: b84a8dee23fd ("usb: gadget: add Faraday fotg210_udc driver") Signed-off-by: Fabian Vogt Link: https://lore.kernel.org/r/20210324141115.9384-7-fabian@ritter-vogt.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/udc/fotg210-udc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c index d25cf5d44121..315d0e485d32 100644 --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c @@ -340,8 +340,9 @@ static void fotg210_start_dma(struct fotg210_ep *ep, } else { buffer = req->req.buf + req->req.actual; length = ioread32(ep->fotg210->reg + - FOTG210_FIBCR(ep->epnum - 1)); - length &= FIBCR_BCFX; + FOTG210_FIBCR(ep->epnum - 1)) & FIBCR_BCFX; + if (length > req->req.length - req->req.actual) + length = req->req.length - req->req.actual; } } else { buffer = req->req.buf + req->req.actual; -- 2.30.2