netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Yann Droneaud <ydroneaud@opteya.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] af_unix: Escape abstract unix socket address
Date: Wed, 6 Apr 2022 14:59:41 -0700	[thread overview]
Message-ID: <20220406145941.728b4cb5@hermes.local> (raw)
In-Reply-To: <20220406102213.2020784-1-ydroneaud@opteya.com>

On Wed,  6 Apr 2022 12:22:13 +0200
Yann Droneaud <ydroneaud@opteya.com> wrote:

> Abstract unix socket address are bytes sequences up to
> 108 bytes (UNIX_PATH_MAX == sizeof(struct sockaddr_un) -
> offsetof(struct sockaddr_un, sun_path)).
> 
> As with any random string of bytes, printing them in
> /proc/net/unix should be done with caution to prevent
> misbehavior.
> 
> It would have been great to use seq_escape_mem() to escape
> the control characters in a reversible way.
> 
> Unfortunately userspace might expect that NUL bytes are
> replaced with '@' characters as it's done currently.
> 
> So this patch implements the following scheme: any control
> characters, including NUL, in the abstract unix socket
> addresses is replaced by '@' characters.
> 
> Sadly, with such non reversible escape scheme, abstract
> addresses such as "\0\0", "\0\a", "\0\b", "\0\t", etc.
> will have the same representation: "@@".
> 
> But will prevent "cat /proc/net/unix" from messing with
> terminal, and will prevent "\n" in abstract address from
> messing with parsing the list of Unix sockets.
> 
> Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
> ---
>  net/unix/af_unix.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index e71a312faa1e..8021efd92301 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -3340,7 +3340,8 @@ static int unix_seq_show(struct seq_file *seq, void *v)
>  				i++;
>  			}
>  			for ( ; i < len; i++)
> -				seq_putc(seq, u->addr->name->sun_path[i] ?:
> +				seq_putc(seq, !iscntrl(u->addr->name->sun_path[i]) ?
> +					 u->addr->name->sun_path[i] :
>  					 '@');
>  		}
>  		unix_state_unlock(s);

Unfortunately, you will break userspace ABI with this.

  reply	other threads:[~2022-04-06 21:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-06 10:22 [PATCH] af_unix: Escape abstract unix socket address Yann Droneaud
2022-04-06 21:59 ` Stephen Hemminger [this message]
2022-04-07 10:56   ` Yann Droneaud

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=20220406145941.728b4cb5@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ydroneaud@opteya.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;
as well as URLs for NNTP newsgroup(s).