From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: netdev@vger.kernel.org
Cc: Werner Almesberger <Werner.Almesberger@epfl.ch>,
Vic Abell <vabell@lsof.comcastbiz.net>
Subject: newline characters in unix socket names and /proc/net/unix
Date: Sat, 14 Mar 2015 22:33:42 +0000 [thread overview]
Message-ID: <20150314223342.GA4146@chaz.gmail.com> (raw)
Hello,
it seems the kernel doesn't escape newline characters in the
file names displayed in /proc/net/unix
That file has this format:
Num RefCount Protocol Flags Type St Inode Path
ffff8802441bcb40: 00000002 00000000 00000000 0002 01 9219 /run/systemd/shutdownd
ffff8800a0651780: 00000002 00000000 00010000 0001 01 37020 /tmp/.menu-cached-:0-stephane
[...]
and is used by things like fuser, lsof for instance to map Inode
to Path (and libgtop, systemd (to check which sockets are still
in use for cleanup) at least).
# fuser /run/systemd/shutdownd
/run/systemd/shutdownd: 1
# fuser /tmp/.menu-cached-:0-stephane
/tmp/.menu-cached-:0-stephane: 4263
Now, one can bind a socket like:
socket=$'/tmp/foo\nffff8802441bcb40: 00000002 00000000 00000000 0002 01 9219 /tmp/.menu-cached-:0-stephane'
mkdir -p "${socket%/*}"
nc -lU "$socket"
Now /proc/net/unix has
Num RefCount Protocol Flags Type St Inode Path
ffff8802441bcb40: 00000002 00000000 00000000 0002 01 9219 /run/systemd/shutdownd
ffff8800a0651780: 00000002 00000000 00010000 0001 01 37020 /tmp/.menu-cached-:0-stephane
ffff880104af9400: 00000002 00000000 00010000 0001 01 5918000 /tmp/foo
ffff8802441bcb40: 00000002 00000000 00000000 0002 01 9219 /tmp/.menu-cached-:0-stephane
And fuser gives:
# fuser /run/systemd/shutdownd
# fuser /tmp/.menu-cached-:0-stephane
/tmp/.menu-cached-:0-stephane: 1 4263
Which could be a problem if the output of fuser were used to
decide what process to kill (like with -k).
I think at least newline characters (and the escape character
itself) should be escaped in there, maybe do something similar
to what is currently done for the process name in
/proc/self/status
(fuser and lsof and the other tools would also need to be
updated to take the change into account, note that lsof already
chokes on space/tab/colon in there which I've already reported
to Vic).
Also note that /proc/net/unix doesn't change after a socket file
has been renamed, so even after that issue is fixed, fuser -k on
a socket may not be very reliable. Maybe it would help if the
filesystem device/inode for the socket file were added to
/proc/net/unix and/or if the path was updated like for the
symlink targets of /proc/self/fd/*.
--
Stephane
next reply other threads:[~2015-03-14 22:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-14 22:33 Stephane Chazelas [this message]
2015-03-17 21:27 ` newline characters in unix socket names and /proc/net/unix Stephane Chazelas
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=20150314223342.GA4146@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=Werner.Almesberger@epfl.ch \
--cc=netdev@vger.kernel.org \
--cc=vabell@lsof.comcastbiz.net \
/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;
as well as URLs for NNTP newsgroup(s).