[PATCH v2] tomoyo: Don't check open/getattr permission on sockets.

From: Tetsuo Handa
Date: Sat Jun 22 2019 - 00:46:28 EST


On 2019/06/19 5:49, Al Viro wrote:
> On Sun, Jun 16, 2019 at 03:49:00PM +0900, Tetsuo Handa wrote:
>> Hello, Al.
>>
>> Q1: Do you agree that we should fix TOMOYO side rather than SOCKET_I()->sk
>> management.
>
> You do realize that sockets are not unique in that respect, right?
> All kinds of interesting stuff can be accessed via /proc/*/fd/*, and
> it _can_ be closed under you. So I'd suggest checking how your code
> copes with similar for pipes, FIFOs, epoll, etc., accessed that way...

I know all kinds of interesting stuff can be accessed via /proc/*/fd/*,
and it _can_ be closed under me.

Regarding sockets, I was accessing "struct socket" memory and
"struct sock" memory which are outside of "struct inode" memory.

But regarding other objects, I am accessing "struct dentry" memory,
"struct super_block" memory and "struct inode" memory. I'm expecting
that these memory can't be kfree()d as long as "struct path" holds
a reference. Is my expectation correct?

>
> We are _not_ going to be checking that in fs/open.c - the stuff found
> via /proc/*/fd/* can have the associated file closed by the time
> we get to calling ->open() and we won't know that until said call.

OK. Then, fixing TOMOYO side is the correct way.

>
>> Q2: Do you see any problem with using f->f_path.dentry->d_inode ?
>> Do we need to use d_backing_inode() or d_inode() ?
>
> Huh? What's wrong with file_inode(f), in the first place? And
> just when can that be NULL, while we are at it?

Oh, I was not aware of file_inode(). Thanks.

>
>>> static int tomoyo_inode_getattr(const struct path *path)
>>> {
>>> + /* It is not safe to call tomoyo_get_socket_name(). */
>>> + if (path->dentry->d_inode && S_ISSOCK(path->dentry->d_inode->i_mode))
>>> + return 0;
>
> Can that be called for a negative?
>

I check for NULL when I'm not sure it is guaranteed to hold a valid pointer.
You meant "we are sure that path->dentry->d_inode is valid", don't you?

By the way, "negative" associates with IS_ERR() range. I guess that
"NULL" is the better name...

Anyway, here is V2 patch.