From patchwork Mon Jun 19 23:36:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9798039 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7DC1B60381 for ; Mon, 19 Jun 2017 23:38:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A7AC27861 for ; Mon, 19 Jun 2017 23:38:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6EF2527F92; Mon, 19 Jun 2017 23:38:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 2174727861 for ; Mon, 19 Jun 2017 23:37:49 +0000 (UTC) Received: (qmail 11576 invoked by uid 550); 19 Jun 2017 23:37:01 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 11450 invoked from network); 19 Jun 2017 23:36:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VhqugdIhuRCUd8HTJ2D86xB3GMClCdUrCTi5qhCZ1Dk=; b=Ka4U5D7Zb4VfVqxiKCnppaZXSySBWOBQnucLOMTmkSxc2se6bY5HbcbD/b01js9v/t bEFQTF2AryQVcCwBrEUks0/oLc4ctWXKyzGvy3O9FmStegLL2LJ+oM7M9JPLNcjF9oQE IUqbPPiDAGEYlGKBtk3Gx5IxtFoxFWFXg36xU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VhqugdIhuRCUd8HTJ2D86xB3GMClCdUrCTi5qhCZ1Dk=; b=kF4/JsxEtYBjKd7+/uIPWtlH90SBHgJV6woN/YnEyBEgxPtFNrx3DUAoDkwVTSGTGB XBhmJ+MRVqrRXZzz6No2JyRtiZtGxHHJ0XB28T3mwaEOwPfk/EmIPdHBl80SIhLsFIV8 kBJt6mx1CCaWCEN/QiuYa6opaN+0KB2oYq1s+mqca1wWTWrIxRyByMhUNyFUIETBcx/W P3Lrpb9ntWsh1h6a+EBARQzRaXbdIhdDU9YpWPSM80NE9FBH5y+qbiIBhBFG2qr6CJCu aE+xzy7J5rHGkmgCd671OcCdafJyvhSVOLK8LeBjL21LEojw3/TkQz75NjklQP9dNZ0v C5fg== X-Gm-Message-State: AKS2vOx1bYF0djszTBUbekX5DEhONKznpiyFrLPVTZ86pCwWkwh97Uiv pmcfADP6B/yzy3V2 X-Received: by 10.99.100.68 with SMTP id y65mr17911140pgb.165.1497915406211; Mon, 19 Jun 2017 16:36:46 -0700 (PDT) From: Kees Cook To: kernel-hardening@lists.openwall.com Cc: Kees Cook , David Windsor , linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 19 Jun 2017 16:36:18 -0700 Message-Id: <1497915397-93805-5-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497915397-93805-1-git-send-email-keescook@chromium.org> References: <1497915397-93805-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 04/23] vfs: copy struct mount.mnt_id to userspace using put_user() X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor The mnt_id field can be copied with put_user(), so there is no need to use copy_to_user(). In both cases, hardened usercopy is being bypassed since the size is constant, and not open to runtime manipulation. This patch is verbatim from Brad Spengler/PaX Team's PAX_USERCOPY whitelisting code in the last public patch of grsecurity/PaX based on my understanding of the code. Changes or omissions from the original code are mine and don't reflect the original grsecurity/PaX code. Signed-off-by: David Windsor [kees: adjust commit log] Signed-off-by: Kees Cook --- fs/fhandle.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/fhandle.c b/fs/fhandle.c index 58a61f55e0d0..46e00ccca8f0 100644 --- a/fs/fhandle.c +++ b/fs/fhandle.c @@ -68,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path, } else retval = 0; /* copy the mount id */ - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id, - sizeof(*mnt_id)) || + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) || copy_to_user(ufh, handle, sizeof(struct file_handle) + handle_bytes)) retval = -EFAULT;