Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1797327ybc; Sun, 24 Nov 2019 06:24:37 -0800 (PST) X-Google-Smtp-Source: APXvYqyOwnPxvyKrx4KzYNasgAPWnXIXhn43L32ZP9DWTG48lcduMTUvfo8nL/h2xgM36cpDHzeC X-Received: by 2002:a50:fb85:: with SMTP id e5mr12795597edq.274.1574605477681; Sun, 24 Nov 2019 06:24:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574605477; cv=none; d=google.com; s=arc-20160816; b=ATkKT/b9lzll3MGQ39yRpMk7D9uyWi1v2/u7r8xNN74He/HRJQ7kBPnQoqoYyneCbf POAQbnZcOkxlywx7SYFgupAiJfOysGiQteMZL7iNleBLFbPZAzMTQbkDE2Y4sHCFYbe8 lO6YBPJCJIjzn3QlCfgqKT9qVbxGlM3vVS2kumnREtPNGBoDOl0NnzJixx8R5Lrkc60x S7Odf8Ss6+6BRbmNJAHWjmbaItIr0K8lChLi9tgWnV3P7H+7HQGyiDp+e4BY0kFCfugB Pb735L/NGWN1e9PQ25gWouhH4+eH/oYMKFo5UxN+MFYxFgYq1ZojdW9n7f2LLRRkyKZ2 zURw== 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 :message-id:date:subject:cc:to:from; bh=U8uonuKAPYyg8LgL4Bt7ANId1dMkVETlOXaSubnbQis=; b=szMLV0MChLJjOQeeHN2whSMso86QP9uU1A7kUZJYg6ScTdYNZ5vfBPdjrqRPNPKcfn r5KwUNtpdc/g8xNXdgLqCvVq74AjV+xUE79Zp7N8Qr0bMCPepTZHXCwhLlwzlyIRF+nT xjMZotAoQCQICmpwFvPf/lOrsHZhrr9XlH27ZH30MnNtwiJGVQURVb6V50LDOLuFx+ce DngQM/RWNnMKRaISBa+OHoNYuaevtYCxn2IF2mLXX7Crly0Xyb8DvAX9uzpmW63MY2n3 vFHeYKekah7wv8sFfTatshdmh0B7W2HLx0KfJow0Km6/tux2aei+9ZUD16zaVe5ke2CM um8Q== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bo21si2910601edb.137.2019.11.24.06.24.10; Sun, 24 Nov 2019 06:24:37 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726975AbfKXOXM (ORCPT + 99 others); Sun, 24 Nov 2019 09:23:12 -0500 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:40576 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726779AbfKXOXM (ORCPT ); Sun, 24 Nov 2019 09:23:12 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=wenyang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0Tiwhm23_1574605381; Received: from localhost(mailfrom:wenyang@linux.alibaba.com fp:SMTPD_---0Tiwhm23_1574605381) by smtp.aliyun-inc.com(127.0.0.1); Sun, 24 Nov 2019 22:23:09 +0800 From: Wen Yang To: Greg Kroah-Hartman , Heikki Krogerus Cc: Wen Yang , Hans de Goede , Chunfeng Yun , Suzuki K Poulose , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usb: roles: fix a potential use after free Date: Sun, 24 Nov 2019 22:22:36 +0800 Message-Id: <20191124142236.25671-1-wenyang@linux.alibaba.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Heikki Krogerus Cc: Hans de Goede Cc: Greg Kroah-Hartman Cc: Chunfeng Yun Cc: Suzuki K Poulose Cc: linux-usb@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/usb/roles/class.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index 8273126..63a00ff 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -169,8 +169,8 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode) 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); -- 1.8.3.1