Netdev Archive on lore.kernel.org
 help / Atom feed
* [RFC] apparently bogus logics in unix_find_other() since 2002
@ 2019-02-10  4:24 Al Viro
  2019-02-11  3:19 ` Al Viro
  2019-02-11 11:21 ` Solar Designer
  0 siblings, 2 replies; 3+ messages in thread
From: Al Viro @ 2019-02-10  4:24 UTC (permalink / raw)
  To: netdev; +Cc: Solar Designer, David Miller

	In "net/unix/af_unix.c: Set ATIME on socket inode" (back in
2002) we'd grown something rather odd in unix_find_other().  In the
original patch it was
                u=unix_find_socket_byname(sunname, len, type, hash);
-               if (!u)
+               if (u) {
+                       struct dentry *dentry;
+                       dentry = u->protinfo.af_unix.dentry;
+                       if (dentry)
+                               UPDATE_ATIME(dentry->d_inode);
+               } else
                        goto fail;

These days the code is

                u = unix_find_socket_byname(net, sunname, len, type, hash);
                if (u) {
                        struct dentry *dentry;
                        dentry = unix_sk(u)->path.dentry;
                        if (dentry)
                                touch_atime(&unix_sk(u)->path);
                } else  
                        goto fail;

but the logics is the same.  It's the abstract address case - we have
'\0' in sunname->sun_path[0].  How in hell could that possibly have
non-NULL ->path.dentry and what would it be?

Note that unix_find_socket_byname() returns non-NULL u here only if
u->addr->name->sun_path[0] is equal to sunname->sun_path[0], i.e.
'\0'.  There are only two places where we ever might assign non-NULL
to ->path.dentry:
        if (sun_path[0]) {
                addr->hash = UNIX_HASH_SIZE;
                hash = d_backing_inode(path.dentry)->i_ino & (UNIX_HASH_SIZE - 1);
                spin_lock(&unix_table_lock);
                u->path = path;
                list = &unix_socket_table[hash];
        } else {
in unix_bind() (in which case u->addr->name->sun_path[0] will not be '\0') and
        /* copy address information from listening to new sock*/
        if (otheru->addr) {
                refcount_inc(&otheru->addr->refcnt);
                newu->addr = otheru->addr;
        }
        if (otheru->path.dentry) {
                path_get(&otheru->path);
                newu->path = otheru->path;
        }
in unix_stream_connect().  And once ->addr is non-NULL, it's never changed,
and ->addr->name contents is never modified afterwards.  So we would have
to had the same condition (non-NULL ->path.dentry with '\0' in
->addr->name->sun_path[0]) at earlier point on the listener socket.

Looks like that should be impossible; what am I missing here?  Incidentally,
how can the quoted fragment in in unix_stream_connect() be reached with NULL
otheru->addr?  After all, otheru is unix_sock of a listener; how could
we possibly have found it if it had NULL ->addr?

Confused...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] apparently bogus logics in unix_find_other() since 2002
  2019-02-10  4:24 [RFC] apparently bogus logics in unix_find_other() since 2002 Al Viro
@ 2019-02-11  3:19 ` Al Viro
  2019-02-11 11:21 ` Solar Designer
  1 sibling, 0 replies; 3+ messages in thread
From: Al Viro @ 2019-02-11  3:19 UTC (permalink / raw)
  To: netdev; +Cc: Solar Designer, David Miller

On Sun, Feb 10, 2019 at 04:24:15AM +0000, Al Viro wrote:
> 
> Looks like that should be impossible; what am I missing here?  Incidentally,
> how can the quoted fragment in in unix_stream_connect() be reached with NULL
> otheru->addr?  After all, otheru is unix_sock of a listener; how could
> we possibly have found it if it had NULL ->addr?
> 
> Confused...

BTW, speaking of interesting corner cases in AF_UNIX: am I right assuming that
identical abstract names with different protocols are considered entirely
independent?  Where is that thing (== abstract namespace) documented, anyway?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] apparently bogus logics in unix_find_other() since 2002
  2019-02-10  4:24 [RFC] apparently bogus logics in unix_find_other() since 2002 Al Viro
  2019-02-11  3:19 ` Al Viro
@ 2019-02-11 11:21 ` Solar Designer
  1 sibling, 0 replies; 3+ messages in thread
From: Solar Designer @ 2019-02-11 11:21 UTC (permalink / raw)
  To: Al Viro; +Cc: netdev, David Miller

On Sun, Feb 10, 2019 at 04:24:22AM +0000, Al Viro wrote:
> 	In "net/unix/af_unix.c: Set ATIME on socket inode" (back in
> 2002) we'd grown something rather odd in unix_find_other().  In the
> original patch it was
>                 u=unix_find_socket_byname(sunname, len, type, hash);
> -               if (!u)
> +               if (u) {
> +                       struct dentry *dentry;
> +                       dentry = u->protinfo.af_unix.dentry;
> +                       if (dentry)
> +                               UPDATE_ATIME(dentry->d_inode);
> +               } else
>                         goto fail;

It's this commit:

https://github.com/dmgerman/linux-bitkeeper/commit/80cbc5b9c7393c4456236543ca1e639ea0841c19

There are two hunks in that patch: one after "if (sunname->sun_path[0])"
and the other after "else".  I just did some more digging and found the
private discussion of the time, as well as a previous revision of the
patch (against 2.2.21, whereas the committed one was against 2.4.x of
the same era).  Even the earliest revision I found already has both
hunks.  I couldn't find any discussion as to why the second hunk was
possibly needed.  It is quite possible that I had added it in error.

The original problem this patch addressed was stmpclean deleting sockets
that were still actively used - specifically, PostgreSQL's.  I found
that I also tested the patch on /dev/log and X11 sockets.  However, I
can't find any indication of me ever testing with the first hunk only,
so it's quite possible I wrote both hunks at once and only tested both.

> These days the code is
> 
>                 u = unix_find_socket_byname(net, sunname, len, type, hash);
>                 if (u) {
>                         struct dentry *dentry;
>                         dentry = unix_sk(u)->path.dentry;
>                         if (dentry)
>                                 touch_atime(&unix_sk(u)->path);
>                 } else  
>                         goto fail;
> 
> but the logics is the same.  It's the abstract address case - we have
> '\0' in sunname->sun_path[0].  How in hell could that possibly have
> non-NULL ->path.dentry and what would it be?

This is probably in fact impossible.

I think it'd make sense to drop this logic, reverting to:

		if (!u)
			goto fail;

and then see if atime on an actively used socket in /tmp or on /dev/log
keeps getting updated (due to the first hunk of the above commit).

Alexander

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-10  4:24 [RFC] apparently bogus logics in unix_find_other() since 2002 Al Viro
2019-02-11  3:19 ` Al Viro
2019-02-11 11:21 ` Solar Designer

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org netdev@archiver.kernel.org
	public-inbox-index netdev


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox