Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5623570ybh; Wed, 7 Aug 2019 08:50:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxu0wAPKLrOQP/G4VEGzWq2OsWewoOGK2IQMm7J/UaE0MnJExuvRlczjc2DR1tXJx+iMnxf X-Received: by 2002:a17:90a:eb04:: with SMTP id j4mr540790pjz.103.1565193055226; Wed, 07 Aug 2019 08:50:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565193055; cv=none; d=google.com; s=arc-20160816; b=yR8TZP78Xy5hnP+n4hO3/6t8YoHAwhHCd1+oP7ith0ue1uqAi2GNWzDMY68gUYWcZY GMkD5+GWZLseevEpXgSyV285axZgJFGjQaeBPSHvwOEjbu1qbRueOh46RrsdPWJ61odG ab5ihtZ7wnVuQn/xUgdYJUrmd0GUt94uZWpTKPcbbZBGl0+mVHDpfw7NdqbmKEmELiAU I7Vqk1IAoGA/8WKs+AwiVgTj9T7d5a3420MxlNIofzwgAZ4fIxkOehnxJaVaTk4HvvbJ CmuHlV0SeG13Wh1z6FeUPBHRU5OEdCPjVQbDyE3dNpk8rxPo6AKmNXSK8N8huMeZDhjV tCiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=LnMnos9wqFirCCdImWWmAG5Vvkl80ttOLDuKp8iWUeg=; b=EyJ9C9PjpxK/I8a3EOtx6UyY0rgMpfLsWN2MzFl1Mqiv87Nz2c4UvVhWq/1sVI9KZ7 rm85u1cQesPUM4YaOkxVVzpkBYdjrbRTa6KrOBB9Schu9ZGxD4RO61BLB5JRfGm1PMf+ NG4eHiy62XOkoTVfmt4VXf974+EIS1oiEnoBhUXTpHUoV44wvaVGhADDEQYuD1640Bo5 KVR2J5iEVhzcLWAUD/HW4Jcut9Wk4HA50hh4nWasxsRdmCKI1uHqdLFXuEzaGwsolMgC bXtoW8HeV9Tet1bAk90c86iuE6Du6NFWT7bPEmxyV0zrTaAxgd4nWTAbxvFX5zyMs4jO Brpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s13si11460835pgn.123.2019.08.07.08.50.37; Wed, 07 Aug 2019 08:50:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388782AbfHGPsc (ORCPT + 99 others); Wed, 7 Aug 2019 11:48:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48516 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388769AbfHGPsc (ORCPT ); Wed, 7 Aug 2019 11:48:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8177EC529; Wed, 7 Aug 2019 15:48:31 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.136]) by smtp.corp.redhat.com (Postfix) with SMTP id DAE0960BE1; Wed, 7 Aug 2019 15:48:29 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 7 Aug 2019 17:48:31 +0200 (CEST) Date: Wed, 7 Aug 2019 17:48:29 +0200 From: Oleg Nesterov To: Adrian Reber Cc: Christian Brauner , Eric Biederman , Pavel Emelianov , Jann Horn , Dmitry Safonov <0x7f454c46@gmail.com>, linux-kernel@vger.kernel.org, Andrei Vagin , Mike Rapoport , Radostin Stoyanov Subject: Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID Message-ID: <20190807154828.GD24112@redhat.com> References: <20190806191551.22192-1-areber@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190806191551.22192-1-areber@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 07 Aug 2019 15:48:32 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.