From patchwork Tue Jun 30 07:42:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunfeng Yun X-Patchwork-Id: 11633407 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 F3302138C for ; Tue, 30 Jun 2020 07:43:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D955F2081A for ; Tue, 30 Jun 2020 07:43:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="QvcLyBiH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731159AbgF3HnI (ORCPT ); Tue, 30 Jun 2020 03:43:08 -0400 Received: from mailgw02.mediatek.com ([1.203.163.81]:3025 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731148AbgF3HnI (ORCPT ); Tue, 30 Jun 2020 03:43:08 -0400 X-UUID: 204592bd81da417395f4e1d8f98ebfbf-20200630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=UdlqnIpqX91+qcJu2d7pulF4nEY7A/HDqmQfaO6yNK4=; b=QvcLyBiHAc7o4RfjtJxOqKNe3OW7yML7zkp1ea/tBGkaQ9mFcmwI5dBhOF6HY5Kj4xz9iduxPaNEbbjqCA07CNZy6CkOMa7PS/6u+Vu27inL0ab7hNhDN+1uGx5/fU/pYANHg2gSLUxJBqFSNpmBfQxJ+AKxFUfzcsUomtl6JQs=; X-UUID: 204592bd81da417395f4e1d8f98ebfbf-20200630 Received: from mtkcas35.mediatek.inc [(172.27.4.253)] by mailgw02.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLS) with ESMTP id 1196866331; Tue, 30 Jun 2020 15:43:00 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by MTKMBS31DR.mediatek.inc (172.27.6.102) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 30 Jun 2020 15:42:58 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 30 Jun 2020 15:42:58 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Felipe Balbi CC: Matthias Brugger , Markus Elfring , Chunfeng Yun , , , , Subject: [V2 PATCH] usb: mtu3: fix NULL pointer dereference Date: Tue, 30 Jun 2020 15:42:22 +0800 Message-ID: <1593502942-24455-1-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty MIME-Version: 1.0 X-TM-SNTS-SMTP: BBCAD5F173D4D802F40271206CF74BA46974853C7E2A6E35343B12D1811A5EB22000:8 X-MTK: N Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Some pointers are dereferenced before successful checks. Reported-by: Markus Elfring Signed-off-by: Chunfeng Yun --- v2: nothing changed, but abandon another patch --- drivers/usb/mtu3/mtu3_gadget.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c index f93732e..1689ca8 100644 --- a/drivers/usb/mtu3/mtu3_gadget.c +++ b/drivers/usb/mtu3/mtu3_gadget.c @@ -332,14 +332,21 @@ static int mtu3_gadget_queue(struct usb_ep *ep, static int mtu3_gadget_dequeue(struct usb_ep *ep, struct usb_request *req) { - struct mtu3_ep *mep = to_mtu3_ep(ep); - struct mtu3_request *mreq = to_mtu3_request(req); + struct mtu3_ep *mep; + struct mtu3_request *mreq; struct mtu3_request *r; + struct mtu3 *mtu; unsigned long flags; int ret = 0; - struct mtu3 *mtu = mep->mtu; - if (!ep || !req || mreq->mep != mep) + if (!ep || !req) + return -EINVAL; + + mep = to_mtu3_ep(ep); + mtu = mep->mtu; + + mreq = to_mtu3_request(req); + if (mreq->mep != mep) return -EINVAL; dev_dbg(mtu->dev, "%s : req=%p\n", __func__, req); @@ -373,8 +380,8 @@ static int mtu3_gadget_dequeue(struct usb_ep *ep, struct usb_request *req) */ static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value) { - struct mtu3_ep *mep = to_mtu3_ep(ep); - struct mtu3 *mtu = mep->mtu; + struct mtu3_ep *mep; + struct mtu3 *mtu; struct mtu3_request *mreq; unsigned long flags; int ret = 0; @@ -382,6 +389,9 @@ static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value) if (!ep) return -EINVAL; + mep = to_mtu3_ep(ep); + mtu = mep->mtu; + dev_dbg(mtu->dev, "%s : %s...", __func__, ep->name); spin_lock_irqsave(&mtu->lock, flags); @@ -422,11 +432,12 @@ static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value) /* Sets the halt feature with the clear requests ignored */ static int mtu3_gadget_ep_set_wedge(struct usb_ep *ep) { - struct mtu3_ep *mep = to_mtu3_ep(ep); + struct mtu3_ep *mep; if (!ep) return -EINVAL; + mep = to_mtu3_ep(ep); mep->wedged = 1; return usb_ep_set_halt(ep);