Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3344464pxv; Sun, 4 Jul 2021 16:07:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwu8ydK9GfVESXLvleFHaakEBPG//qm83GoTqoQrjvEGVgKYsR91FC/G9zUh0q/tF2mgPkI X-Received: by 2002:a5d:889a:: with SMTP id d26mr6428199ioo.14.1625440040957; Sun, 04 Jul 2021 16:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440040; cv=none; d=google.com; s=arc-20160816; b=roY7uEBaOcV15M6gzV+izNs5vuu/C7P/BKryIb7MNvK6R8ucFpAE1ajLV9Uq5VWn19 Hmhk/KUHbavQkrhSHHqcxDFxkoxyrWq7ExwP04JDy4pwOuwgAI1ZVgkG6Cgb0r36nNvB rEi7T323839egBGmfBhSpZLiUIBvMFHWRffV9anGDwvVgBPqZHb7RYk0J/O31+Ppxdvz KwOFOVqDF4b8oZr84ZiHKtxVYAO298g01TPNia/h1E3yMlSt8xyL+D+UH220TCLHOEWf 7HUo5bqkUiJ3anTWkJYIpEuKy0pD3u4qN9vVX4H2gC4AGtRkzaYyvXaayEB8vhfU98eJ Iqng== 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=43QhZVyIdQA9gPSELxI9V1smJevvX+b6Obyj2csIljA=; b=oO9epEyDD7k1wUbEOrmursqtsl6Pz9QvBvYlX9zP3H75fVd9ZRGxd9NcnMOqcVUeS1 nYmcof562viQOhoAsvN86w7ep7vibnNUt0fZTxKQmm9q7d3eOeRwsaCYPPgEfSZdWEpY O+ixZL0WGXuqJRepwbp2k26YOYESJVM8nISKWxcyTew5oewfTPhxiwv6keRGleZfHu/M W6m6AyqQ4bHNUBMOynEOt8CPJ6X0512uEat8nu3dvS2TOatO+T3ULYXcXubCWKYXQWEh RXZDycUvuyfYnFCF/2T9VXUO8a0GRtZNnYX8cs7egjD04Qfl9zSOPD2PQgDgvOBKf65p 4f6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bxUxEWfH; 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 y6si12113400jai.101.2021.07.04.16.07.09; Sun, 04 Jul 2021 16:07:20 -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=bxUxEWfH; 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 S231407AbhGDXIp (ORCPT + 99 others); Sun, 4 Jul 2021 19:08:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:46816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbhGDXIG (ORCPT ); Sun, 4 Jul 2021 19:08:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A2BEC61958; Sun, 4 Jul 2021 23:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439929; bh=lJ3hh8R41P8DiijbBEOO6KYz41OVlnc6F8l5msauMoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bxUxEWfHaNARcDRTpbbju8O7cUDJRpg8+zzWq3KLLhDoMwQcrTd7CLJgV+7HIu4io aUKQWIVC7FX5qZPFgDxwy3+CxqSXtDj7/cnSYNe+4AKJb3oX/f2rrPpYG4MdEQpuQB vE8X9cF29iyQaTPa30AHC4v7PHKTkpEOYKQIeeAULqRSZjZCUZc9PKRdcFOaXtB8vu jlrus60jcdpv0B9KD79Llmbb/ZYh/iLPfXzcVKqh7JhBJeyiyvHWRPJxGcsdA5T5wy lQ2dbvwibXqNxl/Yi+bu5GltZSSdcOWSNgrLt7LhtalHnlXsNPCOSM4v49Ck+mlhQt f3QDkQo2RbjZQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dongliang Mu , syzbot+e1de8986786b3722050e@syzkaller.appspotmail.com, Sean Young , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.13 50/85] media: dvd_usb: memory leak in cinergyt2_fe_attach Date: Sun, 4 Jul 2021 19:03:45 -0400 Message-Id: <20210704230420.1488358-50-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu [ Upstream commit 9ad1efee086e0e913914fa2b2173efb830bad68c ] When the driver fails to talk with the hardware with dvb_usb_generic_rw, it will return an error to dvb_usb_adapter_frontend_init. However, the driver forgets to free the resource (e.g., struct cinergyt2_fe_state), which leads to a memory leak. Fix this by freeing struct cinergyt2_fe_state when dvb_usb_generic_rw fails in cinergyt2_frontend_attach. backtrace: [<0000000056e17b1a>] kmalloc include/linux/slab.h:552 [inline] [<0000000056e17b1a>] kzalloc include/linux/slab.h:682 [inline] [<0000000056e17b1a>] cinergyt2_fe_attach+0x21/0x80 drivers/media/usb/dvb-usb/cinergyT2-fe.c:271 [<00000000ae0b1711>] cinergyt2_frontend_attach+0x21/0x70 drivers/media/usb/dvb-usb/cinergyT2-core.c:74 [<00000000d0254861>] dvb_usb_adapter_frontend_init+0x11b/0x1b0 drivers/media/usb/dvb-usb/dvb-usb-dvb.c:290 [<0000000002e08ac6>] dvb_usb_adapter_init drivers/media/usb/dvb-usb/dvb-usb-init.c:84 [inline] [<0000000002e08ac6>] dvb_usb_init drivers/media/usb/dvb-usb/dvb-usb-init.c:173 [inline] [<0000000002e08ac6>] dvb_usb_device_init.cold+0x4d0/0x6ae drivers/media/usb/dvb-usb/dvb-usb-init.c:287 Reported-by: syzbot+e1de8986786b3722050e@syzkaller.appspotmail.com Signed-off-by: Dongliang Mu Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/dvb-usb/cinergyT2-core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c index 969a7ec71dff..4116ba5c45fc 100644 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c @@ -78,6 +78,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap) ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 3, 0); if (ret < 0) { + if (adap->fe_adap[0].fe) + adap->fe_adap[0].fe->ops.release(adap->fe_adap[0].fe); deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep state info\n"); } mutex_unlock(&d->data_mutex); -- 2.30.2