Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2905676pxb; Tue, 24 Aug 2021 10:17:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNIWn1DD4dbaBlKmV8QqHIZroiCZp7QeVgNmyPS2sEaBTNzNzugphNK5wLzgYhrXseRD/Q X-Received: by 2002:a92:cda4:: with SMTP id g4mr28492997ild.236.1629825463816; Tue, 24 Aug 2021 10:17:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629825463; cv=none; d=google.com; s=arc-20160816; b=aJm+ot8xfVOZ78FEbFTKBAqUvLF3YFS9FEKpNsZdrOog12yo2jgmU6nnkO9Ds4GYh4 QfhYSvq5DfpbTj5T0xRyQIiMQUxg7QKFw2zvODGXEMcMkmXlOoH6wL8CZUVDWDdhpkjf jOG4T8JmDHSCEanfUBOIK8tZ5D7376wG7i8QuAIGbRpv8IXjRtl22bGT44LqM1sJrl27 Lw6FMuumyhTqNU7Kls6DtXnTbFKixBPSMLyrUgE64HwfLORQEoz3KKT0wFD5P+6eUAeM QAyW66A2SNa6g1yyuC7tjhe7hzuLXkcsDaoRQlYVcraQWryrLMebozTpg+HnBJWjlgEV Oakw== 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=GSgsjjMy0w9lTD3wpIZzcUyiX8IJt2nv1WZiXfoeiIA=; b=DWqkbHFN3S1B11MPIPZsj4WpzIPhC8iVRBDJRdHTSbvGXMMTo6DeNwHRes/8C6JTyh PXMA3L/kfVd3mrn+5IgqqKtjtaEQt1Pe8ldOUnBoyjREFco9AT1zRb2TqCHQrS1locgy QBxOl2Q2rUvED/E/uw8iSPqlePLrVVKilcFE8neD28bafuhWN0Ra7AHQbTjp5wbNdsnH CHDNBkuH1TtIqiVjHYx71qjcqaCIQQg6DA80H9tqDVj0EJDmCjaOFZB+H+RAjpUN4PPV 3jc2+c8ejWTQ4rBC6i9KOKZzOw7U4GEgo/h8gn/LZU3RM6LYNL17kzB2RMFREM1W1ltl EH0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PwfaL7HD; 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 n123si21005597iof.15.2021.08.24.10.17.31; Tue, 24 Aug 2021 10:17:43 -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=PwfaL7HD; 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 S239973AbhHXRPq (ORCPT + 99 others); Tue, 24 Aug 2021 13:15:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:52078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239744AbhHXRMJ (ORCPT ); Tue, 24 Aug 2021 13:12:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CD65061A57; Tue, 24 Aug 2021 17:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824479; bh=SH2z3W9UdRkceihNUWj1TKuavYYwM8EJO3016Azv254=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PwfaL7HDQVFE0G9G+hitZbnl4t7D++wWRwMfwVegoKvFDtkqkGTo8Ut7K0qJunUqD HCo98nVpXjBmLVQh+nJQ4/PSW14g9TLSrqNuLp1KAIYUpL2V7tQN4YXVzjoyaaakMM k7rfLmfq4Vb1PWmdOlOhgniywzTDBJ0mdsJVbyg16e3E7ZgGcgWz/8IHqf1CvWOzRb IJe5mx9HEG5ttsZLXBWrGZMR9f9IykLhVb+cMWbtNrU6d0+wX/WQaYaqkiwNx3z6um 0FvVW2FI7INa9A+X67JfTPJF2PSMs/zrb4VUGnjSi+E3jn+NfDixjmg7IP7cnomJSg 4XbsYKiEp0jHA== 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.4 11/61] media: drivers/media/usb: fix memory leak in zr364xx_probe Date: Tue, 24 Aug 2021 13:00:16 -0400 Message-Id: <20210824170106.710221-12-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824170106.710221-1-sashal@kernel.org> References: <20210824170106.710221-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.143-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.4.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.4.143-rc1 X-KernelTest-Deadline: 2021-08-26T17:01+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 b3f01de9cf37..25f16ff6dcc7 100644 --- a/drivers/media/usb/zr364xx/zr364xx.c +++ b/drivers/media/usb/zr364xx/zr364xx.c @@ -1436,7 +1436,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; @@ -1509,7 +1509,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 */ @@ -1521,7 +1521,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; @@ -1539,7 +1539,7 @@ static int zr364xx_probe(struct usb_interface *intf, err = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); if (err) { dev_err(&udev->dev, "video_register_device failed\n"); - goto free_handler; + goto board_uninit; } cam->v4l2_dev.release = zr364xx_release; @@ -1547,11 +1547,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