Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp848559pxb; Wed, 6 Apr 2022 01:50:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXi+DJy5Cdge+RtPUUSnJfEtizOagPwskFwz/7Waw0upxZ1G3vcAbQCrujPwKt6U3tOHui X-Received: by 2002:a17:902:7297:b0:156:46bc:4b7 with SMTP id d23-20020a170902729700b0015646bc04b7mr7648920pll.77.1649235012536; Wed, 06 Apr 2022 01:50:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649235012; cv=none; d=google.com; s=arc-20160816; b=qUhVf+TCavbw3+WD233yl0TxfNbOXqghKNiTEN02FBk2N76kWFfcUa4zVDL2QK8Tbf /L1xjQajA1qnRYtWv2aDKDrMc4c8fN/42NLmXgvt7NVJwXGtzk5X82zPHBxCLl7eYn7b 1i/Jr0R96RRf92C1I9KZ8oqeV+pfF2Q7+10s73cAehmMXegTNoJpWt5UatnhCbUL6zZa sCDpFctVyah2BuR6r/c6wNsYp3emunwya0pJwScnjMk/4AiQMIR2HrmIghBX99LO0tOu KjvaPJrmATINcwTrXU+W26kEGyBs+0vYaaPJRENc4CdNegpTBv/LG6dqkHhkk4kV6foW kU7A== 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=3zIF2sCix7VY2oCxO2zizVToV9QWu/LQUScsPri4ybI=; b=Bx88nYqZsNfWNOtP8kHujU8RTnD0iIQVVP9B6epULkSxLT2oH4BaeNmNVxDr83m/8w OzpHE2WexxGk6rvgboHajX6uMd0rQFeuyPWCpCU8LwM/XxBeEwcxmdOg3S33BsIPI8W8 1wAxPIDa/sgNqzPZYt0GynsaUy8V0sZ7vgta09hf+E/DtO86MgG6YC9g1awwOQfJSTiJ HaMf/LXsKN1Qp+5uYoCoso+RnzTpj8IeSeI0cshl7NgkINFXuhJOn+00Bzh6gMSURYw/ NvbAl/ykWoQFprgLdOIF93qbwwzgAYkhKsgoRMRj5hg9fB/q6h1sh+Mf4uQ72YBpaFgN b//g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DUEuDu08; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b2-20020a170902d88200b00153b2d165e4si15026881plz.492.2022.04.06.01.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 01:50:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DUEuDu08; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ADBD558F739; Wed, 6 Apr 2022 01:34:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1836867AbiDFAk0 (ORCPT + 99 others); Tue, 5 Apr 2022 20:40:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349470AbiDEJtz (ORCPT ); Tue, 5 Apr 2022 05:49:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B0D0FD35; Tue, 5 Apr 2022 02:46:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3AE92B817D3; Tue, 5 Apr 2022 09:46:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87C44C385A1; Tue, 5 Apr 2022 09:46:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152010; bh=MgDDT8VuQWca49TghJ4tLzY7YNfYN4Yv/TzRySXi/dQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DUEuDu082wq8XyJQUUOtiHcfzvuvSJ0MPe7ULIL/Da1w+UzpL0iDLyBil6bFNT+EM N51JMpQr9x5thJ8MBhdg1flv/okqvTyPczTcts6k7NkruAkd5YBkAm/K1m8PKciQtM uzvWxGDE4WuokTUL0/LdBUJ+2t5tIGUVK1Zb4JGI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guenter Roeck , Christophe JAILLET , Sasha Levin Subject: [PATCH 5.15 584/913] fsi: Aspeed: Fix a potential double free Date: Tue, 5 Apr 2022 09:27:26 +0200 Message-Id: <20220405070357.350200146@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET [ Upstream commit 83ba7e895debc529803a7a258653f2fe9bf3bf40 ] A struct device can never be devm_alloc()'ed. Here, it is embedded in "struct fsi_master", and "struct fsi_master" is embedded in "struct fsi_master_aspeed". Since "struct device" is embedded, the data structure embedding it must be released with the release function, as is already done here. So use kzalloc() instead of devm_kzalloc() when allocating "aspeed" and update all error handling branches accordingly. This prevent a potential double free(). This also fix another issue if opb_readl() fails. Instead of a direct return, it now jumps in the error handling path. Fixes: 606397d67f41 ("fsi: Add ast2600 master driver") Suggested-by: Greg KH Suggested-by: Guenter Roeck Reviewed-by: Guenter Roeck Signed-off-by: Christophe JAILLET Link: https://lore.kernel.org/r/2c123f8b0a40dc1a061fae982169fe030b4f47e6.1641765339.git.christophe.jaillet@wanadoo.fr Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/fsi/fsi-master-aspeed.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/fsi/fsi-master-aspeed.c b/drivers/fsi/fsi-master-aspeed.c index 8606e55c1721..0bed2fab8055 100644 --- a/drivers/fsi/fsi-master-aspeed.c +++ b/drivers/fsi/fsi-master-aspeed.c @@ -542,25 +542,28 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev) return rc; } - aspeed = devm_kzalloc(&pdev->dev, sizeof(*aspeed), GFP_KERNEL); + aspeed = kzalloc(sizeof(*aspeed), GFP_KERNEL); if (!aspeed) return -ENOMEM; aspeed->dev = &pdev->dev; aspeed->base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(aspeed->base)) - return PTR_ERR(aspeed->base); + if (IS_ERR(aspeed->base)) { + rc = PTR_ERR(aspeed->base); + goto err_free_aspeed; + } aspeed->clk = devm_clk_get(aspeed->dev, NULL); if (IS_ERR(aspeed->clk)) { dev_err(aspeed->dev, "couldn't get clock\n"); - return PTR_ERR(aspeed->clk); + rc = PTR_ERR(aspeed->clk); + goto err_free_aspeed; } rc = clk_prepare_enable(aspeed->clk); if (rc) { dev_err(aspeed->dev, "couldn't enable clock\n"); - return rc; + goto err_free_aspeed; } rc = setup_cfam_reset(aspeed); @@ -595,7 +598,7 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev) rc = opb_readl(aspeed, ctrl_base + FSI_MVER, &raw); if (rc) { dev_err(&pdev->dev, "failed to read hub version\n"); - return rc; + goto err_release; } reg = be32_to_cpu(raw); @@ -634,6 +637,8 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev) err_release: clk_disable_unprepare(aspeed->clk); +err_free_aspeed: + kfree(aspeed); return rc; } -- 2.34.1