Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7588909ybn; Mon, 30 Sep 2019 16:45:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPEZByMxSInAV4PSmDB32OKuG+WTWc6QPAPmg/yw064T98rXgWgXoRn/ZXFFIKUVYhzKO0 X-Received: by 2002:a17:906:c47:: with SMTP id t7mr21565393ejf.133.1569887117235; Mon, 30 Sep 2019 16:45:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569887117; cv=none; d=google.com; s=arc-20160816; b=gQiHtrjPe9epIqm/l4Ep5FVXtgn/3MgQLarpUAn9MWqjAnBgkcr5EoZeKfVox+WTsI +CsS4MUK5Vah0y3OlJqUsOCavuNJs8Lp6/zyFV9BHPZLH1AffIc3ilwn41+wuGfoVgb8 sXUALRfho7ogj8r5yYKp34dkpdeJF5xpuPFOc2DghaEq17fi+QTzzQ2wl/rajJLUSVSv FN8r94DP75Zq9Yri45uoxL83CgFgaXfONNQna/OTXERoBk52X4OZbrMDnB3gM2UpgtT0 tzEfqL0UwBHaTFIlNbDYQWOPSIpXqCR/dIFTX8V3bL7TcsYnPyBCFmHm8B1rZVceUajW BFHA== 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=rt01Jv8ohzIRqssmjcdymlBJksS/BQ9v/XBsfaX3lHA=; b=IuzLTffqKYGoAYau2mqKJFQ18jXONMbDf9Bs0o53qimWcDRBpdUWk8gQN3OJ+59J2W ePRGian0MGD/UO0IUYNrmUKQCkaCNYEncuLVlAiYS415Eypumd7jZRQ/83iknICMNdj3 6s25xsqxDyFOFGWBRBHj2o8NXnH/2xOUnReFgdydUvJ/Vi47Vyf1hU4tgYPlB7+CWpT7 RXUdZHv91WvehCXcUwsgf/Y2VWI2o67x0/SOsUQyRvkanP+pArSKNGEuJfV7UPvLA3Si fFQA24ZG5lpdOkHxSvC/dPVNhNkNQ5biHf0ukqIK+APD/oSvGc7aoQe0xMGzeyO+zcta LuNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=miT9e73N; 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 u12si8051883edi.326.2019.09.30.16.44.51; Mon, 30 Sep 2019 16:45:17 -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=miT9e73N; 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 S1732394AbfI3XoA (ORCPT + 99 others); Mon, 30 Sep 2019 19:44:00 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42318 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726425AbfI3Xn7 (ORCPT ); Mon, 30 Sep 2019 19:43:59 -0400 Received: by mail-pf1-f193.google.com with SMTP id q12so6520207pff.9 for ; Mon, 30 Sep 2019 16:43:59 -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=rt01Jv8ohzIRqssmjcdymlBJksS/BQ9v/XBsfaX3lHA=; b=miT9e73NNApEZbLYrEaknoY7YM8uVcN5fnsZnjpIrEzwOEpxoPYU23GlA3VgcYud6f DPNzRxrf1ONCAhCm1nIrKgbkQ9xMsDEDF0qoErLdhvCj1yt5WGO0vYyhF7/+q2tJD3Sa UNaCV/MjnUznz5scAs1KrNBrj8PlxQPi0HQrA= 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=rt01Jv8ohzIRqssmjcdymlBJksS/BQ9v/XBsfaX3lHA=; b=lBewwAy0szPaAmyJNtjudxLJOhlKSLrCFe8xzaSB1jlmPO5JaN6cxoEshD9HdI06mZ wXkSgtUUQsXk66NqI4wty2RMvBtKCJORy0djQIcdLESiJ6atHNGUFLWw5KAt/Rh7p+N1 tX0F22+V8Gkre8w4K6QI9bP6HQCjTfZ9MQnjFbsITOU+xjkNd9pIbJP6kKhmSsBLuBeq S6HjcMIfRIPqwOWlV/Ig96F3AtEHtlcvB5dXvK/4T0ehlFFeaAlv4e5BboUKR1z0KLY+ PjfnT2QxGqTsvE+JBerkIRuwfd36njimq3iy0hAI7AnwbXhBDEie9GzybjUzKSc1rqx6 MnUg== X-Gm-Message-State: APjAAAUBYNGrwGaZqL0H8ZQiPMpbgKbP5ciOUVb12ZXNmaPCI9Mbx+gU c54OZkrkpUpPw0CspPn/DgWCZw== X-Received: by 2002:a63:fc5f:: with SMTP id r31mr26708650pgk.55.1569887038935; Mon, 30 Sep 2019 16:43:58 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t14sm12804335pgv.84.2019.09.30.16.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 16:43:58 -0700 (PDT) Date: Mon, 30 Sep 2019 16:43:57 -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 3/4] sched_setattr: switch to copy_struct_from_user() Message-ID: <201909301643.570C02E@keescook> References: <20190930191526.19544-1-asarai@suse.de> <20190930191526.19544-4-asarai@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190930191526.19544-4-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:25AM +1000, Aleksa Sarai wrote: > From: Aleksa Sarai > > The change is very straightforward, and helps unify the syscall > interface for struct-from-userspace syscalls. Ideally we could also > unify sched_getattr(2)-style syscalls as well, but unfortunately the > correct semantics for such syscalls are much less clear (see [1] for > more detail). In future we could come up with a more sane idea for how > the syscall interface should look. > > [1]: commit 1251201c0d34 ("sched/core: Fix uclamp ABI bug, clean up and > robustify sched_read_attr() ABI logic and code") > > Signed-off-by: Aleksa Sarai Reviewed-by: Kees Cook -Kees > --- > kernel/sched/core.c | 43 +++++++------------------------------------ > 1 file changed, 7 insertions(+), 36 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 7880f4f64d0e..dd05a378631a 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -5106,9 +5106,6 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a > u32 size; > int ret; > > - if (!access_ok(uattr, SCHED_ATTR_SIZE_VER0)) > - return -EFAULT; > - > /* Zero the full structure, so that a short copy will be nice: */ > memset(attr, 0, sizeof(*attr)); > > @@ -5116,45 +5113,19 @@ static int sched_copy_attr(struct sched_attr __user *uattr, struct sched_attr *a > if (ret) > return ret; > > - /* Bail out on silly large: */ > - if (size > PAGE_SIZE) > - goto err_size; > - > /* ABI compatibility quirk: */ > if (!size) > size = SCHED_ATTR_SIZE_VER0; > - > - if (size < SCHED_ATTR_SIZE_VER0) > + if (size < SCHED_ATTR_SIZE_VER0 || size > PAGE_SIZE) > goto err_size; > > - /* > - * If we're handed a bigger struct than we know of, > - * ensure all the unknown bits are 0 - i.e. new > - * user-space does not rely on any kernel feature > - * extensions we dont know about yet. > - */ > - if (size > sizeof(*attr)) { > - unsigned char __user *addr; > - unsigned char __user *end; > - unsigned char val; > - > - addr = (void __user *)uattr + sizeof(*attr); > - end = (void __user *)uattr + size; > - > - for (; addr < end; addr++) { > - ret = get_user(val, addr); > - if (ret) > - return ret; > - if (val) > - goto err_size; > - } > - size = sizeof(*attr); > + ret = copy_struct_from_user(attr, sizeof(*attr), uattr, size); > + if (ret) { > + if (ret == -E2BIG) > + goto err_size; > + return ret; > } > > - ret = copy_from_user(attr, uattr, size); > - if (ret) > - return -EFAULT; > - > if ((attr->sched_flags & SCHED_FLAG_UTIL_CLAMP) && > size < SCHED_ATTR_SIZE_VER1) > return -EINVAL; > @@ -5354,7 +5325,7 @@ sched_attr_copy_to_user(struct sched_attr __user *uattr, > * sys_sched_getattr - similar to sched_getparam, but with sched_attr > * @pid: the pid in question. > * @uattr: structure containing the extended parameters. > - * @usize: sizeof(attr) that user-space knows about, for forwards and backwards compatibility. > + * @usize: sizeof(attr) for fwd/bwd comp. > * @flags: for future extension. > */ > SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, > -- > 2.23.0 > -- Kees Cook