Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp450385pxj; Thu, 20 May 2021 13:13:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2PhSHW2j8FWBRMgv5iIAlW0nYeK82Pr3Vtd3lPLTWUgRMnrS1Z4HigV0yOfBiqUtm0hEL X-Received: by 2002:a5d:9643:: with SMTP id d3mr6980974ios.6.1621541628244; Thu, 20 May 2021 13:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621541628; cv=none; d=google.com; s=arc-20160816; b=HokSPzNDow38Dnhe4irgIRlbhdLgaswEYTuAsgq+searekBJQxonZvkYmct6Ubtqdr reIY2cMqNXjqhwUXY6cRKcPiJsN2Q1kDxjnqgBLHouK9HTEqU1/zzacGzWqG7SMV1vSo tJOr7VEgVmbSBZ7SOKG+gLkR4UapG0Wi1cwXLe2shxceWdo405JY8rlbe5n9e0UdJmGt jXrV3vmEHyWd5sokAElDds8to+BqVtPP3NfWQW156giJTg2h4GR19VqMANdLzQcm+JUI bdw9THWIie1yzKSjmIDmgCML7MnoK0IdHqjQ5TUVkN6s/ySizJ5id1WHWoXi7ToOa/yS UW3A== 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=H4RqZ9SWbQgxj1BXJRs83TON3D++enSgiyKeTv0318g=; b=bW6CZmcMRRGgqp9LdlDkMvJRFvuCO9hfr5z+Ax5og4YP1EuF4PNz0pucG/hSGUttHQ f9Wfk3xVCNzhOVGFYF+js2n0ScYyOLIkptPCow3PZ/mdizUQOtb0QZrBSt9jRapiae2K Wq2iE8IZkZLNsSmEHlm0h4lJFQu02jyavclBXpBYxhkuO+EKGgRpm3yhbYfCy9SZBULJ B3fruHLwPFIQ+8rsbBzIwRFDN6PDwTgiTShlXt4NaeGRZve1fslmXS6ZQl+vIdbyitpl TR1nXi05py8Z1RRH3v4qIJgL6VCPS+uboqft+eV4kL0tM1JACv1Zk/ISmOpIOmvyCluD lWuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aHs2+SvX; 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 g2si3374066jaj.107.2021.05.20.13.13.34; Thu, 20 May 2021 13:13:48 -0700 (PDT) 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=aHs2+SvX; 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 S237919AbhETKrM (ORCPT + 99 others); Thu, 20 May 2021 06:47:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:60392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237297AbhETKbb (ORCPT ); Thu, 20 May 2021 06:31:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3AA15619A5; Thu, 20 May 2021 09:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504327; bh=ABPAIq8gvkqnkWTpQasrnrVOUKDHwcSujkDgWZ5I+8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aHs2+SvXe6dxi151vc0Y+vTm+Vm6qH+w+RxLPdAZUCBrGh+LFmtmQwiQhoLdRP0XL wTvwP4sv+ItyJ3KsBwFBOJf6HkUNc/7eWuvPwflvl/pzNQrwLYempvjbrIDrAwMxin cVKPCn1ysHgpJjfGn0RxENcCX36iLP8BRESIGrb8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 4.14 168/323] ACPI: CPPC: Replace cppc_attr with kobj_attribute Date: Thu, 20 May 2021 11:21:00 +0200 Message-Id: <20210520092125.862394272@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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: Nathan Chancellor [ Upstream commit 2bc6262c6117dd18106d5aa50d53e945b5d99c51 ] All of the CPPC sysfs show functions are called via indirect call in kobj_attr_show(), where they should be of type ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, char *buf); because that is the type of the ->show() member in 'struct kobj_attribute' but they are actually of type ssize_t (*show)(struct kobject *kobj, struct attribute *attr, char *buf); because of the ->show() member in 'struct cppc_attr', resulting in a Control Flow Integrity violation [1]. $ cat /sys/devices/system/cpu/cpu0/acpi_cppc/highest_perf 3400 $ dmesg | grep "CFI failure" [ 175.970559] CFI failure (target: show_highest_perf+0x0/0x8): As far as I can tell, the only difference between 'struct cppc_attr' and 'struct kobj_attribute' aside from the type of the attr parameter is the type of the count parameter in the ->store() member (ssize_t vs. size_t), which does not actually matter because all of these nodes are read-only. Eliminate 'struct cppc_attr' in favor of 'struct kobj_attribute' to fix the violation. [1]: https://lore.kernel.org/r/20210401233216.2540591-1-samitolvanen@google.com/ Fixes: 158c998ea44b ("ACPI / CPPC: add sysfs support to compute delivered performance") Link: https://github.com/ClangBuiltLinux/linux/issues/1343 Signed-off-by: Nathan Chancellor Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/acpi/cppc_acpi.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 732549ee1fe3..5b2e58cbeb35 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -118,23 +118,15 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr); */ #define NUM_RETRIES 500 -struct cppc_attr { - struct attribute attr; - ssize_t (*show)(struct kobject *kobj, - struct attribute *attr, char *buf); - ssize_t (*store)(struct kobject *kobj, - struct attribute *attr, const char *c, ssize_t count); -}; - #define define_one_cppc_ro(_name) \ -static struct cppc_attr _name = \ +static struct kobj_attribute _name = \ __ATTR(_name, 0444, show_##_name, NULL) #define to_cpc_desc(a) container_of(a, struct cpc_desc, kobj) #define show_cppc_data(access_fn, struct_name, member_name) \ static ssize_t show_##member_name(struct kobject *kobj, \ - struct attribute *attr, char *buf) \ + struct kobj_attribute *attr, char *buf) \ { \ struct cpc_desc *cpc_ptr = to_cpc_desc(kobj); \ struct struct_name st_name = {0}; \ @@ -157,7 +149,7 @@ show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, reference_perf); show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time); static ssize_t show_feedback_ctrs(struct kobject *kobj, - struct attribute *attr, char *buf) + struct kobj_attribute *attr, char *buf) { struct cpc_desc *cpc_ptr = to_cpc_desc(kobj); struct cppc_perf_fb_ctrs fb_ctrs = {0}; -- 2.30.2