Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp666246pxy; Wed, 5 May 2021 10:43:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNeyHe6VslsTWu5hx2nSHlfVBignpqCsL+dAsWWb/J2MUaD+eHu20ApceUgw8/ngkuE2ET X-Received: by 2002:a17:907:c13:: with SMTP id ga19mr16292950ejc.163.1620236617727; Wed, 05 May 2021 10:43:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620236617; cv=none; d=google.com; s=arc-20160816; b=hqOgg6U7qZf0oOrKZL5J56wsfRQyvtucfbhWyMqz3vs7cfQMNnVU3lo4jbUTgnN23w uGqzder1REV6r9I4zPkjLxr2s+r6rHffWw/s6z8onAcgw7qpWyksNyUnmYhvLPTh6gTx Eb/bh6qU19ajDmXc00z/IFcFA7oMZ3gFjd4GSnpCmPzXdr6TorngaBqDoW5c6I0UlUxl K24z+6XiM8AFTft+IihwLLM4Io/5LudL63oeXAllNoVEXLE941mD0kbLqrc5sPlKI+3v xkYQNQKNdRt5btS6XRO4QiZrQ/OSq3mr9d/UFEBifKI1myiLyXh+2k2H+gcnpLvMqjr7 xOfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=c+Pwa5We0eg0N+YQF1AFSXqY42ZWJ2hKuI5mjdc1ii0=; b=sXwZLOaaEtRvSa7vUSTeyFUytIuVci5ZQU88IPBlKLelfj+qyzEkM8oNeJWLQGhkCK VWzOUkLOwwp8MuXJwU7MQUG4u3NyafmlPNv4HWvHkdmJU7Mznp9YzuEcbvPGTWL89UvT 9Gm3igdGKp0QD3vQrAtD3893bMkJ6edqvou7IRpJfWbob9hAZQIZ0zD1TdY7fH8wBKNp K1UqfaTkxHpO3ew7TbK+GI1mEh2uOUJpueCnDhFzD8DZ7QrH+juApbAvBfFfITDGfGr3 lXj23unT0E7ITR9njQg4r6e7KGCM4tiuFbgM44Q1p4avn3WicrIPbf7mUjJKONHv7JSo K5+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AhWldoB3; 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 by7si34844edb.418.2021.05.05.10.43.14; Wed, 05 May 2021 10:43:37 -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=AhWldoB3; 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 S235969AbhEERnB (ORCPT + 99 others); Wed, 5 May 2021 13:43:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:38960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238904AbhEERk5 (ORCPT ); Wed, 5 May 2021 13:40:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B4BDE608FE; Wed, 5 May 2021 17:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620236399; bh=ZjWFsZx1U67ZQFN1wQdlYA9nKqiS+q/v3JEstpo4rD8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AhWldoB3roWUH6qAvHDRmFA/OCZIr7MxdQaxSH1aBPIFILc7cA8mJ6zPi+4jCTNV0 UJhgyF+qrx55YK9btsBBiZmE6O1+GOBLHCFp3U+jGeCpbg4IJri6a8VaddCv0Na3Iw TtLhk2xDP4hqdBVHF0+73qviCCeajeG05p7u4Mv0= Date: Wed, 5 May 2021 19:39:56 +0200 From: Greg KH To: Jason Gunthorpe Cc: Kees Cook , Nathan Chancellor , Doug Ledford , Leon Romanovsky , Parav Pandit , Sami Tolvanen , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: CFI violation in drivers/infiniband/core/sysfs.c Message-ID: References: <20210402195241.gahc5w25gezluw7p@archlinux-ax161> <202104021555.08B883C7@keescook> <20210402233018.GA7721@ziepe.ca> <202104021823.64FA6119@keescook> <20210404135713.GB7721@ziepe.ca> <20210505172916.GC2047089@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210505172916.GC2047089@ziepe.ca> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 05, 2021 at 02:29:16PM -0300, Jason Gunthorpe wrote: > On Wed, May 05, 2021 at 06:26:06PM +0200, Greg KH wrote: > > > They are in many places, for instance. > > > > > > int device_create_file(struct device *dev, > > > const struct device_attribute *attr) > > > > > > We loose the type safety when working with attribute arrays, and > > > people can just bypass the "proper" APIs to raw sysfs ones whenever > > > they like. > > > > > > It is fundamentally completely wrong to attach a 'struct > > > kobject_attribute' to a 'struct device' kobject. > > > > But it works because we are using C and we don't have RTTI :) > > > > Yes, it's horrid, but we do it because we "know" the real type that is > > being called here. That was an explicit design decision at the time. > > I think it is beyond horrid. Just so everyone is clear on what is > happening here.. > > RDMA has this: > > struct hw_stats_attribute { > struct attribute attr; > ssize_t (*show)(struct kobject *kobj, > struct attribute *attr, char *buf); > > And it has two kobject types, a struct device kobject and a ib_port > kobject. > > When the user invokes show on the struct device sysfs we have this > call path: > > dev_sysfs_ops > dev_attr_show() > struct device_attribute *dev_attr = to_dev_attr(attr); > ret = dev_attr->show(dev, dev_attr, buf); > show_hw_stats() > struct hw_stats_attribute *hsa = container_of(attr, struct hw_stats_attribute, attr) > > And from the ib_port kobject we have this one: > > port_sysfs_ops > port_attr_show() > struct port_attribute *port_attr = > container_of(attr, struct port_attribute, attr); > return port_attr->show(p, port_attr, buf); > show_hw_stats() > struct hw_stats_attribute *hsa = container_of(attr, struct hw_stats_attribute, attr) > > Then show_hw_stats() goes on to detect which call chain it uses so it > can apply the proper container of to the kobj: Wait, what? That's not how any of this was designed, you should not be "sharing" a callback of different types of objects, because: > > if (!hsa->port_num) > dev = container_of((struct device *)kobj, > struct ib_device, dev); > else > port = container_of(kobj, struct ib_port, kobj); Yeah, ick. No, that's not how this was designed or intended to be used. Why not just have 2 different show functions? thanks, greg k-h