Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp504045pxb; Wed, 18 Aug 2021 07:20:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0/H6ITs7vVaq6fGpcbwZnDYONkSAR2qhU6GCSOlmPkszb/pw+6sdCJf5R+ZBs44Ty2Wnm X-Received: by 2002:a05:6638:419a:: with SMTP id az26mr8117038jab.70.1629296433051; Wed, 18 Aug 2021 07:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629296433; cv=none; d=google.com; s=arc-20160816; b=jiOF/LxlyVqWjTOVJYvKqwCEWQWw7j3xgOI6QBzVHZQ+Rx88t9v9PZioaSeYCL7LZh g+qbddbdeKZYYOHLBQiSxv5pZrCXtetvnUB2f7S3QRwIPvzTn2b5tnqqfyQRWtZoWnw9 TJnVWohZmK1XXfu0rb4Io01b92JR5vozs/6YT5xM845iZpU9def4oq/gL4UuvBt7+WNN UITfrbhu0PF1qDfAOB5rS6+mgmuChkUHDIaixwz4SqKBG4X4KT9FPTWAi5+igWfUOqLE d2OeBEKN+XuRKcMxqBe73V5hEdfO1FMreXhIsZsYxjli9EMjl0cGqDjvwBALiPd6mfFd wfZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:message-id:date:subject:cc:to:from; bh=pEz6D6T7LljhdkS4sCY+fdrqo7pEuwOnPi3Mjr4z3Fk=; b=md/W3KXI4eiuFOEwOnqkFF3Cw/anwdwjfzzpHcnOM9Y2T/aCHqS1qcFrsC512x8IZf 0FqdA6uuWUOpgXIotDPWm7igy/DzdGXGIsl4ICO+dpyJng/eFy7wHJQB80lfA701YiSM zYyXoCsy4a9hArkLKF0qMyrscKXWkHeaNSoG+qHiT4m/o5yes58WSAmyoAeVCyEFGTn2 Is9HMM4F5nTyu5BMcQDm34YoRf45SBlE45i1vF8LiuOiJvIBP6YrxjCVAc/YiB5Hypz4 cRkGRhcdiLPj865G/tv//bZhEazRk1evRyFADuR7M0s4XYL20N8mw5KpircCTf5daVBo F28Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si7263623iog.43.2021.08.18.07.20.20; Wed, 18 Aug 2021 07:20:33 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239011AbhHROTC (ORCPT + 99 others); Wed, 18 Aug 2021 10:19:02 -0400 Received: from mail.ispras.ru ([83.149.199.84]:35934 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239578AbhHRONv (ORCPT ); Wed, 18 Aug 2021 10:13:51 -0400 Received: from kleverstation.intra.ispras.ru (unknown [10.10.2.220]) by mail.ispras.ru (Postfix) with ESMTPS id 0865440755CA; Wed, 18 Aug 2021 14:13:15 +0000 (UTC) From: Nadezda Lutovinova To: Felipe Balbi Cc: Nadezda Lutovinova , Greg Kroah-Hartman , Johan Hovold , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org, stable@vger.kernel.org Subject: [PATCH v2] usb: gadget: mv_u3d: request_irq() after initializing UDC Date: Wed, 18 Aug 2021 17:12:47 +0300 Message-Id: <20210818141247.4794-1-lutovinova@ispras.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <87mtpegak8.fsf@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Signed-off-by: Nadezda Lutovinova --- v2: fix subject and add a stable tag --- 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 ce3d7a3eb7e3..a1057ddfbda3 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.17.1