Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4599800pxj; Wed, 12 May 2021 09:00:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTE9f3sF5W1ODkwRFnbf4BhoHOuTPJZFEYe+H5WAzQ5HW0mpigT4g8qk+IEAei36sH1PJc X-Received: by 2002:a17:906:58cd:: with SMTP id e13mr15242083ejs.207.1620835245093; Wed, 12 May 2021 09:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835245; cv=none; d=google.com; s=arc-20160816; b=CPg9WwXdxG/11H5qcZwkq3Aaz4E9RGFdtdcmyiRtWotTv6Bth3LbVgkArAJidUnT1A iJb+pvVEh2sHHgnQ/qW2kRLB6bLm2RSjjzTMTGGxHFo5TcJ7gPUrXV7e01GLJe9PaehK ZjIJ2LpcN3cAIEg/mbODOj5Nbr89eRjasqEmA0eM627vvyJmVVYYA1hRGdR2U8Mni2O7 t+kHdjPKWyTxmD2ezGCFqy1IUpE4QR5gds6X9Njb/feDuSIdwZ4/QYnI6SC2ehniW+Mc OqNXRF4Y8pMrW4qmMi5lTakDgT0XyNl3zsjYPrgj12vPjLIXSlY5b+Au0e6+hCqh9wUK SIvw== 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=q7RvfqebuU944X+0wwZaXlX1A1aIcujECPbcbxDH6tc=; b=tsxthEPI/sNZXKNmt9z5wez0AXnyIFJwlyNQWkTV+7oLvZkmIRibwA3IwkZIkO3ExJ 3fftlvOompQuPFvSVaUBvqeI3Pg014fT/gQgXPSiNq+C3xcij+9Hj5C3sr6huZ6YyG4O 30mJlzG+kmTXiEopI77vb6ls/zgY0uLUNKFVuL3m57vLNSWcftbnKxtFOqYECRirOe4u oFdVnlapdEp+7q+hf4rJ3mJV5Piex8HNlmq/DF+hX5bu5RtoND0lAZcnFBcUPMSjBKYi cqLsImkICRwiDw1okielT254ERP3SJoLl2IcDuNzsLVBCtjfENH9T70vVdds37B86AdV D0bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RqGlqjvk; 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 i17si85986edt.91.2021.05.12.09.00.20; Wed, 12 May 2021 09:00:45 -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=RqGlqjvk; 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 S234871AbhELP7A (ORCPT + 99 others); Wed, 12 May 2021 11:59:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:38508 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235474AbhELP2I (ORCPT ); Wed, 12 May 2021 11:28:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F0C3B616ED; Wed, 12 May 2021 15:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832388; bh=EFzdeRfP/X2uieP6ur3M6VsCkAY+gw7saZybeenXfGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RqGlqjvkSGcxi75P+ZPM5Sj9W+ZMwEi8ca5/EBvgC/z6uPPKL6Bv2odUnD+1+Au7B JKUt4nn+zOA0Wp9K7Ss1+NvWmeu0j5IrL87VDISX3fACq3IfBV+YCQhENAZ3S/TbG+ CyBTSRj/2ez3arXXglhhsvvxp5BErgPtm+tLH6XQ= 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 5.10 225/530] ACPI: CPPC: Replace cppc_attr with kobj_attribute Date: Wed, 12 May 2021 16:45:35 +0200 Message-Id: <20210512144827.226892673@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 7a99b19bb893..0a2da06e9d8b 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 500ULL -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}; \ @@ -160,7 +152,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