lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zdd8MAJJD3M11yeR@tycho.pizza>
Date: Thu, 22 Feb 2024 09:54:08 -0700
From: Tycho Andersen <tycho@...ho.pizza>
To: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
Cc: brauner@...nel.org, stgraber@...raber.org, cyphar@...har.com,
	linux-kernel@...r.kernel.org,
	Christian Brauner <christian.brauner@...ntu.com>
Subject: Re: [PATCH v1 2/2] tests/pid_namespace: add pid_max tests

On Thu, Feb 22, 2024 at 05:09:15PM +0100, Alexander Mikhalitsyn wrote:
> +static int pid_max_nested_limit_inner(void *data)
> +{
> +	int fret = -1, nr_procs = 400;
> +	int fd, ret;
> +	pid_t pid;
> +	pid_t pids[1000];
> +
> +	ret = mount("", "/", NULL, MS_PRIVATE | MS_REC, 0);
> +	if (ret) {
> +		fprintf(stderr, "%m - Failed to make rootfs private mount\n");
> +		return fret;
> +	}
> +
> +	umount2("/proc", MNT_DETACH);
> +
> +	ret = mount("proc", "/proc", "proc", 0, NULL);
> +	if (ret) {
> +		fprintf(stderr, "%m - Failed to mount proc\n");
> +		return fret;
> +	}
> +
> +	fd = open("/proc/sys/kernel/pid_max", O_RDWR | O_CLOEXEC | O_NOCTTY);
> +	if (fd < 0) {
> +		fprintf(stderr, "%m - Failed to open pid_max\n");
> +		return fret;
> +	}
> +
> +	ret = write(fd, "500", sizeof("500") - 1);
> +	close(fd);
> +	if (ret < 0) {
> +		fprintf(stderr, "%m - Failed to write pid_max\n");
> +		return fret;
> +	}
> +
> +	for (nr_procs = 0; nr_procs < 500; nr_procs++) {
> +		pid = fork();
> +		if (pid < 0)
> +			break;
> +
> +		if (pid == 0)
> +			exit(EXIT_SUCCESS);
> +
> +		pids[nr_procs] = pid;
> +	}
> +
> +	if (nr_procs >= 400) {
> +		fprintf(stderr, "Managed to create processes beyond the configured outer limit\n");
> +		goto reap;
> +	}

A small quibble, but I wonder about the semantics here. "You can write
whatever you want to this file, but we'll ignore it sometimes" seems
weird to me. What if someone (CRIU) wants to spawn a pid numbered 450
in this case? I suppose they read pid_max first, they'll be able to
tell it's impossible and can exit(1), but returning E2BIG from write()
might be more useful.

Tycho

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ