From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754077AbdDKIJd (ORCPT ); Tue, 11 Apr 2017 04:09:33 -0400 Received: from terminus.zytor.com ([65.50.211.136]:43691 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752759AbdDKIIb (ORCPT ); Tue, 11 Apr 2017 04:08:31 -0400 Date: Tue, 11 Apr 2017 01:03:46 -0700 From: tip-bot for Jiri Olsa Message-ID: Cc: tglx@linutronix.de, shli@fb.com, hpa@zytor.com, mingo@kernel.org, peterz@infradead.org, jolsa@kernel.org, fenghua.yu@intel.com, linux-kernel@vger.kernel.org, efault@gmx.de, a.p.zijlstra@chello.nl Reply-To: mingo@kernel.org, hpa@zytor.com, shli@fb.com, tglx@linutronix.de, fenghua.yu@intel.com, jolsa@kernel.org, peterz@infradead.org, a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org, efault@gmx.de In-Reply-To: <20170411071446.15241-1-jolsa@kernel.org> References: <20170411071446.15241-1-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/intel_rdt: Fix locking in rdtgroup_schemata_write() Git-Commit-ID: 7f00f388712b29005782bad7e4b25942620f3b9c X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 7f00f388712b29005782bad7e4b25942620f3b9c Gitweb: http://git.kernel.org/tip/7f00f388712b29005782bad7e4b25942620f3b9c Author: Jiri Olsa AuthorDate: Tue, 11 Apr 2017 09:14:46 +0200 Committer: Thomas Gleixner CommitDate: Tue, 11 Apr 2017 09:48:12 +0200 x86/intel_rdt: Fix locking in rdtgroup_schemata_write() The schemata lock is released before freeing the resource's temporary tmp_cbms allocation. That's racy versus another write which allocates and uses new temporary storage, resulting in memory leaks, freeing in use memory, double a free or any combination of those. Move the unlock after the release code. Fixes: 60ec2440c63d ("x86/intel_rdt: Add schemata file") Signed-off-by: Jiri Olsa Cc: Fenghua Yu Cc: Peter Zijlstra Cc: Peter Zijlstra Cc: Mike Galbraith Cc: Shaohua Li Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/20170411071446.15241-1-jolsa@kernel.org Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/intel_rdt_schemata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/intel_rdt_schemata.c b/arch/x86/kernel/cpu/intel_rdt_schemata.c index f369cb8..badd2b3 100644 --- a/arch/x86/kernel/cpu/intel_rdt_schemata.c +++ b/arch/x86/kernel/cpu/intel_rdt_schemata.c @@ -200,11 +200,11 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of, } out: - rdtgroup_kn_unlock(of->kn); for_each_enabled_rdt_resource(r) { kfree(r->tmp_cbms); r->tmp_cbms = NULL; } + rdtgroup_kn_unlock(of->kn); return ret ?: nbytes; }