Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp847721ybi; Fri, 12 Jul 2019 05:38:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyrSFygSt6+a3HNsOHl6EOs/Puik9J7l/ljjeuc3nPqpq2lLIU/VxbQMvYHbzFJZ70xH/9y X-Received: by 2002:a17:90a:3247:: with SMTP id k65mr11503029pjb.49.1562935126058; Fri, 12 Jul 2019 05:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562935126; cv=none; d=google.com; s=arc-20160816; b=Skh1urk0QgxNo/FDw9glpHJH883Hkwd8oIxjwluX7ESkNB0woP/r8O+3mhqA0GtozM 5Ug8HGBs6JKSHb4CBSB3fEoTv0SBc9VROobiax+VYv7rmF+yGjHWgXeyodU26+48/+Un RaXFbeU5AykNKcc1U4XeSI7366jfqk+I5uwKa9GIguL4KyJo9ejD71JDZg/G0LPWns+l 2yJasm+gp3esaobEdNs6wXKb/SQqXqS8Qs8sc59CqQdDJ2/hFwsQ75kBfAjopbxImN4Y DCyTvpnTcXDTqJSWaQkuG3CF6JXxcrRs9wK7b86Rwb0MFtsh0z7iKAPMJ/R6VlTMfB/o SHNw== 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=GHx/71ciIxtROEIptV7ZcySC5fmjnJL4TAU7MZQ8/qvdVdtP6qNZeX1IFvquy0mzR2 5WA7xTFMV4xDbnuhKZAXbohkUlbiDsz8iShdT0QLHZqPJCQoxT/dfilbB8H0kUIxEaeG r7r3u51nQ64ptirKt66m/Yzy5/szLZCbOSi38gXpqJZ1ST5xxvQr32juu0v29N0M1CC/ MmJxhpD+Aden8yozMi+sMfi/ET7P1rkvJF/WgjOSh5C1vfJgHOMshDOav3rzs+Q74TTV lb4dGc8JICfUHhvpF+9PtxyI2JU6ZAjhV7TBCxCYeLMwo7tP5uqqnUwhjK2vmUQf4i1d 5viw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1yU10yG2; 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 y15si8074123pfe.133.2019.07.12.05.38.30; Fri, 12 Jul 2019 05:38:46 -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=1yU10yG2; 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 S1729562AbfGLMdD (ORCPT + 99 others); Fri, 12 Jul 2019 08:33:03 -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: 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);