From: Greg KH <gregkh@linuxfoundation.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kees Cook <keescook@chromium.org>,
Nathan Chancellor <nathan@kernel.org>,
Doug Ledford <dledford@redhat.com>,
Leon Romanovsky <leon@kernel.org>,
Parav Pandit <parav@nvidia.com>,
Sami Tolvanen <samitolvanen@google.com>,
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
Date: Wed, 5 May 2021 19:39:56 +0200 [thread overview]
Message-ID: <YJLYbCIKgLCZlcOv@kroah.com> (raw)
In-Reply-To: <20210505172916.GC2047089@ziepe.ca>
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
next prev parent reply other threads:[~2021-05-05 17:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-02 19:52 CFI violation in drivers/infiniband/core/sysfs.c Nathan Chancellor
2021-04-02 23:03 ` Kees Cook
2021-04-02 23:30 ` Jason Gunthorpe
2021-04-03 1:29 ` Kees Cook
2021-04-04 13:57 ` Jason Gunthorpe
2021-05-05 16:26 ` Greg KH
2021-05-05 17:29 ` Jason Gunthorpe
2021-05-05 17:39 ` Greg KH [this message]
2021-04-03 6:55 ` Nathan Chancellor
2021-05-04 20:22 ` Jason Gunthorpe
2021-05-05 16:26 ` Greg KH
2021-05-05 20:08 ` Nathan Chancellor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YJLYbCIKgLCZlcOv@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=clang-built-linux@googlegroups.com \
--cc=dledford@redhat.com \
--cc=jgg@ziepe.ca \
--cc=keescook@chromium.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=parav@nvidia.com \
--cc=samitolvanen@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox