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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,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 18E66C742B9 for ; Fri, 12 Jul 2019 12:36:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D7D7B20645 for ; Fri, 12 Jul 2019 12:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934977; bh=bOSHJRD+yncBX5fw/6Yk1AQF+h2Hxgw71ox8mXIVFeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CtIarcvEd8XkN38fVV/2MUm+1QWtEdrkOumdetdfD/w35lBFSp+Cc3CGtAOdE6hlV NWvpHDZsEbDHmesZk5TYxRcQwTyz65eBg3ECVXmcQ6daoK83Y3xlvLiYlG07Cd0Sjb 4VRhisiuq8AY14qO4+1XGEChTQixOD7JvB6WLtI0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728725AbfGLMdC (ORCPT ); Fri, 12 Jul 2019 08:33:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:51736 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729294AbfGLMdB (ORCPT ); Fri, 12 Jul 2019 08:33:01 -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 92B2F21019; Fri, 12 Jul 2019 12:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934780; bh=bOSHJRD+yncBX5fw/6Yk1AQF+h2Hxgw71ox8mXIVFeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1yU10yG2wMrIoKlQfNOczgrTiAVz6CZJ9AcUDK7LTJ1YuSe1ZUnfYMx7LM2UJ6KFc kMbXbmJadZ6iUpOkD0rcNYVP3IUxGdH0q5Lho5968X12oDtjkMiB2jfJe1GY8YsPUz cpsdElbtOMopR69qdtf6Q4igNJ9R/ZeE7zjU69Lc= 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.2 28/61] usb: gadget: f_fs: data_len used before properly set Date: Fri, 12 Jul 2019 14:19:41 +0200 Message-Id: <20190712121622.138400980@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121620.632595223@linuxfoundation.org> References: <20190712121620.632595223@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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);