Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp35467pxu; Thu, 10 Dec 2020 17:27:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6MgerNFfsdI85K5Qt+K01Hn0aEsb4byAD9uxso9cAJqAQTykpfXSqeRaVTkNP+rLuIHnI X-Received: by 2002:a50:e00f:: with SMTP id e15mr9961992edl.210.1607650077922; Thu, 10 Dec 2020 17:27:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607650077; cv=none; d=google.com; s=arc-20160816; b=KQNwdNXKIue0vnr6UQOY6yTnEGObh+r64BjhbFlDNAViAPrgO9eQ04z6oDHm/0rPVV /wBdmL6TCuzPI6D4L1HO3Z4hesqvk/+uEdqFePgXUW9on3v6CqkxvIwc9L/womm4C9RU LxGeUr+Ve7sdPi5QOcy+h8mP6UkY2MoDijgkREmdblKY7W3H6o64KhQUHb4BngL9BFO/ 71rSdMatQTlr/eRGgzOux6TBIKAOTrOdT2Y2CVoRd0Rm6bZ5HVoB6jV61h6X2ex6EYA/ W1zx1FYlufqov5NqyavF6s4gOE/WE/b+IFVH/7Bj1G7lk2rrXoLqP4QEBaIv6oGKA3hY 3N7Q== 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; bh=aU45AD5UIyzkv2Qzda/ixX83fIeHE1Q/IHKR8aJTkn8=; b=oWKT79oVRom8IEl5mpGgSYaKKLIdyLlYkumNgHrhpvmEK1Cxod0lQ+ZSvZYBr+3Zqd 4ncIA+Mjr1BLuZmF9Nnz/4fp9/0Z9Ern+0PrBjTV/r/BEXcMO5zH6cK0UaHdSwgA366u E2CFm8s495CdbVP1ttEjVelkFoxwovY1ojVPb0gY0XJbwtEi1YnypRQDlofUu1wO1vcT fbewNJ31qUmfbvjH42yLItvNBggvD5O8kKfKksBsJZUb52CQi7QtTAwe+p03dNJl8rIE lj+HU3i5WAqRinHRWGkEzYX8CFHsug+dA0cdA2KSPtRCxmWmUUJb8eCkk2camyCnAXfB tyWQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 c12si3957696eja.450.2020.12.10.17.27.21; Thu, 10 Dec 2020 17:27:57 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390436AbgLJOaq (ORCPT + 99 others); Thu, 10 Dec 2020 09:30:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:38072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390265AbgLJOaK (ORCPT ); Thu, 10 Dec 2020 09:30:10 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Chen , Vamsi Krishna Samavedam , Jack Pham Subject: [PATCH 4.9 22/45] usb: gadget: f_fs: Use local copy of descriptors for userspace copy Date: Thu, 10 Dec 2020 15:26:36 +0100 Message-Id: <20201210142603.464476420@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210142602.361598591@linuxfoundation.org> References: <20201210142602.361598591@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: Vamsi Krishna Samavedam commit a4b98a7512f18534ce33a7e98e49115af59ffa00 upstream. The function may be unbound causing the ffs_ep and its descriptors to be freed while userspace is in the middle of an ioctl requesting the same descriptors. Avoid dangling pointer reference by first making a local copy of desctiptors before releasing the spinlock. Fixes: c559a3534109 ("usb: gadget: f_fs: add ioctl returning ep descriptor") Reviewed-by: Peter Chen Signed-off-by: Vamsi Krishna Samavedam Signed-off-by: Jack Pham Cc: stable Link: https://lore.kernel.org/r/20201130203453.28154-1-jackp@codeaurora.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_fs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -1224,7 +1224,7 @@ static long ffs_epfile_ioctl(struct file case FUNCTIONFS_ENDPOINT_DESC: { int desc_idx; - struct usb_endpoint_descriptor *desc; + struct usb_endpoint_descriptor desc1, *desc; switch (epfile->ffs->gadget->speed) { case USB_SPEED_SUPER: @@ -1236,10 +1236,12 @@ static long ffs_epfile_ioctl(struct file default: desc_idx = 0; } + desc = epfile->ep->descs[desc_idx]; + memcpy(&desc1, desc, desc->bLength); spin_unlock_irq(&epfile->ffs->eps_lock); - ret = copy_to_user((void *)value, desc, sizeof(*desc)); + ret = copy_to_user((void *)value, &desc1, desc1.bLength); if (ret) ret = -EFAULT; return ret;