Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp22891pxb; Mon, 13 Sep 2021 11:54:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTMRyVj3HC8g3HT19sga6un28ag4MjcFR7aTk3X7EgNMbGizs4wt2vbhuRgByvxiDuMqwZ X-Received: by 2002:a05:6e02:921:: with SMTP id o1mr5362400ilt.289.1631559277027; Mon, 13 Sep 2021 11:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631559277; cv=none; d=google.com; s=arc-20160816; b=zxRTQjNp/F+nimQDvB4LQ9b9e3SXWetLfBbTE+21+MbhEWJgXdM0zOZwHb2PVy7FWB nOWgSZWbsoxWpnz8khHI1mTAJ0FO02bFYDXPxMt/j6oqw8xOfCKyWvPlPGdBkVxIxvsM 2Zzbbxwv0DZirX+ZgME2NE6qo5G+ozUl6uMdScJGzhDvjQ3QLb4DazCJUAG79WsuHwUM 0XsWd5YdhMD2dGjbyOInsd+I9k2zywC5ifBnnzkAmpR8D/sEyd16hYX2OXNNKqKk5lzD CwMovdn3IZP3jKfP4nYfbrsPeZNpRDy9q/u3LFgfwhw5TLufI69NX5TsfpYTwMUfc9xC 9jnQ== 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:dkim-signature; bh=Oq3OUW2JG970iZ6Ga+MciD7C+fe9sWhoGylbk05VR9Q=; b=uH1r/A7wG9ZJRbINM+GTWSWTEcfb/odeGg0Qow/eVwLXPYTmAs0DBsKgG3TYR+NZkR te9t7hi3MfihY1tDHkvDQ0kAaEURii6y/qy1eOdZ0RIZp36KFChh3tcZCekHrQBoBvSG ZfCJc1jmFUuYf6DVl+noyFXq7JBOuDxNaV9hPFvwexDJabMVN7qu+RLkiVByYTUOIEl5 uk8qUpzIDLzGvLxStMxhmZ89dxERzLvt2N4EEYwG7P2ADGNYk1kv6irtRAt3zYOul7zx w/GIQ1D8yZslaYdPUgcWkImTV2I5Rb8OpI5w7oSPqroGJejSLl4K1LJphOQifQgRvT05 b8LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DsbneIgn; 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=pass (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 p4si9394924ilc.19.2021.09.13.11.54.25; Mon, 13 Sep 2021 11:54:37 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DsbneIgn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242166AbhIMN1p (ORCPT + 99 others); Mon, 13 Sep 2021 09:27:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:46794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241785AbhIMNZr (ORCPT ); Mon, 13 Sep 2021 09:25:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B31D561246; Mon, 13 Sep 2021 13:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539335; bh=3ZjcMKku0QHghHQfWo84FCqjec1aaxpy9utY0WxZBI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DsbneIgnply+bTP4VnrRzyEk/7wcaC4Ic5QQQduOBfBiorMLz/77wjld7PdkWGgla gEFwPvcufda7oBd4Bu5ZPT8rcOiZf02bro8QUAaToFE84YnJR+yONnIUJZCmVi3ZWw EIWnOiqVkxFnn3ASU8Wv5M8izxHz0ZIWBSCIlTTU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Felipe Balbi , Nadezda Lutovinova , Sasha Levin Subject: [PATCH 5.4 098/144] usb: gadget: mv_u3d: request_irq() after initializing UDC Date: Mon, 13 Sep 2021 15:14:39 +0200 Message-Id: <20210913131051.218669063@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@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: Nadezda Lutovinova [ Upstream commit 2af0c5ffadaf9d13eca28409d4238b4e672942d3 ] If IRQ occurs between calling request_irq() and mv_u3d_eps_init(), then null pointer dereference occurs since u3d->eps[] wasn't initialized yet but used in mv_u3d_nuke(). The patch puts registration of the interrupt handler after initializing of neccesery data. Found by Linux Driver Verification project (linuxtesting.org). Fixes: 90fccb529d24 ("usb: gadget: Gadget directory cleanup - group UDC drivers") Acked-by: Felipe Balbi Signed-off-by: Nadezda Lutovinova Link: https://lore.kernel.org/r/20210818141247.4794-1-lutovinova@ispras.ru Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/udc/mv_u3d_core.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c index 35e02a8d0091..bdba3f48c052 100644 --- a/drivers/usb/gadget/udc/mv_u3d_core.c +++ b/drivers/usb/gadget/udc/mv_u3d_core.c @@ -1922,14 +1922,6 @@ static int mv_u3d_probe(struct platform_device *dev) goto err_get_irq; } u3d->irq = r->start; - if (request_irq(u3d->irq, mv_u3d_irq, - IRQF_SHARED, driver_name, u3d)) { - u3d->irq = 0; - dev_err(&dev->dev, "Request irq %d for u3d failed\n", - u3d->irq); - retval = -ENODEV; - goto err_request_irq; - } /* initialize gadget structure */ u3d->gadget.ops = &mv_u3d_ops; /* usb_gadget_ops */ @@ -1942,6 +1934,15 @@ static int mv_u3d_probe(struct platform_device *dev) mv_u3d_eps_init(u3d); + if (request_irq(u3d->irq, mv_u3d_irq, + IRQF_SHARED, driver_name, u3d)) { + u3d->irq = 0; + dev_err(&dev->dev, "Request irq %d for u3d failed\n", + u3d->irq); + retval = -ENODEV; + goto err_request_irq; + } + /* external vbus detection */ if (u3d->vbus) { u3d->clock_gating = 1; @@ -1965,8 +1966,8 @@ static int mv_u3d_probe(struct platform_device *dev) err_unregister: free_irq(u3d->irq, u3d); -err_request_irq: err_get_irq: +err_request_irq: kfree(u3d->status_req); err_alloc_status_req: kfree(u3d->eps); -- 2.30.2