Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3983014pxb; Mon, 4 Oct 2021 14:23:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyL+a9HR3Nk83Q20aAQ418WZmaKF8LifqdgXLuSgsF2wgDUuNrFeqsCzRa5+9X3OlboE+4o X-Received: by 2002:a63:594a:: with SMTP id j10mr12718809pgm.205.1633382615767; Mon, 04 Oct 2021 14:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633382615; cv=none; d=google.com; s=arc-20160816; b=d0SwCCrsjDe4Tvq6FsM6M7EO5GP6pSN0GrSlKDK/ii3Pd7iHcNBdjfGhIPyxmgmdR3 MHyRxq8x/hHlZvOZAwv5hSoJkqRFvECUC2Uiht+S4ka8MBwVf25ZuhTVOBoT2nyI1iWP 7eFnBglng32py8sNeFbu72WyCDT/8WRyiWriGGVphcC9hxHid75qt4Q6GZOCB9G0vcbt 7jAhdj0PqAHAZGwvG2t3ZnILiy3ixFMAsGxqcS95NsJulgOJcF9n2g+vX2Fbbg2WRrOk btp9f+rlAIM+fkSF57I2SPTLc0vED8fy9cHcdl/iGZ4nd2CVHyISbbb5xisygp9gJAIV iV6g== 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=PGSDfy+guXn1M3Rtklm0tj4ObyDXRSQ3esjgr4BhtFY=; b=IZmAdNENwjZdjskThjFYvsBuMWqYd9RIxPZ8adZRd/rgbzFm9LlFLY5Uz386IgtWLJ Zy+LZQnbHlxvE6UczwKXPu3v4MvlImq4oFynZ9wFMJBnf2NijZfwHd66tvHebUyJNSUy aRvkPXH+9Jh547blntxXefS/OGcrPllqJhUus6AB552xFZsnyJ62g3kuf011V1C3LeOt tjI/zzFdq3UH7zEDRwh71WFG5H9ZzCEEzSRTlQOuHf+KfPkIQ+EFi3flJH384n9/03sj KKFpzBBanPaQJBBYgT8BkMw7D2Uh29BjJmlU411doshbEh9bHwSbS3UrbsRY9IAF6XjP 1Gqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="0+miB/05"; 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 d27si23963579pgd.29.2021.10.04.14.23.23; Mon, 04 Oct 2021 14:23:35 -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="0+miB/05"; 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 S237049AbhJDNbc (ORCPT + 99 others); Mon, 4 Oct 2021 09:31:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:42730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235297AbhJDN3b (ORCPT ); Mon, 4 Oct 2021 09:29:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7F60B6321B; Mon, 4 Oct 2021 13:13:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353195; bh=ZTne2VZLofEonIy43J/+zmPzCS+nJjaStaqiKJNj2kM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0+miB/05vgrr9wPz+rukJcwAgkowtk47iY9m7+6+ndAD07VQXz2U0u/qoeXos2T0s fuvNU1NF4IyuZp2JPHhkcKOEuJtAgp142vIq+G1hStb2hu0jgHqVeS2iIHVozPNtEz 4Dpml7udUUvAem1OGhPEWyIylwUmFkJTelaA3fwg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Morse , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.14 033/172] cpufreq: schedutil: Destroy mutex before kobject_put() frees the memory Date: Mon, 4 Oct 2021 14:51:23 +0200 Message-Id: <20211004125046.036208574@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@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: James Morse [ Upstream commit cdef1196608892b9a46caa5f2b64095a7f0be60c ] Since commit e5c6b312ce3c ("cpufreq: schedutil: Use kobject release() method to free sugov_tunables") kobject_put() has kfree()d the attr_set before gov_attr_set_put() returns. kobject_put() isn't the last user of attr_set in gov_attr_set_put(), the subsequent mutex_destroy() triggers a use-after-free: | BUG: KASAN: use-after-free in mutex_is_locked+0x20/0x60 | Read of size 8 at addr ffff000800ca4250 by task cpuhp/2/20 | | CPU: 2 PID: 20 Comm: cpuhp/2 Not tainted 5.15.0-rc1 #12369 | Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno Development | Platform, BIOS EDK II Jul 30 2018 | Call trace: | dump_backtrace+0x0/0x380 | show_stack+0x1c/0x30 | dump_stack_lvl+0x8c/0xb8 | print_address_description.constprop.0+0x74/0x2b8 | kasan_report+0x1f4/0x210 | kasan_check_range+0xfc/0x1a4 | __kasan_check_read+0x38/0x60 | mutex_is_locked+0x20/0x60 | mutex_destroy+0x80/0x100 | gov_attr_set_put+0xfc/0x150 | sugov_exit+0x78/0x190 | cpufreq_offline.isra.0+0x2c0/0x660 | cpuhp_cpufreq_offline+0x14/0x24 | cpuhp_invoke_callback+0x430/0x6d0 | cpuhp_thread_fun+0x1b0/0x624 | smpboot_thread_fn+0x5e0/0xa6c | kthread+0x3a0/0x450 | ret_from_fork+0x10/0x20 Swap the order of the calls. Fixes: e5c6b312ce3c ("cpufreq: schedutil: Use kobject release() method to free sugov_tunables") Cc: 4.7+ # 4.7+ Signed-off-by: James Morse Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/cpufreq/cpufreq_governor_attr_set.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq_governor_attr_set.c b/drivers/cpufreq/cpufreq_governor_attr_set.c index 66b05a326910..a6f365b9cc1a 100644 --- a/drivers/cpufreq/cpufreq_governor_attr_set.c +++ b/drivers/cpufreq/cpufreq_governor_attr_set.c @@ -74,8 +74,8 @@ unsigned int gov_attr_set_put(struct gov_attr_set *attr_set, struct list_head *l if (count) return count; - kobject_put(&attr_set->kobj); mutex_destroy(&attr_set->update_lock); + kobject_put(&attr_set->kobj); return 0; } EXPORT_SYMBOL_GPL(gov_attr_set_put); -- 2.33.0