public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH v2 1/3] util, conf: Add and use ns_is_init() helper
Date: Tue, 23 May 2023 16:11:48 +0200	[thread overview]
Message-ID: <20230523161148.0a029260@elisabeth> (raw)
In-Reply-To: <20230522085205.2803560-2-sbrivio@redhat.com>

On Mon, 22 May 2023 10:52:03 +0200
Stefano Brivio <sbrivio@redhat.com> wrote:

> +bool ns_is_init(void)
> +{
> +	const char root_uid_map[] = "         0          0 4294967295\n";
> +	char buf[sizeof(root_uid_map)];
> +	bool ret = true;
> +	int fd;
> +
> +	if ((fd = open("/proc/self/uid_map", O_RDONLY | O_CLOEXEC)) < 0) {
> +		die("Can't determine if we're in init namespace: %s",
> +		    strerror(errno));
> +	}
> +
> +	if (read(fd, buf, sizeof(root_uid_map)) != sizeof(root_uid_map) - 1 ||
> +	    strncmp(buf, root_uid_map, sizeof(root_uid_map)))

Oops, valgrind noticed I didn't actually initialise that extra byte at the end
of 'buf'. Fixing this up as well before pushing...

-- 
Stefano


  parent reply	other threads:[~2023-05-23 14:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22  8:52 [PATCH v2 0/3] Fix pasta-in-pasta operation (and similar) Stefano Brivio
2023-05-22  8:52 ` [PATCH v2 1/3] util, conf: Add and use ns_is_init() helper Stefano Brivio
2023-05-22  9:03   ` David Gibson
2023-05-23 14:11   ` Stefano Brivio [this message]
2023-05-22  8:52 ` [PATCH v2 2/3] pasta: Detach mount namespace, (re)mount procfs before spawning command Stefano Brivio
2023-05-22  8:52 ` [PATCH v2 3/3] isolation: Initially Keep CAP_SETFCAP if running as UID 0 in non-init Stefano Brivio

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=20230523161148.0a029260@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /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).