Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp413306pxj; Thu, 20 May 2021 12:14:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXxaDQFQTnY7XAjv1f1EROvp4Gci+wfLWSVA3tJVB+OR2On+86kx1rpUzxfvgDIzXHPxvO X-Received: by 2002:a50:fb0f:: with SMTP id d15mr6646276edq.343.1621538066465; Thu, 20 May 2021 12:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621538066; cv=none; d=google.com; s=arc-20160816; b=UDirLoaUqZp2/C4TsL+lYYhZ0MnHQelX8PEyogbJPxKyqDzuY4eSPeuxilX7rbljUV 8zOKottdeGVvq6jCjzS6afz8jCo3tDzPKMjTW4MC0xWj406cPWgDGShZ2bylML5dbcNx yOe8vvBXfmltFvydqXAuXSfWCshSF2qKMsx2WRvC0f3Q+sMKNH5dgvnC9gu/gDubNE7N B2zv0XoCK/hhXh1oQDaaxovtyWSbNCfn5lIdhRadgvhihSGrpSPefQRkMYDNVyy1RS94 ww4kS9qa/32bL4j7SvBNdA/pOvKb1D54xhthi5tESOD4eCnbR1ovbsRK1bk7yZaKkGEH NFkw== 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=a9np/dC4oTKR48tlrGoSHkMCqmFMjZYJ1S2NxK8YXSQ=; b=D9bwtvW15RajMNQz07acBiRRBbb2ILBBwWdaJRfIjJO25fC0AhuF/q8acfWf77Mox4 njkVGyM/JE/wcTvLuDU/2YKTplzxyhPyyFs7hWDkUhvdCnRIDpTyy30brenwF6gDgz0M nt1ku6igJbVtUPMcUj+ZW7zkO4Ue/JG0EaoCiWIugQ2BlRfwhy4pTcrPh78ZZwKjDhY3 Trzo69Ku9oPDdyEmtO61bVqbj5ADJlzaW3qfS9V6DE5nismlxu24EZC3RTz6xAOPgJa+ AVNzIEdD2GoIRdCkmm5l7GjxUMibB9IjZgY2iiQhWb2YqMsPJR9BTdjiULdu6ughGEHU ALSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Nsx17ike; 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 n8si3261815eje.94.2021.05.20.12.14.02; Thu, 20 May 2021 12:14:26 -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=Nsx17ike; 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 S237189AbhETKdE (ORCPT + 99 others); Thu, 20 May 2021 06:33:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:52002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236440AbhETKTf (ORCPT ); Thu, 20 May 2021 06:19:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B5A89619C3; Thu, 20 May 2021 09:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504036; bh=8PUeSK6m8NDiKRs+ov5NRIEpA7ooQ2i5cHoY4/B8N8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nsx17ikeEfWWb0DWhKgCve0uaF70XiKWcP+wh9LiG7etgZJMX9BEoaDu/xKj8qy4v QD5RF5JOF5WxboHW8y3bSAQEj6BQVAIw71XENud5JJ5fnfccJSKsqlU1BMZIOIcwdK o0Jx2bdZjz41iRibQ8xMLDDRYGuryQJkIK0Fx5SA= 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.14 066/323] media: dvb-usb: fix memory leak in dvb_usb_adapter_init Date: Thu, 20 May 2021 11:19:18 +0200 Message-Id: <20210520092122.365609333@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 b3413404f91a..690c1e06fbfa 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