Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7588098ybn; Mon, 30 Sep 2019 16:44:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxyf667fTwBoJUKFXbHBvvI59p5Wus/m13Ylsz1gVcfhbuwzFOXqloRVHrdDf9iv6hxTvVA X-Received: by 2002:a50:ab84:: with SMTP id u4mr22571596edc.13.1569887068060; Mon, 30 Sep 2019 16:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569887068; cv=none; d=google.com; s=arc-20160816; b=TSlTQjj2z13NkfUA8MKoAFvelHZn+x8jmwD8uS9er/j2yXfoFSkeB1PvyLMj/6VkLY TQpcOUol/Q+9oLyMKwZKoRbYIEZgtw+AbTnENNp6nAw1qAMj/NEAc+RJpPXyjbla3h42 MtrzVOEwPpYAbHAt9tG28cXuKrpLOlN48GFVshSsfhbpwNm4jwPZ+zMEPK2bLVwsY7Fb jxB5qP4gelaWXwhNCC0Tz2Q+UddbdaQb6ctCTdS2V8/Lzut+7kj2DxmtHXSP6BkbV2D5 Thc2fTZHeTpA1FmycsALieJdvhlNJESrz/wmgoi30I2atUtNHt0yyAQFRLhxU6x1LDCN 8+jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=wLr0Vt1uSURCynHd+D4IDsYdXD0Hdb1LJEHAhkiX/7E=; b=LIS1cOGw6KlrTQb2SzUdGBM1jaaTEpMOwvruhPwFuM0yAMkfqAKQOxTRLAaDjeo1AU miIKD2AxPkGn8cgKS7Er+cloSBFheuwvSSaHNoHiqqKgYpcoohWcdSzi3S5SS5C213IW LQlCReZKUKHOj0V5wTfabUypb7+VghFrbyoj363La7lqFzhxLgQogrgicHqTLd5ZpM1T vOadf1mnIPYLjMHmx7keNUTOXMUt57GIsnXyemVNIJiub0Cuzq3L73+nC91MfVza7wcZ BiForlhuzw7/h5vBfJuD91y6Dp7Iba8/sG0tfwy8S9qpMNfK2m4f4AxYpNzeFufQa44X SnCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mZNGk+x3; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si8362844eda.285.2019.09.30.16.44.03; Mon, 30 Sep 2019 16:44:28 -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=@chromium.org header.s=google header.b=mZNGk+x3; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732029AbfI3Xml (ORCPT + 99 others); Mon, 30 Sep 2019 19:42:41 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33739 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726425AbfI3Xml (ORCPT ); Mon, 30 Sep 2019 19:42:41 -0400 Received: by mail-pl1-f193.google.com with SMTP id d22so4537460pls.0 for ; Mon, 30 Sep 2019 16:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=wLr0Vt1uSURCynHd+D4IDsYdXD0Hdb1LJEHAhkiX/7E=; b=mZNGk+x3kv2moNk1c6RdHZOB0UU5sAU0q9JBjluoBUvDvNH/Lmpq4eOCBGv+MGh9HI v1KPLnIl7veKR6Q9e3kxUbtQbhQkwn+IT+g6quH9axLM/w/qnnEUxnjJTaw8w+yQiIGH 42MTn25g0mYOn/CoJPJhttFlMW89mPwGRjYyQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=wLr0Vt1uSURCynHd+D4IDsYdXD0Hdb1LJEHAhkiX/7E=; b=ml0AOCCGfOlUO5L+MJEU3uV5IWV9bCrblCNNWEH9Qb3roK15yG7POKzqYCW2NhaOrs JDvXyP6aBztNzwkXHu7wtmgUgiR0sC5PcMeASncO1GR8Lm9nnUqh0d5FCudKYUjSXs2E DUQFHIB6GaaWPYOXJVt+2jTXhn41MKdlQxG+tNRR5CJW/Xh+NVrEKPjM1YDxcvObi6pA UNjLM7v2kJy+gPlNOoNS7beADhRj3yBydPFfsjKetLHHJaveGXZIz7TD52dRZ2fBqM8M 3Qmr7kqpwjVEERikeg/YmcYQq0VrDffYzQvaKwyz58xCqR5qoKESDgUmz/1hAc9IeO0z zang== X-Gm-Message-State: APjAAAWu07XybKk/5HWgyi3skC5rDZoLqtQKVV6yCFzJEn1RWvvNCQRA 1Umbk1NFuTQPka6988WfYxkW7w== X-Received: by 2002:a17:902:b603:: with SMTP id b3mr15122196pls.29.1569886960701; Mon, 30 Sep 2019 16:42:40 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g7sm22247124pfm.176.2019.09.30.16.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 16:42:39 -0700 (PDT) Date: Mon, 30 Sep 2019 16:42:38 -0700 From: Kees Cook To: Aleksa Sarai Cc: Ingo Molnar , Peter Zijlstra , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Aleksa Sarai , Rasmus Villemoes , Al Viro , Linus Torvalds , libc-alpha@sourceware.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RESEND v3 2/4] clone3: switch to copy_struct_from_user() Message-ID: <201909301640.4FC92294FF@keescook> References: <20190930191526.19544-1-asarai@suse.de> <20190930191526.19544-3-asarai@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190930191526.19544-3-asarai@suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 01, 2019 at 05:15:24AM +1000, Aleksa Sarai wrote: > From: Aleksa Sarai > > The change is very straightforward, and helps unify the syscall > interface for struct-from-userspace syscalls. Additionally, explicitly > define CLONE_ARGS_SIZE_VER0 to match the other users of the > struct-extension pattern. > > Signed-off-by: Aleksa Sarai > --- > include/uapi/linux/sched.h | 2 ++ > kernel/fork.c | 34 +++++++--------------------------- > 2 files changed, 9 insertions(+), 27 deletions(-) > > diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h > index b3105ac1381a..0945805982b4 100644 > --- a/include/uapi/linux/sched.h > +++ b/include/uapi/linux/sched.h > @@ -47,6 +47,8 @@ struct clone_args { > __aligned_u64 tls; > }; > > +#define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */ > + > /* > * Scheduling policies > */ > diff --git a/kernel/fork.c b/kernel/fork.c > index f9572f416126..2ef529869c64 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -2525,39 +2525,19 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp, > #ifdef __ARCH_WANT_SYS_CLONE3 > noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs, > struct clone_args __user *uargs, > - size_t size) > + size_t usize) > { > + int err; > struct clone_args args; > > - if (unlikely(size > PAGE_SIZE)) > + if (unlikely(usize > PAGE_SIZE)) > return -E2BIG; I quickly looked through the earlier threads and couldn't find it, but I have a memory of some discussion about moving this test into the copy_struct_from_user() function itself? That would seems like a reasonable idea? ("4k should be enough for any structure!") Either way: Reviewed-by: Kees Cook > - > - if (unlikely(size < sizeof(struct clone_args))) > + if (unlikely(usize < CLONE_ARGS_SIZE_VER0)) > return -EINVAL; > > - if (unlikely(!access_ok(uargs, size))) > - return -EFAULT; > - > - if (size > sizeof(struct clone_args)) { > - unsigned char __user *addr; > - unsigned char __user *end; > - unsigned char val; > - > - addr = (void __user *)uargs + sizeof(struct clone_args); > - end = (void __user *)uargs + size; > - > - for (; addr < end; addr++) { > - if (get_user(val, addr)) > - return -EFAULT; > - if (val) > - return -E2BIG; > - } > - > - size = sizeof(struct clone_args); > - } > - > - if (copy_from_user(&args, uargs, size)) > - return -EFAULT; > + err = copy_struct_from_user(&args, sizeof(args), uargs, usize); > + if (err) > + return err; > > /* > * Verify that higher 32bits of exit_signal are unset and that > -- > 2.23.0 > -- Kees Cook