Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4820932ybl; Wed, 22 Jan 2020 05:23:16 -0800 (PST) X-Google-Smtp-Source: APXvYqz/GbgqPMiWE+VsgVgZ+wC/agEEAoy3ijs5uJENzrObudBujWs3m6WkPMDEhHivRRawylww X-Received: by 2002:a9d:5542:: with SMTP id h2mr6772882oti.146.1579699396476; Wed, 22 Jan 2020 05:23:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699396; cv=none; d=google.com; s=arc-20160816; b=k3x0RjjkwLE9w4HBiGafVMQtzQ8kJFohXrvKoTQrwYoNiWvoYUbSilF8fgGuZTHR6f cie0PGp2QMtQwD5c3j5J6YKHrj6eIShKZlfmcfSPDY0R1I7FdLUrZXY+cfIVbTtQZp7U W5hLD0wCPLngKzgrgYt/KGFEzE8Q15ddVGeH8Nbu9BpAJkmX/HSWarlhOV+TWD87fv96 2BuDEp1uZmD76xMOhBv11i1ICxqpKF8vROGB2EoU0Z+bT1TeeZfMERUS3RywCS0VnsFe zBCKQOwdlhb0V8f+LVZW3oYIIBIF4L0LEwe7ZUm/fcqSSiof2JzH5TelQDknGdwQP9qQ zAWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dXJHGvhBHeVYcXY8J779oG9v0tVjtlJMWuO2zBLcvuI=; b=0eRKsh67hGzRRKsYV5uE1cGvSJECbO8KHEesHoCXh8HrThZTlh0O8vyJen78+aZy/L YM5en+ZtRJceTTX/oxfZhPwLu+na//G77/wnKV+qVrCMdzpR6ztUeVZM+9nsNoUHMMNd LEc4Yue8sw5LWgqBQQFGBdBbjs+J1WoQR2P4RM3IQG8718Tbp2wqFcMkBhbxbiHqB3dz 1yEWcAJjmEnEhUinVx/YtZIP+q2eU2ipJuEbkpB28pZIh0zdZbwsqnkkn11Zfe7rdpud UEMshK00STAh846VNShIWSkd/4gMYVtAhFOVlhNgY3HfAiDwLkwpVpfV+r7GRH6b7e3J al6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g5lv3YxK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m7si20617483oih.7.2020.01.22.05.23.04; Wed, 22 Jan 2020 05:23:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g5lv3YxK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729963AbgAVNU0 (ORCPT + 99 others); Wed, 22 Jan 2020 08:20:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:36614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729409AbgAVNUY (ORCPT ); Wed, 22 Jan 2020 08:20:24 -0500 Received: from localhost (unknown [84.241.205.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 35C242467F; Wed, 22 Jan 2020 13:20:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699223; bh=uafhk5sWJvoBC4coMWjV2mrDWqrFLj8kEONNP6ybf40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g5lv3YxK91GZfixCYCSG9TbM3U/kwRxwn1iL4JxMlAlslEozrN7WtPI2TzdnHe67E wIKZxxVR1fx6T3TXfuaBwMkJhwLehikHN9xWPpQHsWpiT5f4jfaAjaL4sJmG/KKbo4 UflXUV9kH33YmeJt/WvEwDikZnjKaHYWdu8GnV/o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shakeel Butt , Borislav Petkov , Fenghua Yu , "H. Peter Anvin" , Ingo Molnar , Reinette Chatre , Thomas Gleixner , x86-ml Subject: [PATCH 5.4 071/222] x86/resctrl: Fix potential memory leak Date: Wed, 22 Jan 2020 10:27:37 +0100 Message-Id: <20200122092838.804074617@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shakeel Butt commit ab6a2114433a3b5b555983dcb9b752a85255f04b upstream. set_cache_qos_cfg() is leaking memory when the given level is not RDT_RESOURCE_L3 or RDT_RESOURCE_L2. At the moment, this function is called with only valid levels but move the allocation after the valid level checks in order to make it more robust and future proof. [ bp: Massage commit message. ] Fixes: 99adde9b370de ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG") Signed-off-by: Shakeel Butt Signed-off-by: Borislav Petkov Cc: Fenghua Yu Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Reinette Chatre Cc: Thomas Gleixner Cc: x86-ml Link: https://lkml.kernel.org/r/20200102165844.133133-1-shakeelb@google.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1741,9 +1741,6 @@ static int set_cache_qos_cfg(int level, struct rdt_domain *d; int cpu; - if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL)) - return -ENOMEM; - if (level == RDT_RESOURCE_L3) update = l3_qos_cfg_update; else if (level == RDT_RESOURCE_L2) @@ -1751,6 +1748,9 @@ static int set_cache_qos_cfg(int level, else return -EINVAL; + if (!zalloc_cpumask_var(&cpu_mask, GFP_KERNEL)) + return -ENOMEM; + r_l = &rdt_resources_all[level]; list_for_each_entry(d, &r_l->domains, list) { /* Pick one CPU from each domain instance to update MSR */