Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7439282ybn; Mon, 30 Sep 2019 13:59:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxV+3hoRFa6gdprFJJXFLv66u7LpcWfTP5afIEZCvW07v9yX/4Xzce0gPPZJBp49gxgBB1O X-Received: by 2002:a17:906:95cf:: with SMTP id n15mr21110795ejy.183.1569877185183; Mon, 30 Sep 2019 13:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569877185; cv=none; d=google.com; s=arc-20160816; b=ifrcK2hog1fHPHIoz5plK5Ptu7qkaTUrvzwVAKHmdhhLOj75/nnbyLnXxTY8JSIadO 1XAxqQ0+21guM5D/y0WzMcg0sDIyYD9Mx/t0XOCcdA6FoQNYyTpZsnudPubRA6PD9zG/ p26NSHs7EMJQzkInDX6IfS5rCq+CfrxExDD5qF6mPwj9CkDDcUpIY3YTS03iUFGTWHiK UxGidPL0o+7PHQf21DryVmNrUlTxAYSs5rmmx6W3JSq5oSqawu/oXDhW/xxwChUlADJ/ t8cpewaTcorBJj6kNAxX1/MsIrf6WJpSkrc9i/xwXqZ9B3wUPlf7n16Arl8oJ7Gs/8v0 KyvA== 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=h0WtrEgkdwD6sghwUtq0bdUy3oFb9sEvyhK4mq2Rn/I=; b=y71GoR/bSVWy8rRe0fyu9hDi8Et8BSHryEJ2KpUeOTpsJh6f+sUTVqqLr8fF9Th+MU kct5iq5Vf4zk3s4nmeYf7AGTvKUzi8LIdGr+mycWdVX5YRW3PFsFpj2AjuFWmdP9gmMJ R/v7vCD3Itu/vW3NzX+7AZCEsxO+YRnq1zvoMvnhaMOf7UufFYkcRI0SseL+BjNC5CkE zKTxhC+KknvqnBrXj9irLrHLO1vkdZfHbBENrdOCzqczG6DifKrvvmJ2+9triAODVbc5 j3Bv4BRAkd7FdmnD9negPcIuTC7J9cXq/zdlP30D57yii92MtnVFsTB948mKnJ3r4224 toJQ== 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 oq3si7864701ejb.220.2019.09.30.13.59.20; Mon, 30 Sep 2019 13:59:45 -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 S1731893AbfI3U6R (ORCPT + 99 others); Mon, 30 Sep 2019 16:58:17 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:54504 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729366AbfI3U6P (ORCPT ); Mon, 30 Sep 2019 16:58:15 -0400 Received: from smtp2.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 526EAA1893; Mon, 30 Sep 2019 20:29:09 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.240]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id ydpASaiTM1cS; Mon, 30 Sep 2019 20:29:06 +0200 (CEST) From: Aleksa Sarai To: Ingo Molnar , Peter Zijlstra , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Kees Cook Cc: Aleksa Sarai , Rasmus Villemoes , Al Viro , Linus Torvalds , libc-alpha@sourceware.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/4] perf_event_open: switch to copy_struct_from_user() Date: Tue, 1 Oct 2019 04:28:10 +1000 Message-Id: <20190930182810.6090-5-cyphar@cyphar.com> In-Reply-To: <20190930182810.6090-1-cyphar@cyphar.com> References: <20190930182810.6090-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 helps unify the syscall interface for struct-from-userspace syscalls. Signed-off-by: Aleksa Sarai --- kernel/events/core.c | 47 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 4655adbbae10..3f0cb82e4fbc 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -10586,55 +10586,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) + if (size < PERF_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; - attr->size = size; if (attr->__reserved_1) -- 2.23.0