Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2209830iof; Tue, 7 Jun 2022 23:17:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOokpMxyrTPPg2fmnAPx4GP57g3C71sQUgBpXNdYLa5Gvc9M0dxwxOZ8VWl8O9QXInhJHl X-Received: by 2002:a63:1716:0:b0:3f2:52bc:b4f3 with SMTP id x22-20020a631716000000b003f252bcb4f3mr28173382pgl.610.1654669047555; Tue, 07 Jun 2022 23:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654669047; cv=none; d=google.com; s=arc-20160816; b=mJ7QIs50YcxMQXGHvk8c09QJkijwoDj7VukvudgOC7s5IzvfkdbZjrZWzOKMM98mUq /iLnUNPGVF3+MFnP4Aifi2sppiC4ioJ7q0+r9KDGp3e9qz0P+Z5TfdjsQI7+++IgTBgm Gq2LM1dadriBAKR5ssk3BOCSEZ5FyDXJLQhOYPCRcXOsGF69rgV6/P8cHsJBS/jniV/V OAtYCQCDb1e5fsJ1DpCtLcc7Ybcv/1HsnuERSbvasxtmTnCRD2Afu93ZjPleSC+cZkMT UA2OodHmHcAOyNgPDFV//v31NyTtTJMvmjPgaBwC0PvzCtpATfUruIEJrEcOZ60XtyLm jDgw== 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=ioHtfVwkUrwzB2fpSJ1IaOzd0IE0kBykhBwNiazRrXY=; b=jsWzoHSZthvcRhARPpuNEGN8IKdXjTYRHMG7Qhkm/bUBEcI1sphwuGpBGcWMHmJblY V2BqiaZjUTgR9SDLkn0KOwNsnIEpS3etRXgRIPY2IJTh++3DhTvT1zy8T++8wCk3pAyR Eo5P2HAifyqajpdZBXq6TCOxke73HVT0VRcxGxeDoTDLibqCN3zovgh6VBSAGE28YWcC ErrxDPSTViOqf0gpcgDqSWcvXH8RTrjhIenyAMYIrPXspYDLrJAqNYI2GQkacIMovQ9Y 9jzyrwWdFTk/grIk+RW3W/lTSoCp1qQ12pOFAqphX1zRgkazZjhmXM66hv4mcgD3pr73 ptlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XZL1iX5d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 205-20020a6300d6000000b003fdcf48369csi10001315pga.830.2022.06.07.23.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:17:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XZL1iX5d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F16B53D9FA2; Tue, 7 Jun 2022 22:38:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382437AbiFHBtu (ORCPT + 99 others); Tue, 7 Jun 2022 21:49:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381045AbiFGVri (ORCPT ); Tue, 7 Jun 2022 17:47:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EFEF2383E9; Tue, 7 Jun 2022 12:08:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E03AC61846; Tue, 7 Jun 2022 19:08:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED435C34115; Tue, 7 Jun 2022 19:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628885; bh=RyRsPx/V8rOFqBtsBmni5IwGrXX4dyf00pLYARTaC0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZL1iX5dJ/WN1V/4lM2dvjvFZZDi4l/MC92VxuPgBKlFZ/JZ/dCDTbQ0mL2QoCLMl tbXnNbqn0887nDqLEly/tOi831MR6/iNbJrzWhYZjw/iB7OcA0CKPxrYzNH99GIk5h jAlt4/bS54iuSeh/gYhbvG4GhKPfd5LN2fgYvjrQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , Kees Cook , Sami Tolvanen , Tvrtko Ursulin , Jani Nikula , Sasha Levin Subject: [PATCH 5.18 490/879] drm/i915: Fix CFI violation with show_dynamic_id() Date: Tue, 7 Jun 2022 19:00:08 +0200 Message-Id: <20220607165017.094433480@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Nathan Chancellor [ Upstream commit 58606220a2f1407a7516c547f09a1ba7b4350a73 ] 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 Reviewed-by: Kees Cook Reviewed-by: Sami Tolvanen Signed-off-by: Tvrtko Ursulin Link: https://patchwork.freedesktop.org/patch/msgid/20220513075136.1027007-1-tvrtko.ursulin@linux.intel.com (cherry picked from commit 18fb42db05a0b93ab5dd5eab5315e50eaa3ca620) Signed-off-by: Jani Nikula Signed-off-by: Sasha Levin --- 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; -- 2.35.1