Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp16296809ybl; Wed, 1 Jan 2020 02:19:18 -0800 (PST) X-Google-Smtp-Source: APXvYqz/4ci1V4V/YCbKV/VFH+ts7nX+7F6Uxd470TNRwooWXtvBAaWH7AW6bFUQx32TbchHnUkQ X-Received: by 2002:a17:906:3299:: with SMTP id 25mr81652992ejw.118.1577873958471; Wed, 01 Jan 2020 02:19:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577873958; cv=none; d=google.com; s=arc-20160816; b=qTTQd10Aui6gKJajm8ED+so9FpVqIrVzEf7XHx0khC/fFLha9K4uwAwGdBUj9qn2W3 9Ce0PV2t2Z7J2R97Ht2Cavz4znbJm5WrJU3Z9vm8OheHeDYpVoI0uGK7peF+kp/bvOI7 cbXSkT1ryptQKCin1k15Lg2t8j+CSGf1c4r2XHRNCJlSedJGC6R+zfHQS0/z+Qusli9F t3O4n5KHwTGHHG9reRAkSUuJvUf0mgDaQ/2yozurlmMlonEGVpuM72uNAq4mlNoIVEHL ey4fuQLEIbLxZBzjyZV0OeKPtEnx0FrY1zYjoqoLNHNjVfx1+QMeM95zttbzHeqBZQpv viNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=CexLLfP5wXDijeY6hIxv94YwZ310wApZ5/BW+991c/M=; b=Trw+vdCjUaDUNtNUNBkoQqMRYZtlyXtPgCdYFvm6t8SiNX98xOvENZ44lTvQMa+x8f dS0tuOW53t3O9PG7qziNLF5njEqd9/fVeVxQmGZuFIwddlVWM+31XtcWhEBX2KKx3OmX oOxIQ3RxeMsm4s+fNuHotYr7nDCYz4pDVtg8W3ifZN/29YwL++XqWh11+fRIOtACJn7W TqePMi24KkP8CFTs6iLb8JLC2CTVFFFdRVinYAbtnMJtdo+46avj5pB+faUDpj6fz1wN QM22I0csDB38QCyPaSppFFfBKaz+WJKWh3gncI4g/SJM8sGgMVrsmg09uf+gsNVJJAGr 72vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="Yu5SR/gV"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f6si32127141eds.441.2020.01.01.02.18.52; Wed, 01 Jan 2020 02:19:18 -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=@alien8.de header.s=dkim header.b="Yu5SR/gV"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725883AbgAAKRS (ORCPT + 99 others); Wed, 1 Jan 2020 05:17:18 -0500 Received: from mail.skyhub.de ([5.9.137.197]:33680 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725783AbgAAKRS (ORCPT ); Wed, 1 Jan 2020 05:17:18 -0500 Received: from zn.tnic (p200300EC2F00E7006D646DE0D0F19687.dip0.t-ipconnect.de [IPv6:2003:ec:2f00:e700:6d64:6de0:d0f1:9687]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 178471EC0BEA; Wed, 1 Jan 2020 11:17:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1577873837; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=CexLLfP5wXDijeY6hIxv94YwZ310wApZ5/BW+991c/M=; b=Yu5SR/gVn2JiqI/gavibwlfu0AW1qFA+0v9BN/M+QA9S/GgaWSZq7tfsRJjMxEG2aEDPzH q4hXvfaSu8oOSYPGLsV6uNMAz5Z8clP+Ay4Yr9CzKfLDLu2Z3dspYbUIUJBDpokpMKZpUn VVYUBAqhyGDEv4PTbkxHrEyjst/ddWo= Date: Wed, 1 Jan 2020 11:17:08 +0100 From: Borislav Petkov To: Shakeel Butt Cc: Reinette Chatre , Fenghua Yu , Thomas Gleixner , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] x86/resctrl: Fix potential memory leak Message-ID: <20200101101708.GA14315@zn.tnic> References: <20191220164358.177202-1-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191220164358.177202-1-shakeelb@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 20, 2019 at 08:43:58AM -0800, Shakeel Butt wrote: > The set_cache_qos_cfg() is leaking memory when the given level is not > RDT_RESOURCE_L3 or RDT_RESOURCE_L2. However at the moment, this function > is called with only valid levels but to make it more robust and future > proof, we should be handling the error path gracefully. > > Fixes: 99adde9b370de ("x86/intel_rdt: Enable L2 CDP in MSR IA32_L2_QOS_CFG") > Signed-off-by: Shakeel Butt > Acked-by: Fenghua Yu > --- > Changes since v1: > - Updated the commit message > > > arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c > index 2e3b06d6bbc6..a0c279c7f4b9 100644 > --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c > +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c > @@ -1748,8 +1748,10 @@ static int set_cache_qos_cfg(int level, bool enable) > update = l3_qos_cfg_update; > else if (level == RDT_RESOURCE_L2) > update = l2_qos_cfg_update; > - else > + else { > + free_cpumask_var(cpu_mask); > return -EINVAL; > + } And why can't the level check happen first and the allocation second, thus needing to allocate the cpu mask only when the level is valid? -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette