Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp841390ybi; Fri, 12 Jul 2019 05:32:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqysNL/JMFuhawiLMmrgAFb4OFjERL/BnKMgsAV6J9XlhwLIEfUAfKYbnXJ40JstwLZ/PPev X-Received: by 2002:a17:90a:cb18:: with SMTP id z24mr11195220pjt.108.1562934763572; Fri, 12 Jul 2019 05:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934763; cv=none; d=google.com; s=arc-20160816; b=VwysiEFDYnwVM0EWkkps42kTFV0VJ8ZvIFhilDQK1CX295/wDm6RfT/eIEQAjm6dnO SujmOlmlSPnT02hrV/8hbEGxsOFr3a/afwONEFEQN7XrsCQ0HZ175XxwEn9AGQlyl4y/ 9n6qb+Khc/kKMmkL45t0DgWeJKmHkgGpZV/XrVTCN8EYOe4AkdcXc+OJvitHAzwXJ26A dB2y1nkt8I4JZVAXUD7AYxAQJKgZ8ScNWmqWbuoX724GHKTvcK7gmludTgrbDKj5Aok4 849luA3OrpbhwqClV1MOt7hX1Tt6T9j5j/oJ8yBr5sOnWhOCd0cwG6k3uUsNBeD3UpCo LG9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ka1JhY2tQGvGSi+F/DU8IKdSdXjK3hozUwo8XMxRKC0=; b=xySj1+e5Z4qGHUCG4u9HyDHnn6yzBdjBV6qZXCMTYqqX6NR0HVvp2NXEGkX6E/k6cQ FtI/zA4p51S+/jPSlyBxlHfI/D+M7hjP4s9t5YCMf/O7NF2gKv2HhhVp+2AE0JCjJN5O ICChKRP38XF2EvhGxVZRgsfHTdgjywyFavNbzmRYD5+VW5/sSjiodU/HojmUg9yKd/TL EOSJ6wyHZjkRLIUZQs51yPZ/OYjQRL1sOZuYW3rbmYxuxFmp0A/j66+RYpB3+oK3BBEM GKZGO/w2XDdIDVehPFf61978CSeBGgDmfkehSS+7yAbG9bIXgq3ZPQ1+rfGo7YDa/Oys 9OiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nBHMCnQP; 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 r24si8402893pgj.342.2019.07.12.05.32.28; Fri, 12 Jul 2019 05:32:43 -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; dkim=pass header.i=@kernel.org header.s=default header.b=nBHMCnQP; 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 S1729208AbfGLMaV (ORCPT + 99 others); Fri, 12 Jul 2019 08:30:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:45820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729188AbfGLMaO (ORCPT ); Fri, 12 Jul 2019 08:30:14 -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 B4EB42166E; Fri, 12 Jul 2019 12:30:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934614; bh=bOSHJRD+yncBX5fw/6Yk1AQF+h2Hxgw71ox8mXIVFeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nBHMCnQPq1Sd5QqeUyAYOT0UfJ3eIcwoAoTjlk2EkhL/SVnjO9ld6o0tE34JKcUlJ 83OzLc6TO+Sw9u2H5Y7fCqwCauAJpABWWO0Vo9r5tfBDwY9DqbIX9uKfPE3Sr7xuW6 2MhjZifMX1NLtXNP0rbqrYVsP51r/OIVOL9pSP7k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fei Yang , Felipe Balbi Subject: [PATCH 5.1 112/138] usb: gadget: f_fs: data_len used before properly set Date: Fri, 12 Jul 2019 14:19:36 +0200 Message-Id: <20190712121633.054072432@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@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: Fei Yang commit 4833a94eb383f5b22775077ff92ddaae90440921 upstream. The following line of code in function ffs_epfile_io is trying to set flag io_data->use_sg in case buffer required is larger than one page. io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; However at this point of time the variable data_len has not been set to the proper buffer size yet. The consequence is that io_data->use_sg is always set regardless what buffer size really is, because the condition (data_len > PAGE_SIZE) is effectively an unsigned comparison between -EINVAL and PAGE_SIZE which would always result in TRUE. Fixes: 772a7a724f69 ("usb: gadget: f_fs: Allow scatter-gather buffers") Signed-off-by: Fei Yang Cc: stable Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -997,7 +997,6 @@ static ssize_t ffs_epfile_io(struct file * earlier */ gadget = epfile->ffs->gadget; - io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; spin_lock_irq(&epfile->ffs->eps_lock); /* In the meantime, endpoint got disabled or changed. */ @@ -1012,6 +1011,8 @@ static ssize_t ffs_epfile_io(struct file */ if (io_data->read) data_len = usb_ep_align_maybe(gadget, ep->ep, data_len); + + io_data->use_sg = gadget->sg_supported && data_len > PAGE_SIZE; spin_unlock_irq(&epfile->ffs->eps_lock); data = ffs_alloc_buffer(io_data, data_len);