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=ham 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 B0FABC33C8C for ; Sun, 5 Jan 2020 12:51:04 +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 7EE712072C for ; Sun, 5 Jan 2020 12:51:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IUJfP7iB"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RxnpqQhv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7EE712072C 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=0rHhp/JZFZj6SGrjvx0kKB/NiGzj+2FWiN8QAji/EJo=; b=IUJ fP7iBvTqsi08ERdRKH9nCCg+Had46RNTDujgQYSbvkfPp9PZ4XIwlMa5KUCgG3/OZKvimoJ70DblA FgA8yj8UROKHiw2FWLvOvUPrXcVpQuVMj0qOlT9oTJUgeWhgavln7hpm93lx3cN4nq1KsKeVATvww ax6AGmuZuMdSfY+iG/sKS3AeOWHtBHITLCJqBRAkT+wzFOjL2YnTaw9Ew8eT3T9bKiNoe6JiIXVA+ uSoZfQaaXGjZqVRr+6rJXvKaDcMCfE00VMo9KuK0cULNe9s2pnfZyL4W+h2x/Jkpyml2AjIk7lcHS qABsBzOSYi7qoFxB+ufjBETdzQNPykw==; 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 1io5N0-0002CK-Jn; Sun, 05 Jan 2020 12:51:02 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1io5Mw-0002Bi-8u for linux-arm-kernel@lists.infradead.org; Sun, 05 Jan 2020 12:51:00 +0000 Received: by mail-pg1-x542.google.com with SMTP id r11so25585345pgf.1 for ; Sun, 05 Jan 2020 04:50:56 -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=O73F02mr1vEr7ShVhQ/rPt/DWjk1N7vtrWpN2HwbxPw=; b=RxnpqQhvQ5bv7z0xIAnD8gdhFyHKqKqpdXwTBhsUdEpg4sSugA+Vrg+Lmzf2NpnmLO k22F3pGksCJ5uQ+ueN0NIRXsZNOZuD1vRoDmkDrxuHiRk6/pl0MzljAmGMdmWfGPQFjF MZWdUkytwQeduUN8GEa4mwe+wZ2F3Krq2JVCeI+/Pyf/cuxId0btKL3aCfzLBsSwv1rp slF/9GvYZkEQ5yxavZwbu0zKrbowEHUqxJ4GsYFcAcxmKtp90yi1nke2ieHiW/Y7W8rs Pv0qHXykJtQjq3Ag0JxThiJ0f+3T4jeeYm2rTkdjGLbaIp/Z0LZ6y8p/qj/x0xjdFpBB QY8g== 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=O73F02mr1vEr7ShVhQ/rPt/DWjk1N7vtrWpN2HwbxPw=; b=q2Xn1BjCDISXZGLYYycoaiZaYHZa7r9ZDhVNKA9Xhw7Eg4M4gvp0u5HM2lXZb/5D0/ 6FDD9/wiPHoRHS87fAzCPqcla3pVCk4465DL9Y8GwU4wrMtDZwn8r7jH+glPdZDJCo0O O+FxE8EYJ5dCwHEVPCcaxuGPgjHUzJ3IrVJCgzVetNgEzX5Q4UYmX+FEWh/V1NbuFtWE Ve2AZMTJxcMxWCYH+25wlHD80hQXJj33vTxogNGZAGl2/2gYlKrN52D/9BU2Yas/Of+9 65Not/v/zryPfdsbFGR6my0pU32r309ZA74NCgTV/Rs3IPy9/Zo+BhUAkZEz7VM+Orvr hOnA== X-Gm-Message-State: APjAAAWMjBDLGgfDypR+kMc97rJDr5JzB2qSrYt6AaRnqzQPLzmhxo22 TqWDxP1b/sMEg8xLQ9zAJiw= X-Google-Smtp-Source: APXvYqxUgpmdlnIXGhbVIEYm+2ZG/SLeZ4ocWYD5rb0O++qhXkZAxHm0/oxmD2mMWohAObY+FG5NaQ== X-Received: by 2002:a62:e908:: with SMTP id j8mr93764073pfh.55.1578228656502; Sun, 05 Jan 2020 04:50:56 -0800 (PST) Received: from localhost ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id z130sm70081453pgz.6.2020.01.05.04.50.55 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 05 Jan 2020 04:50:56 -0800 (PST) From: qiwuchen55@gmail.com To: mmayer@broadcom.com, rjw@rjwysocki.net, viresh.kumar@linaro.org, f.fainelli@gmail.com Subject: [PATCH v2] cpufreq: brcmstb-avs-cpufreq: avoid potential stuck and UAF risk Date: Sun, 5 Jan 2020 20:50:50 +0800 Message-Id: <1578228650-17157-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-20200105_045058_338515_DA7B21F9 X-CRM114-Status: GOOD ( 10.99 ) 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-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 of cpufreq_cpu_put() is ignored to decrement the kobject reference count back, which may lead to a potential stuck risk that percpu cpuhp thread deadly waits for dropping of kobject refcount when percpu cpufreq policy free. The call trace of stuck risk could be: cpufreq_online() //If cpufreq online 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 this can be easily exercised by attempting to force an unbind of the CPUfreq driver. Signed-off-by: chenqiwu --- drivers/cpufreq/brcmstb-avs-cpufreq.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c index 77b0e5d..6d2bf5c 100644 --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c @@ -452,8 +452,15 @@ 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) + return 0; + + priv = policy->driver_data; + if (!priv || !priv->base) + return 0; 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