From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35728C2D0C8 for ; Sat, 28 Dec 2019 06:15:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0745620838 for ; Sat, 28 Dec 2019 06:15:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OLDHqG5P"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mSbekCGB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0745620838 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=Rb6uZvKef32bg6rKNFUOZ/36amBMZjxiKlaxh6jl20o=; b=OLD HqG5PN+Pms0d6BlU19XZpOd8iIEXtbp8L9i4cjmHZn4QQAJzRYBSGIrc5PkVRjbwQATsDJxFD3dmw KNXVSYcqf0oITrGtlBQ39dHpj+cpCfGBSY1BDo5l784NxfNFzKy+dAuMQn3pKxd/3Swih/9xBCYWe lA2es4K743a/MgJowi4avy6AXeFVqsdyiFjCy+WHPVOICOUj7j7NdzIk3xdQBp5LfHNprZfPBWb4K /4ajOF25lcwKsCniPPBmUx90+uma5WXy62VZNeboC7Lp4iZj7d2mxbJsSmr/RwRY0HJN/tjhbp09D CNeoZS/z1R2v44ApgC9gpI6iC/rz4Cw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1il5O3-00025P-GS; Sat, 28 Dec 2019 06:15:43 +0000 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1il5Ny-00024U-Tf for linux-arm-kernel@lists.infradead.org; Sat, 28 Dec 2019 06:15:40 +0000 Received: by mail-pj1-x1041.google.com with SMTP id t101so5835231pjb.4 for ; Fri, 27 Dec 2019 22:15:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=qe6cSiGPXPhmquRmJ+vPfyD3fRySMNawHDWjAW0LBjw=; b=mSbekCGB4AVcrFqm765lc5SaSM4aAYaisiGXUoW/1H2dX9x3XCyGFhyYGvJ7CAxF0Q i3k//4abu6O5iYqmX0H5lFXruYG78sTBGK3mocMEcU5pUqKdsJ/Qhs8SShcAW1+mvn8k LCvJ1sNGbRlpgMJ+nECm555asbw4gIq1l7liz6zRp12cYiCFQUv45axwicQY0n8WbGDo ZejPXP7ufiq0d0sC5o/MD8vNS6TVAozMG2QFHE5Q0FzQ4cyMBe0jyc8hxb3irxY86sWX AYIl7Le9dcORNFwYb7IkRbUEbB457F+6Urp/7tFbwMHcE6StbYQ5l5MIdz/Vxa1HyEkm pGOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qe6cSiGPXPhmquRmJ+vPfyD3fRySMNawHDWjAW0LBjw=; b=FNoVi6pCQlF9/J6HhE6m8PPGjKw53GNDBvIf8m/rLMhyRQSzJh7kj3DiOz/y/t++t0 l//czTB5nWrhQz4uRXO2jUzRlfxByBQszw+4FzHqUdLRBJ+QYjzhX1ta1tf9OdwKC/2b fdqiZhS/l/zDdkKoU5PsWBmmKOUJ240N5dV9H8AOaAlLxtIPOwOz07I9iO4tA0HRXNG+ E+A4D8bDjZWARv7CaOKWYqpjV8B2w/XIIgcGm6YDNAWSzbT87DcLRnK05A8NG/rzW7ac gkOFhQoizBV/8ct+yYKc36b8+0H0gf3NuXKsK/TIimNVXoVAzYDT3GhRMEa1EuY9QMCu bWSA== X-Gm-Message-State: APjAAAUe3Qd06BYLbp7FtvlIkx1hhdytc627ZOSbA4Au8fsNGOoZxhyt KT3Y/BBCnPMVn/UIgNAXBlE= X-Google-Smtp-Source: APXvYqz2bcxQFOhSNl7uvapbX387WUr60/UnSgG+VSIdTO4YpwUM2lqbK73iE31Un0HN1Uc2lN2I/g== X-Received: by 2002:a17:90a:300b:: with SMTP id g11mr30676779pjb.123.1577513737609; Fri, 27 Dec 2019 22:15:37 -0800 (PST) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id x65sm44401182pfb.171.2019.12.27.22.15.36 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 27 Dec 2019 22:15:37 -0800 (PST) From: qiwuchen55@gmail.com To: mmayer@broadcom.com, rjw@rjwysocki.net, viresh.kumar@linaro.org, f.fainelli@gmail.com Subject: [PATCH] cpufreq: brcmstb-avs-cpufreq: avoid a stuck risk and UAF issue in brcm_avs_cpufreq_get() Date: Sat, 28 Dec 2019 14:15:30 +0800 Message-Id: <1577513730-14254-1-git-send-email-qiwuchen55@gmail.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191227_221538_982743_469589B0 X-CRM114-Status: GOOD ( 10.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chenqiwu , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: chenqiwu brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get cpufreq policy, meanwhile, it also increments the kobject reference count of policy to mark it busy. However, a corresponding call to cpufreq_cpu_put() is ignored to decrement the kobject reference count back, which may lead to a potential stuck risk that cpuhp thread deadly wait for dropping of refcount when cpufreq policy free. The call trace of stuck risk could be: cpufreq_online() //cpufreq initialization failed, goto out_free_policy. ->cpufreq_policy_free() //do cpufreq_policy free. ->cpufreq_policy_put_kobj() ->kobject_put() //skip if policy kfref count is not 1. ->cpufreq_sysfs_release() ->complete() //complete policy->kobj_unregister. ->wait_for_completion() //wait for policy->kobj_unregister. A simple way to avoid this stuck risk is use cpufreq_cpu_get_raw() instead of cpufreq_cpu_get(), since brcmstb-avs driver just want to get cpufreq policy in cpufreq_notify_transition(). What's more, there is a potential UAF issue in cpufreq_notify_transition() that the cpufreq policy of current cpu has been released before using it. So we should make a judgement to avoid it. Thanks! Qiwu Signed-off-by: chenqiwu --- drivers/cpufreq/brcmstb-avs-cpufreq.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c index 77b0e5d..31aa76f 100644 --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c @@ -452,8 +452,17 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) { - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); - struct private_data *priv = policy->driver_data; + struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu); + struct private_data *priv; + + if (!policy) { + dev_warn(dev, "cpu %d: CPUFreq policy not found\n", cpu); + return NULL; + } + + priv = policy->driver_data; + if (!priv || !priv->base) + return NULL; return brcm_avs_get_frequency(priv->base); } -- 1.9.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel