Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp567626pxj; Thu, 20 May 2021 16:26:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzORGQdZULKQ88u6rPnRYG3V75ZBG67e38WH7d2H3Qs/5HIr2ZXA1qQsQUPIHxrfv/ysOAO X-Received: by 2002:a17:907:2148:: with SMTP id rk8mr7156739ejb.270.1621553167919; Thu, 20 May 2021 16:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621553167; cv=none; d=google.com; s=arc-20160816; b=l1GeyNjhnerN8SUjvhKuwcLJkpR6DCXn+VjJCoqv8xHuXH6HeIRtDaV2kzAHVpUK5k sat5jOL/AC59YeNim8yb6FDo12FDsL4oo3aNPC/bsJkilqTwiSmcyjppc2ixe8gI7juj k6tNXsMFR8yrU+r4PH+GqD6NDZvFfPrgsegHbgXxXz/zpY4ldnrMAV8vux2c5+2SFPoN 0RNE3BoVudKyRLkPW+Fk/CKO6/z/2mm5NTro1bG/MZ62y2vWh2hOYzF65ovo+CTKsD96 iv+QfiC22pGdFZKbB/7cbF7GZEtT6Akpla8dibo216zJdA/v/FR1EaD64mke+dJYXSj1 cqtg== 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=n8MQuPRfnTfI4sNiTRdOoify4DRpWi14aWkKsZIORJY=; b=wNlgtIlIyU1NwaNPsHS+qzpXfGSFkUqbBrmDQWGaMRZ7Zr5wwGdiBF8T6RbgznNN9i /ckgkuDXC9XDwQWF78gFL9Wp56ciEHdmrG0oboQXHgLkb+6VPIiE0U7sQqmau6VWGRGw e0Ph8vBEL+f4XWuzzgEez2DI/C15nOFJvAt80dewNLHJcJy7uwCPpl8uOkNConi7sezM VI0P0oCXzmdS3LpkUtMdcCfOrAn5i0gzy4anHL4SOQF98q/7OQ0pOggojt4815k8XWLi +UQ0R6I7aVwq263eIwFUwBjBo/6xcE+imG7AJKLCr/m2MPz9gf0e6o3o8q1Nt9p9Nl1h Y77A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xMeON8p7; 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 b13si3457689edt.321.2021.05.20.16.25.44; Thu, 20 May 2021 16:26:07 -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=xMeON8p7; 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 S241415AbhETLaR (ORCPT + 99 others); Thu, 20 May 2021 07:30:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:56448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240372AbhETLKD (ORCPT ); Thu, 20 May 2021 07:10:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2B9CB61D41; Thu, 20 May 2021 10:06:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505216; bh=E/eIhmQ2iYDShdcXVmEy/i6ztpfOYBecc292FLsv814=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xMeON8p7jkARhcTGnMm0Qzxa9DVbxMY2UW2g7UTt3xqwbLDPEKtLthTCKtT0QE+hQ 7wcf2dGd5BDacoNcQ/P+mk8YG1oo8mtAnb7Ra7Ee8KlYw7C6fY28/p93NuawHttY/D qdD1qRU+u86s71DJfanMi5FkJOwn9/wS6kUmuZVc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , syzbot+3c2be7424cea3b932b0e@syzkaller.appspotmail.com, Sean Young , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.4 033/190] media: dvb-usb: fix memory leak in dvb_usb_adapter_init Date: Thu, 20 May 2021 11:21:37 +0200 Message-Id: <20210520092103.267648884@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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: Pavel Skripkin [ Upstream commit b7cd0da982e3043f2eec7235ac5530cb18d6af1d ] syzbot reported memory leak in dvb-usb. The problem was in invalid error handling in dvb_usb_adapter_init(). for (n = 0; n < d->props.num_adapters; n++) { .... if ((ret = dvb_usb_adapter_stream_init(adap)) || (ret = dvb_usb_adapter_dvb_init(adap, adapter_nrs)) || (ret = dvb_usb_adapter_frontend_init(adap))) { return ret; } ... d->num_adapters_initialized++; ... } In case of error in dvb_usb_adapter_dvb_init() or dvb_usb_adapter_dvb_init() d->num_adapters_initialized won't be incremented, but dvb_usb_adapter_exit() relies on it: for (n = 0; n < d->num_adapters_initialized; n++) So, allocated objects won't be freed. Signed-off-by: Pavel Skripkin Reported-by: syzbot+3c2be7424cea3b932b0e@syzkaller.appspotmail.com Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/dvb-usb/dvb-usb-init.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c index 97a89ef7e4c1..151212168c9f 100644 --- a/drivers/media/usb/dvb-usb/dvb-usb-init.c +++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c @@ -82,11 +82,17 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs) } } - if ((ret = dvb_usb_adapter_stream_init(adap)) || - (ret = dvb_usb_adapter_dvb_init(adap, adapter_nrs)) || - (ret = dvb_usb_adapter_frontend_init(adap))) { + ret = dvb_usb_adapter_stream_init(adap); + if (ret) return ret; - } + + ret = dvb_usb_adapter_dvb_init(adap, adapter_nrs); + if (ret) + goto dvb_init_err; + + ret = dvb_usb_adapter_frontend_init(adap); + if (ret) + goto frontend_init_err; /* use exclusive FE lock if there is multiple shared FEs */ if (adap->fe_adap[1].fe) @@ -106,6 +112,12 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs) } return 0; + +frontend_init_err: + dvb_usb_adapter_dvb_exit(adap); +dvb_init_err: + dvb_usb_adapter_stream_exit(adap); + return ret; } static int dvb_usb_adapter_exit(struct dvb_usb_device *d) -- 2.30.2