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: <20210312164119.GC27820@redhat.com>
Date:   Fri, 12 Mar 2021 17:41:20 +0100
From:   Oleg Nesterov <oleg@...hat.com>
To:     Jim Newsome <jnewsome@...project.org>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        "Eric W . Biederman" <ebiederm@...ssion.com>,
        Christian Brauner <christian@...uner.io>,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4] do_wait: make PIDTYPE_PID case O(1) instead of O(n)

On 03/11, Jim Newsome wrote:
>
> +static bool is_effectively_child(struct wait_opts *wo, bool ptrace,
> +				 struct task_struct *target)
> +{
> +	struct task_struct *parent =
> +		!ptrace ? target->real_parent : target->parent;
> +
> +	return current == parent || (!(wo->wo_flags & __WNOTHREAD) &&
> +				     same_thread_group(current, parent));
> +}
> +
> +/*
> + * Optimization for waiting on PIDTYPE_PID. No need to iterate through child
> + * and tracee lists to find the target task.
> + */
> +static int do_wait_pid(struct wait_opts *wo)
> +{
> +	bool ptrace;
> +	struct task_struct *target;
> +	int retval;
> +
> +	ptrace = false;
> +
> +	/* A non-ptrace wait can only be performed on a thread group leader. */
> +	target = pid_task(wo->wo_pid, PIDTYPE_TGID);
> +
> +	if (target && is_effectively_child(wo, ptrace, target)) {
> +		retval = wait_consider_task(wo, ptrace, target);
> +		if (retval)
> +			return retval;
> +	}
> +
> +	ptrace = true;
> +
> +	/* A ptrace wait can be done on non-thread-group-leaders. */
> +	if (!target)
> +		target = pid_task(wo->wo_pid, PIDTYPE_PID);
> +
> +	if (target && is_effectively_child(wo, ptrace, target)) {
> +		retval = wait_consider_task(wo, ptrace, target);

No, this is not right... You need to check target->ptrace != 0.

I know that Eric suggests to not use thread_group_leader() and I won't argue
even if I don't really agree.

Up to you, but to me something like

	do_wait_pid()
	{
		target = pid_task(wo->wo_pid, PIDTYPE_PID);

		if (!target)
			return 0;

		if (thread_group_leader(target) &&
		    is_effectively_child(wo, 0, target) {
			...			
		}

		if (target->ptrace &&
		    is_effectively_child(wo, 1, target) {
			...
		}

		return 0;

	}

looks more simple/clean.

Oleg.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ