From patchwork Mon Dec 16 17:48:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 11294925 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BED7514B7 for ; Mon, 16 Dec 2019 18:02:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9CEAE207FF for ; Mon, 16 Dec 2019 18:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576519342; bh=a8gQC8OZYPAqcL31XGpixU+cG46ZxnAzjXI3yfM5cqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=tXr8seD9gnvZb+5aGNVgsWEY5F30BAbF5fGnSFy2J+zzi14RnI7bvL9Mpgx9Jr22M UCF5LYlxzyj+pWA1I8jp29He92u8B0OWXAZNKB3VGPzvJW1L1pnCVUkYsem0KLvVbp uJq8b6ZanfdeNOeUCi+TDwlZdrcbn2j+g/dM7ZUc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729324AbfLPSCV (ORCPT ); Mon, 16 Dec 2019 13:02:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:38026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729309AbfLPSCQ (ORCPT ); Mon, 16 Dec 2019 13:02:16 -0500 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 5F83820726; Mon, 16 Dec 2019 18:02:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576519335; bh=a8gQC8OZYPAqcL31XGpixU+cG46ZxnAzjXI3yfM5cqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0Dm7uuuoMkiVvKCbVuPIycPkRfC012zg1k4nztjDEUt6pAgUI4mMObFpsld5C40WP Wqr/DEbj8Cts2WrB0j0US54kjl0gfN7Nx6PfXadusyX+cgpabmINPw4vfRCutzZW+b GaIvjdxUdy/SGlmIQkxxOJM6A4rTovqAO3h0ARwI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wen Yang , Heikki Krogerus , Peter Chen , Hans de Goede , Chunfeng Yun , Suzuki K Poulose , linux-usb@vger.kernel.org Subject: [PATCH 4.19 025/140] usb: roles: fix a potential use after free Date: Mon, 16 Dec 2019 18:48:13 +0100 Message-Id: <20191216174757.050729358@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191216174747.111154704@linuxfoundation.org> References: <20191216174747.111154704@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Wen Yang commit 1848a543191ae32e558bb0a5974ae7c38ebd86fc upstream. Free the sw structure only after we are done using it. This patch just moves the put_device() down a bit to avoid the use after free. Fixes: 5c54fcac9a9d ("usb: roles: Take care of driver module reference counting") Signed-off-by: Wen Yang Reviewed-by: Heikki Krogerus Reviewed-by: Peter Chen Cc: stable Cc: Hans de Goede Cc: Chunfeng Yun Cc: Suzuki K Poulose Cc: linux-usb@vger.kernel.org Cc: linux-kernel@vger.kernel.org Link: https://lore.kernel.org/r/20191124142236.25671-1-wenyang@linux.alibaba.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/roles/class.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -130,8 +130,8 @@ EXPORT_SYMBOL_GPL(usb_role_switch_get); void usb_role_switch_put(struct usb_role_switch *sw) { if (!IS_ERR_OR_NULL(sw)) { - put_device(&sw->dev); module_put(sw->dev.parent->driver->owner); + put_device(&sw->dev); } } EXPORT_SYMBOL_GPL(usb_role_switch_put); From patchwork Mon Dec 16 17:49:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 11295041 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A910109A for ; Mon, 16 Dec 2019 18:37:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 28E2C20CC7 for ; Mon, 16 Dec 2019 18:37:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576521477; bh=UOc/FJlJ+vBa71ybe5UqQhEaD33njVr12Vobl8SZBx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lYahake35cksZqNlC1Rc3njtroBW1s2aHpwrNFcn7vvWldJL78gOkPjDElcnGv828 sEwAyKlyhzdJboLVUPKaL9TgkvolAz9K4zVNpDOb2H5I5nx3xPVffC3M3E4T/EIy9z PmJ18SjqgwotqR7i2PM57/L9OgHx2dIKXDYrI9YE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729654AbfLPSFi (ORCPT ); Mon, 16 Dec 2019 13:05:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:44230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727459AbfLPSFg (ORCPT ); Mon, 16 Dec 2019 13:05:36 -0500 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 AC3202166E; Mon, 16 Dec 2019 18:05:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576519536; bh=UOc/FJlJ+vBa71ybe5UqQhEaD33njVr12Vobl8SZBx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S7G2aWN92uHE3nc3Mja17MYMPPhnCijFoXC8ocjWcZXd2Cmmh0J06CxuEaTcn/5Ho OB2Kqw5NnUmp7pTVELCD+peAO7lSBIlwyiZ6X3ubdq3Iq/jWGIYRhEmwGyHerOB9HH 8NnB7BdzWUB15MzKuJLC9UJNqXwCCCGp+t8APK1o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wen Yang , linux-usb@vger.kernel.org, =?utf-8?q?Heikki_Krogerus=C2=A0?= , Sasha Levin Subject: [PATCH 4.19 107/140] usb: typec: fix use after free in typec_register_port() Date: Mon, 16 Dec 2019 18:49:35 +0100 Message-Id: <20191216174815.842184472@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191216174747.111154704@linuxfoundation.org> References: <20191216174747.111154704@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Wen Yang [ Upstream commit 5c388abefda0d92355714010c0199055c57ab6c7 ] We can't use "port->sw" and/or "port->mux" after it has been freed. Fixes: 23481121c81d ("usb: typec: class: Don't use port parent for getting mux handles") Signed-off-by: Wen Yang Cc: stable Cc: linux-usb@vger.kernel.org Cc: linux-kernel@vger.kernel.org Acked-by: Heikki Krogerus  Link: https://lore.kernel.org/r/20191126140452.14048-1-wenyang@linux.alibaba.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/typec/class.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 00141e05bc724..1916ee1600b47 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1589,14 +1589,16 @@ struct typec_port *typec_register_port(struct device *parent, port->sw = typec_switch_get(&port->dev); if (IS_ERR(port->sw)) { + ret = PTR_ERR(port->sw); put_device(&port->dev); - return ERR_CAST(port->sw); + return ERR_PTR(ret); } port->mux = typec_mux_get(&port->dev, "typec-mux"); if (IS_ERR(port->mux)) { + ret = PTR_ERR(port->mux); put_device(&port->dev); - return ERR_CAST(port->mux); + return ERR_PTR(ret); } ret = device_add(&port->dev);