Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4293765pxu; Tue, 1 Dec 2020 01:03:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpoQdMTaZqNxBwiAu5ZtFZ+C4dX5Q6wRPVMV9UFs8nMsGqIylcg8bHU9iVB1HBZY65j+EU X-Received: by 2002:a17:906:5a8b:: with SMTP id l11mr1887983ejq.99.1606813403294; Tue, 01 Dec 2020 01:03:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606813403; cv=none; d=google.com; s=arc-20160816; b=zXj658Z4g19YTs3QNCE4qkp2GWJ0BHTeFEvV2ncMXDcuk28EB3aNsL7UgtmKA4gSxp ihs2UJsJ6QTuCNQWasS2vRl9fny/Vgn5a/6XnbQEJBnIsUY9Les7yJKiVpRISGV4+kHO CjcidD82/6pz7F60Jf3wtRHrL2d0dbqu5Jpi6N+gof4PmKrsvetqMBBFQ6ybed/G0b8G ZRRHTYNMM1JM6lMw/t6gk49y1ywT31R/G335teGwpbxPXMId6rj6rB/t33Dw12q8ZisW 2wkY+R8c9SWnKPso8XZaAWFw1n11fciXpXUNumAAPa1vKeD+9QEvyxOU5xiPc78GgMLh 8WhA== 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=r8CZvQD+y+d76oCgTf6U4r/nWYIDKmYdaezYyGk9tUs=; b=ADL5Y7Z0HGHWIWag9ves1kw/8wjNxJ4mOI9RhOht48xj7DFYEslWX95BFwU/0rOu3j 8fOIlcwF1tgSqAwWLNMVp7BfuzwzJnpvQ6aY+gOJ3LRI5RF/RicgdrPzjk8Zh3WRqzqk wm+Dw1N/2QEDCL/0zujVyuRxtjv5FbbldlrRznkvj6JIV8fxdbup4qR3oRDCBpHfmwd6 bXK5CNhzuE+KRKHYV3kKML8psI0IhP81fSsfN61OP0pER8/5/9aDjnlSmRLNVsROI0h2 3sD3GiiIzuUyjyDYWlcguXIbWx3qYreyHy8wAm856omRR9AFL8oSXDP+Uta9Na8273OB zi3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="nq/fjUOd"; 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 w12si765472edf.161.2020.12.01.01.03.00; Tue, 01 Dec 2020 01:03:23 -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="nq/fjUOd"; 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 S2388191AbgLAI7r (ORCPT + 99 others); Tue, 1 Dec 2020 03:59:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:33962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387532AbgLAI7o (ORCPT ); Tue, 1 Dec 2020 03:59:44 -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 3CA622220B; Tue, 1 Dec 2020 08:59:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813162; bh=YZRoVfn7kdvzWAZKkCiULDpnioEOCNeIPjlBVUtxGto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nq/fjUOdTtblckWYXvZJz4hnr3nz4+uAQPYFxZO8VV3ZEmOVxFPDHS/Dn+TVqn5Zd hY9BX34MS4IaiwFnU+FlXNz0DYjJCQc8N5robX1uFW2JGWdaj4YhjLwkVmoON7gomD fhVNJj0hvSmxRgE5wgKTcpXqXFvHvRdlmCO0FARo= 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 4.14 25/50] perf/x86: fix sysfs type mismatches Date: Tue, 1 Dec 2020 09:53:24 +0100 Message-Id: <20201201084648.180871938@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084644.803812112@linuxfoundation.org> References: <20201201084644.803812112@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/rapl.c | 14 +------------- arch/x86/events/intel/uncore.c | 4 ++-- arch/x86/events/intel/uncore.h | 12 ++++++------ 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/arch/x86/events/intel/cstate.c b/arch/x86/events/intel/cstate.c index 59521c71c98a4..4ebeaa3c67100 100644 --- a/arch/x86/events/intel/cstate.c +++ b/arch/x86/events/intel/cstate.c @@ -99,14 +99,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/rapl.c b/arch/x86/events/intel/rapl.c index d36a5fac6a18b..7d3f861e31654 100644 --- a/arch/x86/events/intel/rapl.c +++ b/arch/x86/events/intel/rapl.c @@ -115,18 +115,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) \ @@ -548,7 +536,7 @@ static struct attribute_group rapl_pmu_events_group = { .attrs = NULL, /* patched at runtime */ }; -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, diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index c56cb37b88e33..4ad93871508cd 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -90,8 +90,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 4364191e7c6b2..ae4ab89e16c7d 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -125,7 +125,7 @@ struct intel_uncore_box { #define UNCORE_BOX_FLAG_CTL_OFFS8 1 /* event config registers are 8-byte apart */ struct uncore_event_desc { - struct kobj_attribute attr; + struct device_attribute attr; const char *config; }; @@ -137,8 +137,8 @@ struct pci2phy_map { struct pci2phy_map *__find_pci2phy_map(int segment); -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); #define INTEL_UNCORE_EVENT_DESC(_name, _config) \ { \ @@ -147,14 +147,14 @@ ssize_t uncore_event_show(struct kobject *kobj, } #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 unsigned uncore_pci_box_ctl(struct intel_uncore_box *box) -- 2.27.0