Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp281452pxx; Wed, 28 Oct 2020 04:56:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9hl3xwmxsefb+Mgk5RQGPi+BOXlk6ZKcmCAZIGlmB1v4YCoZ5Xoo/p+dFwC2YYExmiBCF X-Received: by 2002:a05:6402:392:: with SMTP id o18mr7413487edv.283.1603886212969; Wed, 28 Oct 2020 04:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603886212; cv=none; d=google.com; s=arc-20160816; b=o/NfXCOecTuyWeQfK+bhzVL6VIrBNaB6IQBB6IPNpDuYU00oBrJ/RTXJ3AXEF/D3gO Lg6YRM2YjBjS205p/RCxyFGUZVjLy9QBK1MKSbU17Kdq4MhbZZ/lRDjXEx9uY4Hlsa8f 0BOqzJhVo02VJz1jaOkW3ftO3Ull38H119mdTbhFyDv8pvQAuUEN6cP2noInu/xmNCAi ZJKMjuR/epfLbooM+j9LnLnJT8cbGc5Wa1poKCw+NclbP9GI59QRET8R3BQkx0Jqu3uB rez2iD/fmO2eugZ3HCAZpBWT651/O5paVYAWlT70ikQHZhDIWDv7N3Z5vCEHDYzybSfC xIig== 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=w+RNmlDsouvPnYjekIr8TDM2zSQPjXuB9/sCM+UXxYM=; b=BSK4Lc6SOQ0dH9eOSLPLy+4gmFDC+DS8/sYM5fwq85Z7xOyxouJ6zu1CbHWWBHnpoo j81/YHh07a24LcDGtBKZiti1svuHTfkZVOBhiSL4p+fEDLVWapITQq6FbvXp23ZOnEQb UHNCc5gDW6qJ7Y26tDT5csoNuM2gC4v6H7Onw0kN/WatQ8+ny/0L03aJ0nUaORFwm8fC ArU5opnF1b2ZBApjKYpzPqHLP3AOaaKGI48slmK3MTGLDzJnEJ7CdKlCd4gvAa2mLu8K qXYVCOHPwZFNENyvdT+Yt47aZ8/qlDgchuKtLixjoSLfcgflNvOc4LiL0L51ArEAk10U 6agA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="eywQ9O/V"; 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=fail (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 z8si2802677eju.267.2020.10.28.04.56.30; Wed, 28 Oct 2020 04:56:52 -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=default header.b="eywQ9O/V"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1794862AbgJ0PN7 (ORCPT + 99 others); Tue, 27 Oct 2020 11:13:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:42866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755003AbgJ0PHx (ORCPT ); Tue, 27 Oct 2020 11:07:53 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1A9A6206F4; Tue, 27 Oct 2020 15:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811272; bh=We996f3Yt0RlMfvEgD/QJQy46NEviZymVLgf3GEBbvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eywQ9O/VxuRbbGF59zHM0s4GGzOR8JpJynn4nYATPcPQJ/wAT0ESj5f+CLyVgyjya eUVTHuNMxxhFDV8IMndJGyJCoYJunAGMJWpcGhXt5eBCX8PxSi2FmZdnq1tb440Ti1 KHBp5HwCRr+2M9NzT7XwVzv63dgWvD00H2zdmLL0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Boichat , Mathieu Poirier , Bjorn Andersson , Sasha Levin Subject: [PATCH 5.8 434/633] rpmsg: Avoid double-free in mtk_rpmsg_register_device Date: Tue, 27 Oct 2020 14:52:57 +0100 Message-Id: <20201027135543.087484945@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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: Nicolas Boichat [ Upstream commit 231331b2dbd71487159a0400d9ffd967eb0d0e08 ] If rpmsg_register_device fails, it will call mtk_rpmsg_release_device which already frees mdev. Fixes: 7017996951fd ("rpmsg: add rpmsg support for mt8183 SCP.") Signed-off-by: Nicolas Boichat Reviewed-by: Mathieu Poirier Link: https://lore.kernel.org/r/20200903080547.v3.1.I56cf27cd59f4013bd074dc622c8b8248b034a4cc@changeid Signed-off-by: Bjorn Andersson Signed-off-by: Sasha Levin --- drivers/rpmsg/mtk_rpmsg.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/rpmsg/mtk_rpmsg.c b/drivers/rpmsg/mtk_rpmsg.c index 83f2b8804ee98..96a17ec291401 100644 --- a/drivers/rpmsg/mtk_rpmsg.c +++ b/drivers/rpmsg/mtk_rpmsg.c @@ -200,7 +200,6 @@ static int mtk_rpmsg_register_device(struct mtk_rpmsg_rproc_subdev *mtk_subdev, struct rpmsg_device *rpdev; struct mtk_rpmsg_device *mdev; struct platform_device *pdev = mtk_subdev->pdev; - int ret; mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); if (!mdev) @@ -219,13 +218,7 @@ static int mtk_rpmsg_register_device(struct mtk_rpmsg_rproc_subdev *mtk_subdev, rpdev->dev.parent = &pdev->dev; rpdev->dev.release = mtk_rpmsg_release_device; - ret = rpmsg_register_device(rpdev); - if (ret) { - kfree(mdev); - return ret; - } - - return 0; + return rpmsg_register_device(rpdev); } static void mtk_register_device_work_function(struct work_struct *register_work) -- 2.25.1