Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6245631ybi; Wed, 31 Jul 2019 10:49:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxlJ+6QzwzGzjQ5sFYgn7+kJiw3kQM5JeOpOwfRNbwN+N9awmQNlDrcnuGIEngpZpUV64bK X-Received: by 2002:a65:6081:: with SMTP id t1mr116462036pgu.9.1564595350117; Wed, 31 Jul 2019 10:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564595350; cv=none; d=google.com; s=arc-20160816; b=I7TP3twzFihiJ+ntG3OaJCjHTGF02ccKzrXD/oOmCJSu/bfr5USj7fIEeH05pBLr9Z fEanMjJ0Zf8CvMfUtgRPGauP9MPlUh2S89Sr9Zqnhq5CQGm5Krx5LayUuwKPVTZA/ogp aQCw5ddlqKQkaOMCWOh/ntP4m8CJ3X8SHPGnKxKciJTmnb2AydARqDKI7obPdcd8WTUN sDkIQxc/Iyni3FxXeZ7BXYgNUW3dA3i697Wj2g8O/fIyV9zjUba5OgdbJf7FqSi87kaO a5lOkrhq4IeaTwKDGG+3QDoKNqFPoBfkigCiO8JVHVyDS5Uh+SYz7M70CWol0AuJEsa9 5/JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature; bh=DqTY6aG8nZY+73IAGA5g/qZiERQkK4hZGuiPzmKKWh8=; b=oWSjwNJmOlxTD/rEUoipyMgsD+dQ4qlyPwMymf/NZD+TdFH7AVRYkoTzdzCJ3BttDn 5bVSNSVO2XrwT9ziiG5rfO/1daxgjGo/mkohXkkvOhF/EF1KVC0gZhZiGJRd74dY+8Ls glplVcJRGShwKjZHcilVrRLCy4yN8nQI60ofsFjSFRUlMFU/tlmNOIjELGCKT9iju8eV P4zw+tSks0YPTNmIxlVRquP35tmqWCltz3MoQ/c4yqyeLDsiH3ZkFahCM9tDD2HH7DwF 4vLjKp8VFg0MbbX41++kNJo4IamLzO3HDb1oT9SHixFp+f8AcqQA/BGXycC46iBprQZw 9VVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FOoxV12s; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x9si34901961pfi.211.2019.07.31.10.48.55; Wed, 31 Jul 2019 10:49:10 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FOoxV12s; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729432AbfGaQ4q (ORCPT + 99 others); Wed, 31 Jul 2019 12:56:46 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41196 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726073AbfGaQ4q (ORCPT ); Wed, 31 Jul 2019 12:56:46 -0400 Received: by mail-wr1-f66.google.com with SMTP id c2so67259581wrm.8 for ; Wed, 31 Jul 2019 09:56:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=DqTY6aG8nZY+73IAGA5g/qZiERQkK4hZGuiPzmKKWh8=; b=FOoxV12saNl7w3akWNrNCgTnPrD+3S544LRe0DFS56PBepCvDb+o+ypQ3kWM+CcjZh A60KOtsbTCJSXGUZKAfj13fHFuxNpVqtz0Pk4SgCR+3P1m2UeRtJ2lGobZyvKUz2OXRP 3Y6pyFUe3ZMvjhYrabMaLY3VaQmTKvaLDMuGH+VDdVFcz83ty4pg9448jpvyz+GmoKZF RDl+6A3WygeFh88OBt1z+RM4uPZZZtsgNPTwtoUV90DTQP7P/OPtE7f6yu9CFgmdi+RX a+3W1n2/MyoIRxKRJ/VdwFxAz08GPRoe9ie7NX2ycW1cpBYQeiXQ1t4zZeY8LE5WTgol 1+Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DqTY6aG8nZY+73IAGA5g/qZiERQkK4hZGuiPzmKKWh8=; b=FWOgZUptgOmwNv5CJFUhJuy02I5/x0wQhGuOvwZusbS9ZwHyThjW2YyXIQoTqV/RwX /rQtC1QjTE8SR5puLI8UOsxeeXYszsuFvLEXDCeZk6c0k9JAp14epVPG4XuH636lCVEA 5suwFb3JsWMBWTpzk2wv9Wo9X0Nulbd4GAeWQxr4CzsSVc2ko8MbToMWAMCoYBjt2oAT 6cIV3eb+lhFY3N7+sP1W+MrR8nWat2xMCV1hz+4u3+tanOqwFXP6QY49r0RtmzRmYPdq 2KrItGOLh/naQIzrrNGtJ+Dh+eYVoOBoDNgiYOni383JPR5wp5xOm102I0/LvB4BLF29 4PiQ== X-Gm-Message-State: APjAAAWRNOC/bK7WJIoqbm+WNCxreQq4m82pOkG+JhXrNjI7glfwkcZv gjG3+ma2fPRWT34645gE/RTkS5Pp X-Received: by 2002:a05:6000:11c6:: with SMTP id i6mr34529911wrx.193.1564592204430; Wed, 31 Jul 2019 09:56:44 -0700 (PDT) Received: from [10.83.36.153] ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id v5sm83709220wre.50.2019.07.31.09.56.43 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 09:56:43 -0700 (PDT) Subject: Re: [PATCH v2 1/2] fork: extend clone3() to support CLONE_SET_TID From: Dmitry Safonov <0x7f454c46@gmail.com> To: Adrian Reber , Christian Brauner , Eric Biederman , Pavel Emelianov , Jann Horn , Oleg Nesterov Cc: linux-kernel@vger.kernel.org, Andrei Vagin , Mike Rapoport , Radostin Stoyanov References: <20190731161223.2928-1-areber@redhat.com> <417a9682-c7fc-fec4-3510-81a8aa7cd0af@gmail.com> Message-ID: <6ccdda8e-73a3-c8e9-1f37-f89bf688c0fa@gmail.com> Date: Wed, 31 Jul 2019 17:56:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <417a9682-c7fc-fec4-3510-81a8aa7cd0af@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/31/19 5:49 PM, Dmitry Safonov wrote: > Hi Adrian, > > On 7/31/19 5:12 PM, Adrian Reber wrote: > [..] >> @@ -2530,14 +2530,12 @@ 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))) >> - return -EINVAL; >> - > > It might be better to validate it still somehow, but I don't insist. > > [..] >> @@ -2578,11 +2580,16 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs, >> >> static bool clone3_args_valid(const struct kernel_clone_args *kargs) >> { >> - /* >> - * All lower bits of the flag word are taken. >> - * Verify that no other unknown flags are passed along. >> - */ >> - if (kargs->flags & ~CLONE_LEGACY_FLAGS) >> + /* Verify that no other unknown flags are passed along. */ >> + if (kargs->flags & ~(CLONE_LEGACY_FLAGS | CLONE_SET_TID)) >> + return false; >> + >> + /* Fail if set_tid is set without CLONE_SET_TID */ >> + if (kargs->set_tid && !(kargs->flags & CLONE_SET_TID)) >> + return false; >> + >> + /* Also fail if set_tid is invalid */ >> + if ((kargs->set_tid <= 0) && (kargs->flags & CLONE_SET_TID)) >> return false; > > Sorry for not mentioning it on v1, but I've noticed it only now: > you check kargs->set_tid even with the legacy-sized kernel_clone_args, > which is probably some random value on a task's stack? Self-correction: On kernel stack in copy_clone_args_from_user(). Which may probably be considered as a security leak.. Sorry again for not spotting it in v1. Thanks, Dmitry