Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2898154pxb; Tue, 24 Aug 2021 10:07:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7G4CeGjDQkPeoEpuo+Gvve6lZ/MaWKbxExTD7H/hgEcU6AUEiqbQf8gQLGhOpToCm9j/N X-Received: by 2002:a05:6402:2889:: with SMTP id eg9mr44811862edb.38.1629824876111; Tue, 24 Aug 2021 10:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629824876; cv=none; d=google.com; s=arc-20160816; b=hxjjCRvWsWXRN1zZnTb8S+Se4NkrOs4a/xQHcjg530eyKEEclmqmeDzXYD8LDzt7bP rT3QqGRcrk0B/ev7UAM1SgaTeTrrBEt2XWxQjIKoB1zMbAMjMLyfJxh3/FVVeh2QpLv/ UAeYznUFvzyEMbFTeYIWR72jC+6WYrR59dFYDTmtfpknGme3sDGLhk/Sl4Lmbd82nKv2 fjJtEK69h5SevZFyN1TfzbnHYQb6zQeTPB8+6BppG9z2jWnaIXte8YA4ruUqtoelJj9H /6vUOjh1Uo+KFsETsoizHKMGF4dgx614heAiw3pWhl97Lu8uQSHbATBkRjf3X9kpEj2s qGvA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eAvZTqvdx/u00HhjtCgM6dKlXG/DmNsIVjx3mdJVUrs=; b=xQeDu5UE7aBWqkD5/4BtI1JbSWogCemyRVNv9lq+GXmR7yScfaVmNP0YCNjud0/+gj eylebhQgTU4tbgYDl2J+nA2XyxY8pWOwusmpCVUbdDvk8MRr53jP4zfwYrkt36KKtpPh RgVOst+7L+M1JEWeu8M/jrvaWT3Ip71AcsNZ7NTZgxZ3WmXlYSaR/M7DbQUiyur5AckW oKdYBKAUGcS6iBXNCC4B2ZlHPme/X95v6ejP7qb4GvNLgWXluJnh88JBvdUEVdymctbz zoE0ok09JlDvXxUE4SIIuocPRu1fST2wPo0lQB6ekYtrc1xiN4jcWGjR7U9lH7zM5crI rqaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kIhUUYli; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si17684339eje.225.2021.08.24.10.07.29; Tue, 24 Aug 2021 10:07:56 -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=@kernel.org header.s=k20201202 header.b=kIhUUYli; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233775AbhHXRGL (ORCPT + 99 others); Tue, 24 Aug 2021 13:06:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:46598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239019AbhHXRDQ (ORCPT ); Tue, 24 Aug 2021 13:03:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 240906138B; Tue, 24 Aug 2021 16:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824361; bh=wH79ToyYDe2xMQpedE9hyjF1u1EBTRwOuFyi+xhOqp0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kIhUUYliM/nZYeYxscntR8nJ5bPQvcHUNSc4A7+6owMTBNol0bHXpVRV6IWLbkAVg 9Q9lSknDk88rpo0IqXvr1l1SUVeDhNz7WsQLcvSPoNdobmpZ8zaumGfK68BVm4fXBZ fB4M3yvFeYME0GdV7YAJJmWf4+IDXjY/Kn+sBBWNocLpuf0idwb7zsG4uQF9hl8M9K 7DUQ5e3X/HqM2dmpnetFuaJ/gWsOk0FEO5Un1nxCegeYOCrw4jDPksNHdTJPUGIi0m RQT8yV9D8M1tSXCYFTJCD+4u1EBTaIqiuYZpQtCj3HtiJm3O2mL40f3++tBrek4YtQ EE623xU9/bxpQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pavel Skripkin , syzbot+efe9aefc31ae1e6f7675@syzkaller.appspotmail.com, Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.10 11/98] media: drivers/media/usb: fix memory leak in zr364xx_probe Date: Tue, 24 Aug 2021 12:57:41 -0400 Message-Id: <20210824165908.709932-12-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165908.709932-1-sashal@kernel.org> References: <20210824165908.709932-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.10.61-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.10.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.10.61-rc1 X-KernelTest-Deadline: 2021-08-26T16:58+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit 9c39be40c0155c43343f53e3a439290c0fec5542 ] syzbot reported memory leak in zr364xx_probe()[1]. The problem was in invalid error handling order. All error conditions rigth after v4l2_ctrl_handler_init() must call v4l2_ctrl_handler_free(). Reported-by: syzbot+efe9aefc31ae1e6f7675@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/zr364xx/zr364xx.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/zr364xx/zr364xx.c b/drivers/media/usb/zr364xx/zr364xx.c index 8636acf2dad0..08b86b22e5e8 100644 --- a/drivers/media/usb/zr364xx/zr364xx.c +++ b/drivers/media/usb/zr364xx/zr364xx.c @@ -1433,7 +1433,7 @@ static int zr364xx_probe(struct usb_interface *intf, if (hdl->error) { err = hdl->error; dev_err(&udev->dev, "couldn't register control\n"); - goto unregister; + goto free_hdlr_and_unreg_dev; } /* save the init method used by this camera */ cam->method = id->driver_info; @@ -1506,7 +1506,7 @@ static int zr364xx_probe(struct usb_interface *intf, if (!cam->read_endpoint) { err = -ENOMEM; dev_err(&intf->dev, "Could not find bulk-in endpoint\n"); - goto unregister; + goto free_hdlr_and_unreg_dev; } /* v4l */ @@ -1518,7 +1518,7 @@ static int zr364xx_probe(struct usb_interface *intf, /* load zr364xx board specific */ err = zr364xx_board_init(cam); if (err) - goto unregister; + goto free_hdlr_and_unreg_dev; err = v4l2_ctrl_handler_setup(hdl); if (err) goto board_uninit; @@ -1536,7 +1536,7 @@ static int zr364xx_probe(struct usb_interface *intf, err = video_register_device(&cam->vdev, VFL_TYPE_VIDEO, -1); if (err) { dev_err(&udev->dev, "video_register_device failed\n"); - goto free_handler; + goto board_uninit; } cam->v4l2_dev.release = zr364xx_release; @@ -1544,11 +1544,10 @@ static int zr364xx_probe(struct usb_interface *intf, video_device_node_name(&cam->vdev)); return 0; -free_handler: - v4l2_ctrl_handler_free(hdl); board_uninit: zr364xx_board_uninit(cam); -unregister: +free_hdlr_and_unreg_dev: + v4l2_ctrl_handler_free(hdl); v4l2_device_unregister(&cam->v4l2_dev); free_cam: kfree(cam); -- 2.30.2