Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp979647iob; Fri, 13 May 2022 18:25:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8DpNNQ75Dx7lzLdilvfhEl4gJzmr0fkhr/HDS6uYTTHMHj3olQ5oJlGRzm9/NTugB/4EL X-Received: by 2002:a7b:ce95:0:b0:393:fbe5:32a7 with SMTP id q21-20020a7bce95000000b00393fbe532a7mr6580897wmj.123.1652491538844; Fri, 13 May 2022 18:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652491538; cv=none; d=google.com; s=arc-20160816; b=Q5coRJh+aYEFN6jxMjCraTbZj39XNwyWR1eEWzRapS4rQKHsKoisWC6HfJt22oJr3m vGgK+fXxV2RfAsAFhVhJdsxTqmbE/KqtwR2DaBLeQ++ursFVBODbvFlVIXjs1tbNKMYc 33RVbAK6/3KL8BEeVodF2cf0a44t4z6S+qVqK14/nZOCqcdi6cTY1Of5ogZuhgwehg0D b6Te7FrG8N6X9JZeZxATtT1Ub1VRzyK+W4BD07TQ6ES3r+o1owiJczwGbAwPfVq5DQVN pll4GFUxQFOYTuJC1MsPPNLg7RDsjg7KhJT5wh8T2MP4M9ofizMvv6de1qCeH5L7jfDn R6Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3GME8g6CPueWMd7lO8qXn1DRp2ceHlUdCzpOykCHbrg=; b=iReqRxdzswdyZ+9gdKu+LbDzayoTFzewOvMZoqxf5wFqwgx/fDNngRTjBmD0/Eg4// RDzmf5XZoqC62mDC1f9/8pktQuhkdDKx0c8D/YJwZtS76P0xeDWO7qqUUsVLq762AgTL 34zo4EWp+R7IF5WMWH4jXZongPIeYDeXvEWofcTx3XSQ+3tSRnfzzPGpiP0As6oeGBqc 1WhiREIf3/i8vYQg4L0frDn1mO2GvjeQjX2fn0rkBDv2S1xQGaCAaA5629Jam/gdcr5F j2upzbCBC/43F2z1XcppQ5tGx6zE44+bTmu9tvpcELZkAU/yY6vYPzn6piRWWhiMDWlq mCxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sZeZsptj; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o9-20020a05600c510900b00393fdb36bbbsi8823832wms.210.2022.05.13.18.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:25:38 -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=@google.com header.s=20210112 header.b=sZeZsptj; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 27BC23DEAA6; Fri, 13 May 2022 16:54:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358728AbiELVbf (ORCPT + 99 others); Thu, 12 May 2022 17:31:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358732AbiELVbd (ORCPT ); Thu, 12 May 2022 17:31:33 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04B113E0C2 for ; Thu, 12 May 2022 14:31:31 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id j84so1301320ybc.3 for ; Thu, 12 May 2022 14:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3GME8g6CPueWMd7lO8qXn1DRp2ceHlUdCzpOykCHbrg=; b=sZeZsptj07txPT3pe6bg85WLBogL/niFdujvXhGmvGHvUMdf+ubK/UMpNHCLyogLwJ 1SzO61ddJPTl2rtfw/kEWCzbP/eORv0uCHNC9PQeJyNGrGAE73x2lB0kWBr2Kjmq3xRa mHwmaWFkL87Lq1cgfh194/MR4V/+H09KgB3y8gzFiALIbiGBD1RimwncOW3qBHBZ2PVs UJ6FI/VP/MEHjwSS79k9qDB+GAXe0Ehg7pg7yN/vCBgUpTkurP3pNm1JUOvBj2epSt4W zK35VaXeUyV2ai5LhbEjWsjFjQ7WQtGm92S5pR09fzSj8A5IT67/CPetqREViJP8tMHW dVyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3GME8g6CPueWMd7lO8qXn1DRp2ceHlUdCzpOykCHbrg=; b=hMKaCiyiWwOC25Z7bKOA1D/9KbPrzhNbD4iel3dEp4Y7T2yAvOvEpZLR/xT/1akBFc +9tUaRpO2VmR8qci7XG4wmGHwj/oeCpZUXAsXcPk2sRCVaPYU5EpDgvCRCcE5wAz+g10 CI+rTwP8mtFGNs2qH4nwmIhUNKpjZspRrV9MncmyZSibXuO4DQ7pbvpx4hvYW1XvGsht 7ydakftTuIRFSZc0jsStQLC/nXKNiv57FS+qD7aRgnvWXMSM2fQy3AmaNKcg0XC+2JuL EWxi72GsDj7/g55US4J6uIUHid11uj71HEUrvWqBNFzTkO/3tmnU1Kb3L+/1iOgEaru0 XzQQ== X-Gm-Message-State: AOAM533iVUSwKOGpUAEMDG0yhxtCEOEYdzu7arlfgxvieH7X2kybRzya 8VxHaWqm/BKbz9/aY6LmQlw8P5rQTru5iMYnmiHKqg== X-Received: by 2002:a25:84c3:0:b0:64a:de2c:2b75 with SMTP id x3-20020a2584c3000000b0064ade2c2b75mr1889370ybm.70.1652391089597; Thu, 12 May 2022 14:31:29 -0700 (PDT) MIME-Version: 1.0 References: <20220512211704.3158759-1-nathan@kernel.org> In-Reply-To: <20220512211704.3158759-1-nathan@kernel.org> From: Sami Tolvanen Date: Thu, 12 May 2022 14:30:53 -0700 Message-ID: Subject: Re: [PATCH] drm/i915: Fix CFI violation with show_dynamic_id() To: Nathan Chancellor Cc: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Kees Cook , Nick Desaulniers , Tom Rix , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, LKML , llvm@lists.linux.dev, patches@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Thu, May 12, 2022 at 2:17 PM 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 > --- > 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; This looks correct to me. Thanks for testing this and fixing the issue! Reviewed-by: Sami Tolvanen Sami