Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp384181iob; Fri, 13 May 2022 03:59:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE8vpirIppgGFjohhoWCVyAsuT1WjxGLXZn5fXtZ0JxlfUOBzl67CzA9Jjfrp79cQmXNzb X-Received: by 2002:a17:902:e5d2:b0:15e:9467:187 with SMTP id u18-20020a170902e5d200b0015e94670187mr4046531plf.123.1652439592972; Fri, 13 May 2022 03:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652439592; cv=none; d=google.com; s=arc-20160816; b=WCWx+hWiFBF6X8edIG1RuFOVwtBDjTfMV6T8DTgKBM06yT/9DEFuHnYvt9Xj08jMAm ncn4VI9Mt61iGewiWmnooIQr/7lJSQMqXW/lmtngaQ3h6/h8xbw0YgYK01teV6+/6PVl 2NXTFgquLRr/7Mdcah5wdTJm+9d54HawrdJAhRVnptK7nnzWEKwoQKylnH2CM4ACbqQW gghd0yA2RnOzPPQGXhr34n678f6FpNsP8SyI3NuwWzoG8tRNWmAo/ss9IQ8SugiRCgbb B6EtWU/ofd56n6TjkCnPQ9mDTOY7vHWjT7q1/fheAsRZBMBHLKGvV5AJln2sw7qylSv9 iGAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=oyDk/I1j+9LzIGI5Q2oTO3q2eMcQDl2vfIcWICh0tGM=; b=jq2ap62DxnDauPeFtF8EfS2uv/mTA2K3eUBt2lw/b/UG8L3YGL91YCXo17Zm+kcPW0 57xuqdAYbPvQJONMaA2VcL4fxRcA7222rjdQ5nADwqug41ZphTs++6g5ddJbYTC0QJhI gtT7GY9xXpX6ic4Lv12aTHt0YTV9TEA0MB/W6esutr7gCCufdNxuEvdQo6gLlAGlZ5Jn 91+4/Cjr2ojsiQ+UWTQEoDhm+RVB5dpU142qRLCgVLvt7TNZ9g21UYMzY/z0WDwiz59o zPmjA6Q1ArSJRdQYrtCqA9flU43xXDfqFpW6pxXlClXJTQetQApEW0BqrfQPDaY3fUUe /2+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hzwtz6Au; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d20-20020a656b94000000b003aa6b7e91ebsi2650638pgw.629.2022.05.13.03.59.40; Fri, 13 May 2022 03:59:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hzwtz6Au; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378637AbiEMKJM (ORCPT + 99 others); Fri, 13 May 2022 06:09:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350059AbiEMKJL (ORCPT ); Fri, 13 May 2022 06:09:11 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A86566B09B for ; Fri, 13 May 2022 03:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652436550; x=1683972550; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=5i3oSmoCYG0z99aFLyfO1/Lffb6G3ID6DMGfB1vnRWE=; b=Hzwtz6Au5ZteRNGz8p1ybV3hyIc3qYJnYFQ7+k/iD6lOffXQsyafwzrk XcZm1qPYpciB72tr+qZGLYsIFuYc2DECSpGmRXLPePqr0BIFJuvvRQd/s sFGNnkBQKj3RQ551F98QT1vL4NbVGlbJ5FUamwwOhrjV3viAf1YhtDqzE DTHB5K6epK5vLXtyCAxlXnTpvD9o0TjVer4w/EBwl3xZmTyYGxi7xQsVj HX1IwFpferGM37SoxGqorMg8VQrVyMMt+tYeNiX98vatKhy9vebQqnAT2 0vUHDvopyMixGFfMMsHcwf5RxDGk6jaSP32ugAUEC6W7G+MRGHklS2HAr g==; X-IronPort-AV: E=McAfee;i="6400,9594,10345"; a="257815399" X-IronPort-AV: E=Sophos;i="5.91,221,1647327600"; d="scan'208";a="257815399" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2022 03:08:55 -0700 X-IronPort-AV: E=Sophos;i="5.91,221,1647327600"; d="scan'208";a="554167026" Received: from cpazx-mobl.ger.corp.intel.com (HELO [10.213.209.239]) ([10.213.209.239]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2022 03:08:52 -0700 Message-ID: Date: Fri, 13 May 2022 11:08:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH] drm/i915: Fix CFI violation with show_dynamic_id() Content-Language: en-US To: Nathan Chancellor , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi Cc: Sami Tolvanen , Kees Cook , Nick Desaulniers , Tom Rix , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, patches@lists.linux.dev References: <20220512211704.3158759-1-nathan@kernel.org> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc In-Reply-To: <20220512211704.3158759-1-nathan@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, NICE_REPLY_A,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/05/2022 22:17, Nathan Chancellor wrote: > When an attribute group is created with sysfs_create_group(), the > ->sysfs_ops() callback is set to kobj_sysfs_ops, which sets the ->show() > callback to kobj_attr_show(). kobj_attr_show() uses container_of() to > get the ->show() callback from the attribute it was passed, meaning the > ->show() callback needs to be the same type as the ->show() callback in > 'struct kobj_attribute'. > > However, show_dynamic_id() has the type of the ->show() callback in > 'struct device_attribute', which causes a CFI violation when opening the > 'id' sysfs node under drm/card0/metrics. This happens to work because > the layout of 'struct kobj_attribute' and 'struct device_attribute' are > the same, so the container_of() cast happens to allow the ->show() > callback to still work. > > Change the type of show_dynamic_id() to match the ->show() callback in > 'struct kobj_attributes' and update the type of sysfs_metric_id to > match, which resolves the CFI violation. > > Fixes: f89823c21224 ("drm/i915/perf: Implement I915_PERF_ADD/REMOVE_CONFIG interface") > Signed-off-by: Nathan Chancellor Merged to drm-intel-gt-next, thanks for the fix and reviews! Regards, Tvrtko > --- > drivers/gpu/drm/i915/i915_perf.c | 4 ++-- > drivers/gpu/drm/i915/i915_perf_types.h | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c > index 0a9c3fcc09b1..1577ab6754db 100644 > --- a/drivers/gpu/drm/i915/i915_perf.c > +++ b/drivers/gpu/drm/i915/i915_perf.c > @@ -4050,8 +4050,8 @@ static struct i915_oa_reg *alloc_oa_regs(struct i915_perf *perf, > return ERR_PTR(err); > } > > -static ssize_t show_dynamic_id(struct device *dev, > - struct device_attribute *attr, > +static ssize_t show_dynamic_id(struct kobject *kobj, > + struct kobj_attribute *attr, > char *buf) > { > struct i915_oa_config *oa_config = > diff --git a/drivers/gpu/drm/i915/i915_perf_types.h b/drivers/gpu/drm/i915/i915_perf_types.h > index 473a3c0544bb..05cb9a335a97 100644 > --- a/drivers/gpu/drm/i915/i915_perf_types.h > +++ b/drivers/gpu/drm/i915/i915_perf_types.h > @@ -55,7 +55,7 @@ struct i915_oa_config { > > struct attribute_group sysfs_metric; > struct attribute *attrs[2]; > - struct device_attribute sysfs_metric_id; > + struct kobj_attribute sysfs_metric_id; > > struct kref ref; > struct rcu_head rcu; > > base-commit: 7ecc3cc8a7b39f08eee9aea7b718187583342a70