Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1143845ybe; Wed, 4 Sep 2019 13:22:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOHs/E7Vn7LuH0B2eKrE+ztPevRpuaxDzMEfCcBLXYQFwKIljfjMsUVKufdt2o4N+C3JPm X-Received: by 2002:a62:6489:: with SMTP id y131mr47204652pfb.124.1567628549371; Wed, 04 Sep 2019 13:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567628549; cv=none; d=google.com; s=arc-20160816; b=Gk4g1vPAVmTHkX3Jrcov/Bw1h9DCVmGttXlSl0vShsNBrK8G206TcQSgDVd6GbAppn J5Sz9wQJR3IiCHhgfxjJrU0McGJP5gQssua0LgSqSGOxcl8Rq0Vc9+3GlqUvmLx5gJhZ WVVu7vAQqAaP/5SA1V1+5y4O40KUbBNwoCXd383XPID4a9g0GCUpx/3VhQQBPhYXfsSv jsI9yfnV+FHnceCBKLLyfgPo+bQyn2DNippCj2r4Jlb4FVwShQRCuPuV4tR10y9jUYU8 t1jdaQYN5sDEClefH0Z55vh7Z9HO9BTYkUtaUtvXZZoEHDqg5gWbEjo5cS9O3VyBq8Sr vEMg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hEh3QYdu5uwwyonBwLJdcIY+zL0/Buj5NdAaQ7PXlG0=; b=lXmJXq+s7dGPXHsEBUJiUb9vEZvjZ2SY9E1kagvSoyyBrlWAJwHboqN9aISWphwAJH 1/QlvzX20QDXiiudg/XMzcokip5+99Cdtv8lZZAiwK02oQGTwK3okepj1IwNiwFCXYlt sPWua9Kw5EAp20+Z0KAcGQYuUHFqHsMy1p6N/oTcyU3kOMFWVT/C0TfsicvedUdCHE2Z adfrgUDBwc/bzMT9C/9q0Jyw/9j0UWEjyrxKmk7tjOCyh6IhHIDNM3lmM4GTI/tZnTTE yS4O7demKxwK+QuurJPDvndvlhSp8JjvTyQ2LIfw3PTyQgjQ+xtG3KL9WZ6YIq0QGBRk 0PRw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u46si18514513pgn.578.2019.09.04.13.22.13; Wed, 04 Sep 2019 13:22:29 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730478AbfIDUVX (ORCPT + 99 others); Wed, 4 Sep 2019 16:21:23 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:63936 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728197AbfIDUVW (ORCPT ); Wed, 4 Sep 2019 16:21:22 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 41E63A0195; Wed, 4 Sep 2019 22:21:18 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id zRSgFI6ciWwx; Wed, 4 Sep 2019 22:21:15 +0200 (CEST) From: Aleksa Sarai To: Al Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan , Ingo Molnar , Peter Zijlstra , Christian Brauner Cc: Aleksa Sarai , Eric Biederman , Andy Lutomirski , Andrew Morton , Alexei Starovoitov , Kees Cook , Jann Horn , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Rasmus Villemoes , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Aleksa Sarai , Linus Torvalds , containers@lists.linux-foundation.org, linux-alpha@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org Subject: [PATCH v12 04/12] perf_event_open: switch to copy_struct_from_user() Date: Thu, 5 Sep 2019 06:19:25 +1000 Message-Id: <20190904201933.10736-5-cyphar@cyphar.com> In-Reply-To: <20190904201933.10736-1-cyphar@cyphar.com> References: <20190904201933.10736-1-cyphar@cyphar.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The change is very straightforward, and takes advantage of the (very minor) efficiency improvements in copy_struct_from_user() -- that the memchr_inv() check is done on a buffer instead of one-at-at-time with get_user(). Signed-off-by: Aleksa Sarai --- kernel/events/core.c | 45 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 0463c1151bae..fe5f58443ba6 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -10498,55 +10498,26 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr, u32 size; int ret; - if (!access_ok(uattr, PERF_ATTR_SIZE_VER0)) - return -EFAULT; - - /* - * zero the full structure, so that a short copy will be nice. - */ + /* Zero the full structure, so that a short copy will be nice. */ memset(attr, 0, sizeof(*attr)); ret = get_user(size, &uattr->size); if (ret) return ret; - if (size > PAGE_SIZE) /* silly large */ - goto err_size; - - if (!size) /* abi compat */ + /* ABI compatibility quirk: */ + if (!size) size = PERF_ATTR_SIZE_VER0; - if (size < PERF_ATTR_SIZE_VER0) 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; - attr->size = size; if (attr->__reserved_1) -- 2.23.0