From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Michal Hocko <mhocko@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Masami Hiramatsu <mhiramat@kernel.org>,
Ulf Hansson <ulf.hansson@linaro.org>, Gary R Hook <ghook@amd.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>
Subject: Re: [PATCH 2/2] debugfs: return error values, not NULL
Date: Wed, 23 Jan 2019 14:40:21 +0100 [thread overview]
Message-ID: <20190123134021.GB24700@kroah.com> (raw)
In-Reply-To: <20190123130917.GZ4087@dhcp22.suse.cz>
On Wed, Jan 23, 2019 at 02:09:17PM +0100, Michal Hocko wrote:
> On Wed 23-01-19 14:00:57, Greg KH wrote:
> > On Wed, Jan 23, 2019 at 01:40:24PM +0100, Michal Hocko wrote:
> > > On Wed 23-01-19 13:26:26, Greg KH wrote:
> > > > On Wed, Jan 23, 2019 at 01:13:50PM +0100, Michal Hocko wrote:
> > > > > On Wed 23-01-19 12:55:35, Greg KH wrote:
> > > > > > On Wed, Jan 23, 2019 at 12:06:28PM +0100, Michal Hocko wrote:
> > > > > > > On Wed 23-01-19 11:28:14, Greg KH wrote:
> > > > > > > > When an error happens, debugfs should return an error pointer value, not
> > > > > > > > NULL. This will prevent the totally theoretical error where a debugfs
> > > > > > > > call fails due to lack of memory, returning NULL, and that dentry value
> > > > > > > > is then passed to another debugfs call, which would end up succeeding,
> > > > > > > > creating a file at the root of the debugfs tree, but would then be
> > > > > > > > impossible to remove (because you can not remove the directory NULL).
> > > > > > > >
> > > > > > > > So, to make everyone happy, always return errors, this makes the users
> > > > > > > > of debugfs much simpler (they do not have to ever check the return
> > > > > > > > value), and everyone can rest easy.
> > > > > > >
> > > > > > > How come this is safe at all? Say you are creating a directory by
> > > > > > > debugfs_create_dir and then feed the return value to debugfs_create_files
> > > > > > > as a parent. In case of error you are giving it an invalid pointer and
> > > > > > > likely blow up unless I miss something.
> > > > > >
> > > > > > debugfs_create_files checks for invalid parents and will just refuse to
> > > > > > create the file. It's always done that.
> > > > >
> > > > > I must be missing something because debugfs_create_files does
> > > > > d_inode(parent)->i_private = data;
> > > > > as the very first thing and that means that it dereferences an invalid
> > > > > pointer right there.
> > > >
> > > > debugfs_create_file() -> __debugfs_create_file() -> start_creating()
> > > > and that function checks if parent is an error, which it aborts on, or
> > > > if it is NULL, it sets parent to a valid value:
> > > >
> > > > /* If the parent is not specified, we create it in the root.
> > > > * We need the root dentry to do this, which is in the super
> > > > * block. A pointer to that is in the struct vfsmount that we
> > > > * have around.
> > > > */
> > > > if (!parent)
> > > > parent = debugfs_mount->mnt_root;
> > > >
> > > > I don't see any line that looks like:
> > > > > d_inode(parent)->i_private = data;
> > > > in Linus's tree right now, what kernel version are you referring to?
> > >
> > > Ohh, my bad. I have looked at debugfs_create_files which is a mq helper
> > > around debugfs_create_file. But that is a good example why this patch is
> > > dangerous anyway. blk_mq_debugfs_register simply checks for NULL and
> > > debugfs_create_files doesn't expect ERR_PTR here. So you would have to
> > > check each and every user to make sure you can do that.
> >
> > Ah, I already have that patch in my "to add a proper changelog" queue,
> > it's below and fixes that problem.
>
> OK, fair enough. I am just wondering how many more gems like that are
> lurking there. Do not get me wrong but a broken error handling is rarely
> fixed by removing it.
I think you all are the "lucky" one here :)
I did audit the whole kernel tree already, with the exception of the gpu
drivers, as they are even more insane than block drivers...
> And Cc: stable is completely inappropriate IMNSHO. This is just adding a
> risk without a large benefit.
What risk? Again, the _ONLY_ way that NULL is returned here is if you
are out of memory when you try to create that debugfs file/directory.
Given that we usually don't even fail small kmallocs, I doubt this can
even ever happen.
> Moreover all these changes should be posted in a single patch thread so
> that everybody can see the final outcome.
No one wants to see a 200+ patch thread and be cc:ed on them all.
thanks,
greg k-h
next prev parent reply other threads:[~2019-01-23 13:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-23 10:27 [PATCH 1/2] debugfs: fix debugfs_rename parameter checking Greg Kroah-Hartman
2019-01-23 10:28 ` [PATCH 2/2] debugfs: return error values, not NULL Greg Kroah-Hartman
2019-01-23 10:29 ` Greg Kroah-Hartman
2019-01-23 10:31 ` Greg Kroah-Hartman
2019-01-23 11:06 ` Michal Hocko
2019-01-23 11:55 ` Greg Kroah-Hartman
2019-01-23 12:13 ` Michal Hocko
2019-01-23 12:26 ` Greg Kroah-Hartman
2019-01-23 12:40 ` Michal Hocko
2019-01-23 13:00 ` Greg Kroah-Hartman
2019-01-23 13:09 ` Michal Hocko
2019-01-23 13:40 ` Greg Kroah-Hartman [this message]
2019-01-23 13:49 ` Greg Kroah-Hartman
2019-01-23 13:54 ` Michal Hocko
2019-01-23 21:32 ` Sebastian Andrzej Siewior
2019-01-24 2:26 ` Masami Hiramatsu
2019-01-28 13:55 ` Masami Hiramatsu
2019-01-28 16:04 ` Greg Kroah-Hartman
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=20190123134021.GB24700@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=ghook@amd.com \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mhocko@kernel.org \
--cc=ulf.hansson@linaro.org \
/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