Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp100596pxb; Mon, 13 Sep 2021 14:06:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA0TfvasExJi4ghjDAUxZHMb+ZHPOtIe/hrM88iBSvNsGfFCI/LM60k73oLIeu5RkT9pQ2 X-Received: by 2002:a05:6638:14cd:: with SMTP id l13mr1399776jak.90.1631567182296; Mon, 13 Sep 2021 14:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631567182; cv=none; d=google.com; s=arc-20160816; b=IRc5TXhf94EM72hm4VfZWFl+doI+rvJswWc0mHKKkWA9Hs1+dgFyFPBym+gNfHqi3J mlpX1kn8+rI0HRWuKi3h2C0GgStkCUVr7GOmNtlJM6Eb3T3Nh/T+DsASCeZ+5hkWo3kB rgyN0mcjSXmUjAW3lOXH3PljAwSletGhSOYxf/ZKlwYME23j52Iif/tKWWnLjzz1xiL9 1AQMw7nufpL0OYO2iOQHG2BJTz6/T5UKdAdnkljohvzOIvxUJa27EwoJ0hzAsbgqC2IN CGN6T4EwgzAqeUOfoKJNCibHmzHEx0+pRRo2Y2KWnXn6UimD66l3YqICVuq897zvUP+D gxtw== 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=PSNL1pnnBLv49qwwLi9w5S6sv0PuhHlMU4oQPkQeGzM=; b=VqYYod/LHujtauuapr2cwSfRRpQ4wKx+7ZIPQBHTlLzs5XfVkUqeLLamvccg7MqdN7 /Ga+6Lcir2PJ52ZZiTxZb55xXP8qXIuPkQgIcTj4UTh0WkGhab4bG4MmScbEDiDHb5G9 Css7myJoEcfoZw7it6O7YRx7BnbewHh1uEz8hMtFPfR6H9X7yqeZS3vzF6u2OSI/9PAR 8i/l4PkShWA/Ol/rXo5cydpETK2WfGytovTnHe5vYzr35L4yS+/7cmpCd/aZ56eCjH2i hBIw+9f5ikuqpCX3LxwM3nrpKFYhfZT3bMJ9XsGbGWiIAfHxiKD6hhloDenyzLcP1Ptn cimQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E3joosR0; 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 v189si7091297iof.75.2021.09.13.14.06.10; Mon, 13 Sep 2021 14:06:22 -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=E3joosR0; 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 S244696AbhIMNtq (ORCPT + 99 others); Mon, 13 Sep 2021 09:49:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:46618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244289AbhIMNpc (ORCPT ); Mon, 13 Sep 2021 09:45:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E76E60249; Mon, 13 Sep 2021 13:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539896; bh=dD3fqUeojFwl4DrUD/xsbfGqy5wqRmYiptQoXo5SqX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E3joosR0ih5GpxRRIqN4rqsndJPKEh2LKQO9op0a53O+V9uvE+HNdN/TqsDeA2x5w NypCbyz70dGIBOkwImsZi/nhLaqI7plA1izompvqQPOyp/Z6sQgaPp4pcWOJvNB/Ck hRqP3rssNlmQLjglGZ/KbXgUb0K6zgBd5QoM3PiE= 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.10 172/236] usb: gadget: mv_u3d: request_irq() after initializing UDC Date: Mon, 13 Sep 2021 15:14:37 +0200 Message-Id: <20210913131106.226238437@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@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 5486f5a70868..0db97fecf99e 100644 --- a/drivers/usb/gadget/udc/mv_u3d_core.c +++ b/drivers/usb/gadget/udc/mv_u3d_core.c @@ -1921,14 +1921,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 */ @@ -1941,6 +1933,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; @@ -1964,8 +1965,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