public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Adrian Reber <areber@redhat.com>
Cc: Christian Brauner <christian@brauner.io>,
	Eric Biederman <ebiederm@xmission.com>,
	Pavel Emelianov <xemul@virtuozzo.com>,
	Jann Horn <jannh@google.com>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	linux-kernel@vger.kernel.org, Andrei Vagin <avagin@gmail.com>,
	Mike Rapoport <rppt@linux.ibm.com>,
	Radostin Stoyanov <rstoyanov1@gmail.com>
Subject: Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID
Date: Wed, 7 Aug 2019 17:48:29 +0200	[thread overview]
Message-ID: <20190807154828.GD24112@redhat.com> (raw)
In-Reply-To: <20190806191551.22192-1-areber@redhat.com>

On 08/06, Adrian Reber wrote:
>
> @@ -2530,12 +2530,14 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,
>  					      struct clone_args __user *uargs,
>  					      size_t size)
>  {
> +	struct pid_namespace *pid_ns = task_active_pid_ns(current);
>  	struct clone_args args;
>  
>  	if (unlikely(size > PAGE_SIZE))
>  		return -E2BIG;
>  
> -	if (unlikely(size < sizeof(struct clone_args)))
> +	/* The struct needs to be at least the size of the original struct. */
> +	if (size < (sizeof(struct clone_args) - sizeof(__aligned_u64)))
>  		return -EINVAL;

slightly off-topic, but with or without this patch I do not understand
-EINVAL. Can't we replace this check with

	if (size < sizeof(struct clone_args))
		memset((void*)&args + size, sizeof(struct clone_args) - size, 0);

?

this way we can new members at the end of clone_args and this matches
the "if (size > sizeof(struct clone_args))" block below which promises
that whatever we add into clone_args a zero value should work.


And if we do this

> +	if (size == sizeof(struct clone_args)) {
> +		/* Only check permissions if set_tid is actually set. */
> +		if (args.set_tid &&
> +			!ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
> +			return -EPERM;
> +		kargs->set_tid = args.set_tid;
> +	}

we can move this check into clone3_args_valid() or even copy_process()

	if (kargs->set_tid) {
		if (!ns_capable(...))
			return -EPERM;
	}


Either way,

> @@ -2585,6 +2595,10 @@ static bool clone3_args_valid(const struct kernel_clone_args *kargs)
>  	if (kargs->flags & ~CLONE_LEGACY_FLAGS)
>  		return false;
>
> +	/* Fail if set_tid is invalid */
> +	if (kargs->set_tid < 0)
> +		return false;

I think it would be more clean to do this along with ns_capable() check,
or along with the "set_tid >= pid_max" check in alloc_pid().

I won't insist, but I do not really like the fact we check set_tid 3 times
in copy_clone_args_from_user(), clone3_args_valid(), and alloc_pid().

Oleg.


  parent reply	other threads:[~2019-08-07 15:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06 19:15 [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID Adrian Reber
2019-08-06 19:15 ` [PATCH v3 2/2] selftests: add tests for clone3() Adrian Reber
2019-08-07 14:26 ` [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID Oleg Nesterov
2019-08-07 18:00   ` Christian Brauner
2019-08-07 15:48 ` Oleg Nesterov [this message]
2019-08-07 15:57   ` Dmitry Safonov
2019-08-07 16:21     ` Oleg Nesterov
2019-08-07 16:33       ` Dmitry Safonov
2019-08-07 16:47         ` Dmitry Safonov
2019-08-07 18:20   ` Christian Brauner
2019-08-07 16:08 ` Oleg Nesterov
2019-08-07 18:05   ` Christian Brauner
2019-08-07 17:55 ` Christian Brauner

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=20190807154828.GD24112@redhat.com \
    --to=oleg@redhat.com \
    --cc=0x7f454c46@gmail.com \
    --cc=areber@redhat.com \
    --cc=avagin@gmail.com \
    --cc=christian@brauner.io \
    --cc=ebiederm@xmission.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rppt@linux.ibm.com \
    --cc=rstoyanov1@gmail.com \
    --cc=xemul@virtuozzo.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