Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1770690ybl; Sat, 11 Jan 2020 02:28:48 -0800 (PST) X-Google-Smtp-Source: APXvYqxEYChjC6yj6gUlpaSGYMn/Zd1UhnyOGfwwYOVFr5KsXt3QmzFpi/HC4wZWn3G9DsBfHU1p X-Received: by 2002:aca:3846:: with SMTP id f67mr5632986oia.61.1578738528534; Sat, 11 Jan 2020 02:28:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578738528; cv=none; d=google.com; s=arc-20160816; b=PPDzQea5t1slcFJIbh74D9QG03EQOYWGbJTiBTmPI0ZKb6yxkBEqoanqTOK38OEaoA 2qS7yzUC/YzZyHTfJ+UNiAq4pUOjxkWfL7w0LE6OZv90egHG74VcFY2uLNH56JI+pIuX PxdEmOyJiTQiip85/+Mn9FS6THwXbGLU2TO6DHO+e7MqNZIgxvsyQYQPNDUvFC41rhaw tIpXaHdHrtdAigBwqATpD/fqalm3p7CHUlNj8pcYKNsbYmxpnh2L/mP7A2+SVKDMz1FX PZvOnp8PFPQnWLVcxkoeScok1RSXfUKkazSFJLKZYkoScYFoTM7rejSCWRlScEu3JyTQ hLdQ== 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=jBc/PP2W7KLppYquIA3C442auuDMXlmLdvSjln8a7QE=; b=RDcw+esqIseKntb8Ro7+w9kvExJRrHDc9z2qgnxjRY4RQOCSMXS+g77oLT1Gd3EHn0 reXrKCq7yWaNbLueOAXa7WuapMJNqp42npkrSGRakopqcmgcg4tQ4Z4HhTl7tdicNHjy O9qzagBC4V5I+Y3+HBHAVrVNn6ErpgAD3DGq4Ryb3jIHB/Fz6vz6xjYBiM9rnT3tGNVI ZqRM2JN4Ac4EfZhJ5Cyp/5l9MCwFh5mG6+c4m2OEn/cCpMf72ys61zC95Uo9XAsj6au9 KctIKrXctiZmfpmYERjnsTlvgEiHPhpnt9jRWCbDmCidznsVQmRBvS+3PLEqyIPPYRMh 6/JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TVC2Ej7Q; 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 a7si3278189otp.284.2020.01.11.02.28.37; Sat, 11 Jan 2020 02:28:48 -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=TVC2Ej7Q; 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 S1730994AbgAKK1l (ORCPT + 99 others); Sat, 11 Jan 2020 05:27:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:33854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729453AbgAKK1k (ORCPT ); Sat, 11 Jan 2020 05:27:40 -0500 Received: from localhost (unknown [62.119.166.9]) (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 12CD22082E; Sat, 11 Jan 2020 10:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578738460; bh=rz3vLQZsEWlTvqZxYmkCgHHyAVgnHuRMZcZGDboN2wA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TVC2Ej7Q3EUjp94mQ/+iAnYW9zjcDfxkpUyQK1xeCN+B3/zX3ra+Kq7bySypmx7dw kkccCObFSjNXreqI4EFc2QhKWazPb7T0bCg4jQLY3fqhwUy2Q/4LJhMCb5jfLL98rE NtTEFIiwqgqH2vycmqzXOqPUulHQ0gVmg61V1Vro= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Meelis Roos , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.4 098/165] perf/x86: Fix potential out-of-bounds access Date: Sat, 11 Jan 2020 10:50:17 +0100 Message-Id: <20200111094929.877047542@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200111094921.347491861@linuxfoundation.org> References: <20200111094921.347491861@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: Peter Zijlstra [ Upstream commit 1e69a0efc0bd0e02b8327e7186fbb4a81878ea0b ] UBSAN reported out-of-bound accesses for x86_pmu.event_map(), it's arguments should be < x86_pmu.max_events. Make sure all users observe this constraint. Reported-by: Meelis Roos Signed-off-by: Peter Zijlstra (Intel) Tested-by: Meelis Roos Signed-off-by: Sasha Levin --- arch/x86/events/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 7b21455d7504..b9673396b571 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -1641,9 +1641,12 @@ static struct attribute_group x86_pmu_format_group __ro_after_init = { ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, char *page) { - struct perf_pmu_events_attr *pmu_attr = \ + struct perf_pmu_events_attr *pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr); - u64 config = x86_pmu.event_map(pmu_attr->id); + u64 config = 0; + + if (pmu_attr->id < x86_pmu.max_events) + config = x86_pmu.event_map(pmu_attr->id); /* string trumps id */ if (pmu_attr->event_str) @@ -1712,6 +1715,9 @@ is_visible(struct kobject *kobj, struct attribute *attr, int idx) { struct perf_pmu_events_attr *pmu_attr; + if (idx >= x86_pmu.max_events) + return 0; + pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr); /* str trumps id */ return pmu_attr->event_str || x86_pmu.event_map(idx) ? attr->mode : 0; -- 2.20.1