Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4300706pxu; Tue, 1 Dec 2020 01:15:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRvFz6kY7dXxU6OvIurMa10+lteXav7pAzPb3xGTOsSI3hLEsIGLuGadA6L4AcKlrq7jwa X-Received: by 2002:aa7:db01:: with SMTP id t1mr2018298eds.185.1606814152980; Tue, 01 Dec 2020 01:15:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606814152; cv=none; d=google.com; s=arc-20160816; b=WNofSttNDlc7hmqfBgV1Fzeik5QwiafsYcdLAVBT54V100WVGEXA/lsZdezDG+nW2w eMR2Scx6+jKrPvU3Has74MVEQA8hrTG5jdNcPY6GI+AMgHuWbj3nauNuEYethDSMicfD RzIhzBSHKlOc+DL1nyxzg/inN1c+W0MA8vJtQHkg+YLDhXy0s3nI3ZEwwIuCbeHi9cdY JUrO5vOeRuRNjgFGpyZm7lFhQbPLZr2QrSB/vQFtAOkWAMaucC9irCksGz1t2UwUCAtl 4JtwUN1BTt8YrCZr03CMM90Xb38Lpt5EtCBJukgq5cuVKaIFTjcIGmLDm6R3PxHuUN4Y 7uzA== 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=vNmHDuFREd/s36i4jJ6yi71w2bRcq4rgmojIF/ttKZg=; b=Nd84mlM/HLRXbemDME3wJ6Lpd94oCr7CfeDzuX5Xdkq99bMaYvAwjZTKkTm4pAT96r 1NLeE0YavvWy3TJ+Z3+StS5nCRpn2pbTV32mLbx41wm8m9KXzCGbdGFb3KbpT0zqk97S PguqgoMMLUmaUaCi2jJ1qfKyicCdUr3DWu0PrAN0F8QgXATPYXa/P03Tkc0XgNT5O8D+ GpXF86bcmVk4O0GBr23VET4ehpALvKQpLuPHwmNKwWeQMh2LeviJoDm/QLBggcuqDv7/ dS1Z7mRZ3a2IgTPIWPDWbb9gK34cO0KcFE2tCqwfIcI4EJUbeuy+L55dQYQuf1l+ekB4 WuAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UwktQ557; 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 v10si535719ejb.579.2020.12.01.01.15.16; Tue, 01 Dec 2020 01:15:52 -0800 (PST) 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=UwktQ557; 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 S2389689AbgLAJKZ (ORCPT + 99 others); Tue, 1 Dec 2020 04:10:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:47620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389674AbgLAJKV (ORCPT ); Tue, 1 Dec 2020 04:10:21 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 2F46620671; Tue, 1 Dec 2020 09:10:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813805; bh=PpkHv6MRdo5REGwV+VLtx5I33j0C6wB/LT0a8qVxCOg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UwktQ557wgkAZq81CMxXnpNyWGdhwMzmNtG4V/qr/9lxKueWa8qmYUc5vrXclsQw/ 7koNlg5x5Rf8NWyo86iTyXug1GPqUNcDCJwSV3TFv9h1ZfO55Ed1xnqAOR9lTUOblD ME3bdvUjXiBHQJ3ynRIBFLzbr5oryLpkVj8Qk/wo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sedat Dilek , Sami Tolvanen , "Peter Zijlstra (Intel)" , Kees Cook , Sasha Levin Subject: [PATCH 5.9 065/152] perf/x86: fix sysfs type mismatches Date: Tue, 1 Dec 2020 09:53:00 +0100 Message-Id: <20201201084720.448036043@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084711.707195422@linuxfoundation.org> References: <20201201084711.707195422@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: Sami Tolvanen [ Upstream commit ebd19fc372e3e78bf165f230e7c084e304441c08 ] This change switches rapl to use PMU_FORMAT_ATTR, and fixes two other macros to use device_attribute instead of kobj_attribute to avoid callback type mismatches that trip indirect call checking with Clang's Control-Flow Integrity (CFI). Reported-by: Sedat Dilek Signed-off-by: Sami Tolvanen Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Kees Cook Link: https://lkml.kernel.org/r/20201113183126.1239404-1-samitolvanen@google.com Signed-off-by: Sasha Levin --- arch/x86/events/intel/cstate.c | 6 +++--- arch/x86/events/intel/uncore.c | 4 ++-- arch/x86/events/intel/uncore.h | 12 ++++++------ arch/x86/events/rapl.c | 14 +------------- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/arch/x86/events/intel/cstate.c b/arch/x86/events/intel/cstate.c index 442e1ed4acd49..4eb7ee5fed72d 100644 --- a/arch/x86/events/intel/cstate.c +++ b/arch/x86/events/intel/cstate.c @@ -107,14 +107,14 @@ MODULE_LICENSE("GPL"); #define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format) \ -static ssize_t __cstate_##_var##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, \ +static ssize_t __cstate_##_var##_show(struct device *dev, \ + struct device_attribute *attr, \ char *page) \ { \ BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ return sprintf(page, _format "\n"); \ } \ -static struct kobj_attribute format_attr_##_var = \ +static struct device_attribute format_attr_##_var = \ __ATTR(_name, 0444, __cstate_##_var##_show, NULL) static ssize_t cstate_get_attr_cpumask(struct device *dev, diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index d5c6d3b340c50..803601baa753d 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -92,8 +92,8 @@ end: return map; } -ssize_t uncore_event_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) +ssize_t uncore_event_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct uncore_event_desc *event = container_of(attr, struct uncore_event_desc, attr); diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index 105fdc69825eb..c5744783e05d0 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -157,7 +157,7 @@ struct intel_uncore_box { #define UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS 2 struct uncore_event_desc { - struct kobj_attribute attr; + struct device_attribute attr; const char *config; }; @@ -179,8 +179,8 @@ struct pci2phy_map { struct pci2phy_map *__find_pci2phy_map(int segment); int uncore_pcibus_to_physid(struct pci_bus *bus); -ssize_t uncore_event_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf); +ssize_t uncore_event_show(struct device *dev, + struct device_attribute *attr, char *buf); static inline struct intel_uncore_pmu *dev_to_uncore_pmu(struct device *dev) { @@ -201,14 +201,14 @@ extern int __uncore_max_dies; } #define DEFINE_UNCORE_FORMAT_ATTR(_var, _name, _format) \ -static ssize_t __uncore_##_var##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, \ +static ssize_t __uncore_##_var##_show(struct device *dev, \ + struct device_attribute *attr, \ char *page) \ { \ BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ return sprintf(page, _format "\n"); \ } \ -static struct kobj_attribute format_attr_##_var = \ +static struct device_attribute format_attr_##_var = \ __ATTR(_name, 0444, __uncore_##_var##_show, NULL) static inline bool uncore_pmc_fixed(int idx) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index 67b411f7e8c41..abaed36212250 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -93,18 +93,6 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = { * any other bit is reserved */ #define RAPL_EVENT_MASK 0xFFULL - -#define DEFINE_RAPL_FORMAT_ATTR(_var, _name, _format) \ -static ssize_t __rapl_##_var##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, \ - char *page) \ -{ \ - BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \ - return sprintf(page, _format "\n"); \ -} \ -static struct kobj_attribute format_attr_##_var = \ - __ATTR(_name, 0444, __rapl_##_var##_show, NULL) - #define RAPL_CNTR_WIDTH 32 #define RAPL_EVENT_ATTR_STR(_name, v, str) \ @@ -441,7 +429,7 @@ static struct attribute_group rapl_pmu_events_group = { .attrs = attrs_empty, }; -DEFINE_RAPL_FORMAT_ATTR(event, event, "config:0-7"); +PMU_FORMAT_ATTR(event, "config:0-7"); static struct attribute *rapl_formats_attr[] = { &format_attr_event.attr, NULL, -- 2.27.0