Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2484950pxj; Mon, 10 May 2021 04:13:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZrR2/OWIvdoP61psNaB1adjjWtJBPtRBN+m6cD3LnVAmkTiuJ15tqhlXOeIrEgBQeePj5 X-Received: by 2002:aa7:d0c9:: with SMTP id u9mr28511420edo.43.1620645214927; Mon, 10 May 2021 04:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645214; cv=none; d=google.com; s=arc-20160816; b=PqI8oPId3tOjWr3K6Ibq2wmVUlUwhOkgHzvAUv1vUlcAHYv9EJ9bq6G3JUnSdVdkGS IiEBpTN/8ZI7UmQu+KwXiOUrhMbVALR2bnuZp6vrtF2aKiU0Ns6MnPsMqW8lyq8s7Xo0 PqQjC4DqPsVfVqbbSP5d4JMnOLsDKS2zSFm4O7PiFplI2Oi6NJZNYIh5I+nDyG9aOq7L YxDfckcRqp7wGyKaF+uGlmbAcFcckGBydbHfnb5h+42TFS7zIBc6PG2MdDaSfnH8bIT6 QQTnUgfBYmr18fYjZjKd68m4WrZ93C8vDThOzHE0x1pmdij4lKyOtdiIEywvGJvyqZDF zS1A== 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=kH1fEXm1cSfEiDn8ep8pd3MJdbNOXVeIuJde+nLO33o=; b=fSCx46+cONM7dJM61Ah6M78AiH+NVKRCIPWci1J2oKMlveUa8CLsoavKLbsON38Cbb ssSyvIFuyQQwDbGnHq+YplPY+WrBeqs02pExPc6jBTMXdPeYFdhfegDUcVHPj0ekNGLE 7p12gC8viplx6O0nGLGG2w5q7/yqCJjHo30MvJPj1YoZxfvOmqNAch+Eg4Kmbb9FZ56b D6huvoWCqmbF7K2GedGPiVDPtyJv5iw1LizL1XWw9cPCx9KXVzJHI/7IfNwJBkUhci6/ QlGEBOCqMwPkatk9QI5kv1Q4+B1JnyvbqckW+amD9af69yF9jdVy8OEoo6YexY3X/BZy WKGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="bg+6Fk/U"; 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 y23si12354416edq.482.2021.05.10.04.13.11; Mon, 10 May 2021 04:13:34 -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="bg+6Fk/U"; 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 S237245AbhEJLLq (ORCPT + 99 others); Mon, 10 May 2021 07:11:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:41710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233208AbhEJKtv (ORCPT ); Mon, 10 May 2021 06:49:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CE428619CD; Mon, 10 May 2021 10:38:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643113; bh=MUVpAbIDpHgX4tBtKUQo8bni9gOy8VJ4MiQLiHFiun0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bg+6Fk/Ui2YzCz0VeebQDcDzl8EIMJS15Hf6N4q5tVX85bKX+nnwTGW97OoCr/Dl6 ts+XeODsr+h7sMaRZeNE1odDM5iHA6mV7gBYpqon3JvQER/pyEEqzgTAbX1IhITyCo qdpGPoC7rdk0wNi5UXhFxhZzs3KyI4fx2akRRe3E= 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 5.10 183/299] media: dvb-usb: fix memory leak in dvb_usb_adapter_init Date: Mon, 10 May 2021 12:19:40 +0200 Message-Id: <20210510102011.008455848@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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 c1a7634e27b4..adc8b287326b 100644 --- a/drivers/media/usb/dvb-usb/dvb-usb-init.c +++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c @@ -79,11 +79,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) @@ -103,6 +109,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