Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319591pxb; Mon, 20 Sep 2021 18:42:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTgqBJemvyAqkPJEZyuyszNFJ4cbiikzpa7u1D5i8+7PecHJ0cUWMrEKGD8GvuFe4I3ZZV X-Received: by 2002:a05:6e02:12c9:: with SMTP id i9mr19279333ilm.20.1632188573335; Mon, 20 Sep 2021 18:42:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188573; cv=none; d=google.com; s=arc-20160816; b=wz4zpobk4rhgUo07dsfb2dBCLNSG399OLw8Epk7GLZz5ZiswI4yk2G5hIh/7I9c6Qb dL1Hx13c77UyTx/yyQyRh58fxbxwZoWBInznV+aVGS5hi5n9Cy/tg2dpYz7UHDKjAUBX hTjSZakkVj+OkbAXsrf7DkXz8iuXCWxey54JCqrhBsXM0O3etcSZaA0hhONDXenqWMDC tLuwSWLPaPw9qzHl5dda8uRgQiasqYQnKcfRPqPw0vG8+nVIpDDGPyf+p8pBfEoMlb7n YRZh1Um6lsGf5JIJSYs4RbR72fCYl/p7FmMA4zIC1sV/JwVambaR3yJz5xVGSEkNjplH 00wg== 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=KyC1FcZAbOPsXiq2FlZmwz68dLNLiAn61UWjqGGr0mo=; b=Cxy8//ZIKryQsZsdrltFYb3I2zphY8kfrV1w5jQTTwEAruBJjEauRLTg+oVUr3pIN6 KVsKLHX09ntK1xQzIGR84AwNs2lzLo1u3pI/u/PnvkTrHvtAqhxxXKG2SYJW8zIs0hOv uWMJyO8GlRzvF6sO6XJfQVZ+M7w8iHjm0BtrgYQloJN/MqeoCcPLTXnwcCmcrg8DYPqm 9TbZ2482bzIo6Jlm/dkCs7anaOWeT3+7fX5D4vctJCdyx1jOmmt8gxjfgYNSN2Tu0si3 1oUlrn+C+looyKrhUB7FIIVXU+x7SwZOJ0iW9guYRJiA6DasS00Pg241ShVKlWVKYiQh nOXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WVkffLGl; 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 k34si2983078jac.46.2021.09.20.18.42.42; Mon, 20 Sep 2021 18:42:53 -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=WVkffLGl; 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 S244435AbhITQvy (ORCPT + 99 others); Mon, 20 Sep 2021 12:51:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:36724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244009AbhITQtB (ORCPT ); Mon, 20 Sep 2021 12:49:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6B2FE6128A; Mon, 20 Sep 2021 16:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156447; bh=M+ZNV6YOK3NY148Oj8APLlRC0NCN0y/NwKiXLgd1ajE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WVkffLGlciXagTEJmzGWdBWWoM14fhUOLITHWD9h6PEDtVXyPiamyQb/D9VUFNxEc gkznTmL2lgQOQiwyxSAAhcmEFPRy899qERNJawze1FEs5vZgnFi9fXkWE4z2K7edoZ 9XBhxSavEDAMMkhmCIeYZ2ayOqirH/Rk67baYmtA= 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 4.4 056/133] usb: gadget: mv_u3d: request_irq() after initializing UDC Date: Mon, 20 Sep 2021 18:42:14 +0200 Message-Id: <20210920163914.480702186@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 dafe74eb9ade..9ee4a2605dea 100644 --- a/drivers/usb/gadget/udc/mv_u3d_core.c +++ b/drivers/usb/gadget/udc/mv_u3d_core.c @@ -1929,14 +1929,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 */ @@ -1949,6 +1941,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; @@ -1972,8 +1973,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