public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: "Richard W.M. Jones" <rjones@redhat.com>,
	passt-dev@passt.top, Minxi Hou <mhou@redhat.com>
Subject: Re: [PATCH 7/8] conf, passt, tap: Open socket and PID files before switching UID/GID
Date: Fri, 21 Jun 2024 11:02:38 +1000	[thread overview]
Message-ID: <ZnTRLtW8uQ3FefgT@zatzit> (raw)
In-Reply-To: <20240620162212.09ccc2f9@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 3030 bytes --]

On Thu, Jun 20, 2024 at 04:22:12PM +0200, Stefano Brivio wrote:
> On Thu, 20 Jun 2024 13:47:31 +0100
> "Richard W.M. Jones" <rjones@redhat.com> wrote:
> 
> > On Thu, Jun 20, 2024 at 02:12:53PM +0200, Stefano Brivio wrote:
> > > On Thu, 20 Jun 2024 12:30:54 +0100
> > > "Richard W.M. Jones" <rjones@redhat.com> wrote:
> > >   
> > > > On Wed, May 29, 2024 at 12:35:24PM +1000, David Gibson wrote:  
> > > > > On Wed, May 22, 2024 at 10:59:10PM +0200, Stefano Brivio wrote:    
> > > > > > Otherwise, if the user runs us as root, and gives us paths that are
> > > > > > only accessible by root, we'll fail to open them, which might in turn
> > > > > > encourage users to change permissions or ownerships: definitely a bad
> > > > > > idea in terms of security.
> > > > > > 
> > > > > > Reported-by: Minxi Hou <mhou@redhat.com>
> > > > > > Reported-by: Richard W.M. Jones <rjones@redhat.com>
> > > > > > Signed-off-by: Stefano Brivio <sbrivio@redhat.com>    
> > > > > 
> > > > > Looking at this I did notice a pre-existing, well, maybe not bug
> > > > > exactly, but possibly surprising behaviour, which makes me a
> > > > > bit more nervous now that we can invoke it as root.
> > > > > 
> > > > > tap_sock_unix_open() will silently truncate the given socket path to
> > > > > the maximum length for a Unix socket.  Which means we could bind(),
> > > > > but also unlink() a path that's not exactly the same as the one the
> > > > > one the user requested.  I don't immediately see a way to exploit
> > > > > that, but it's the sort of thing that makes me nervous.  I think we
> > > > > should instead outright fail if the given socket path is too long.    
> > > > 
> > > > Yes, agreed.
> > > > 
> > > > It seems as if the latest passt code still does this.  Do you want me
> > > > to open a bug about it?  
> > > 
> > > Yes, please, that, or a patch :)  
> > 
> > While I was testing this, I found we do seem to check it:
> > 
> > https://passt.top/passt/tree/conf.c#n1446
> 
> Oh, I thought David was referring to the loop in tap_sock_unix_open(),
> where we try paths in the form "/tmp/passt_%i.socket". But even there,
> we can't exceed UNIX_PATH_MAX.

Actually I was referring to the memcpy() from sock_path to path in
tap_sock_unix_open().  I hadn't thought to check if we'd previously
verified the length of sock_path.  So, yeah we seem to be ok here
(although it's not obvious that's the case from within the code of
tap_sock_unix_open()).

> One minor issue remains, though: in conf(), we refuse paths that are
> longer than UNIX_SOCK_MAX (100). That's the maximum index for the
> "/tmp/passt_%i.socket", it happens to be a sane value, but we should use
> UNIX_PATH_MAX (108) instead. I'll fix it, but wait for David's feedback
> first.

Well, apart from that, yes.

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-06-21  1:02 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-22 20:59 [PATCH 0/8] Open socket and PID files as root, before switching Stefano Brivio
2024-05-22 20:59 ` [PATCH 1/8] conf: Don't lecture user about starting us as root Stefano Brivio
2024-05-23  1:45   ` David Gibson
2024-05-23  9:52   ` Richard W.M. Jones
2024-05-22 20:59 ` [PATCH 2/8] tap: Move all-ones initialisation of mac_guest to tap_sock_init() Stefano Brivio
2024-05-23  1:46   ` David Gibson
2024-05-23  9:59   ` Richard W.M. Jones
2024-05-23 10:03     ` Richard W.M. Jones
2024-05-22 20:59 ` [PATCH 3/8] passt, tap: Don't use -1 as uninitialised value for fd_tap_listen Stefano Brivio
2024-05-23  1:48   ` David Gibson
2024-05-22 20:59 ` [PATCH 4/8] tap: Split tap_sock_unix_init() into opening and listening parts Stefano Brivio
2024-05-23 10:05   ` Richard W.M. Jones
2024-05-28  7:01   ` David Gibson
2024-05-22 20:59 ` [PATCH 5/8] util: Rename write_pidfile() to pidfile_write() Stefano Brivio
2024-05-23 10:06   ` Richard W.M. Jones
2024-05-22 20:59 ` [PATCH 6/8] passt, util: Move opening of PID file to its own function Stefano Brivio
2024-05-23 10:06   ` Richard W.M. Jones
2024-05-28  7:04   ` David Gibson
2024-05-22 20:59 ` [PATCH 7/8] conf, passt, tap: Open socket and PID files before switching UID/GID Stefano Brivio
2024-05-23 10:10   ` Richard W.M. Jones
2024-05-29  2:35   ` David Gibson
2024-06-20 11:30     ` Richard W.M. Jones
2024-06-20 12:12       ` Stefano Brivio
2024-06-20 12:47         ` Richard W.M. Jones
2024-06-20 14:22           ` Stefano Brivio
2024-06-21  1:02             ` David Gibson [this message]
2024-05-22 20:59 ` [PATCH 8/8] conf, passt.h: Rename pid_file in struct ctx to pidfile Stefano Brivio
2024-05-23 10:11   ` Richard W.M. Jones
2024-05-28  7:07   ` David Gibson

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=ZnTRLtW8uQ3FefgT@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=mhou@redhat.com \
    --cc=passt-dev@passt.top \
    --cc=rjones@redhat.com \
    --cc=sbrivio@redhat.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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).