From patchwork Mon Aug 28 21:34:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9926253 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 464BC60375 for ; Mon, 28 Aug 2017 21:36:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39D5F287CE for ; Mon, 28 Aug 2017 21:36:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EA09287D4; Mon, 28 Aug 2017 21:36:50 +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=-2.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, URIBL_BLACK 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 3FD0F287CE for ; Mon, 28 Aug 2017 21:36:49 +0000 (UTC) Received: (qmail 12150 invoked by uid 550); 28 Aug 2017 21:35:36 -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 11923 invoked from network); 28 Aug 2017 21:35:33 -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=q79OKAMqF+dEH75tkt9jXSO5So9k1x8IdjLEiB288JE=; b=Tgn6VbASwLM+qGuBrrJQbVmVCM8g67KgN4UYUfMShzDmvZbsyC/kQOmPgho+puZ+Gl Jv5XzA7S/meeX+QiBEQFy8VZq1cD2ifSo2rf/XS6W8iFXWdTTD7TGVDrEEEa7zjRkL4k nvWXfah72tUVGs5G0pkgvxbFWg3wIQJRBdWxM= 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=q79OKAMqF+dEH75tkt9jXSO5So9k1x8IdjLEiB288JE=; b=Op1n1lFdF+tuhf0U9LtsDlEhGdnJIvuID3lIroQfwuXLTMYGysHc9hXKIPYnk73gN0 E2hyV6J2F7s/1v11mV5vtZLtWk/ccsF7sb4qgf+1C3BNRHsZCY9i73IpUDVkPwUh9chW 3frgVRNJOL9fAuP2pIaKAYria05LQaB+fpnaQ4nA4cZMrvrSWvixRJkua9qOxvZfdrx+ 3rDWnvYZ7fJSYQX3tucKOSVEPtMQQNeYkt2NwKxKuGggmq9x8cZ5VlYsf8sScI4+GW3+ Ok4noCZhEgI8gBtUOhzalLsCSLe8gbHRc7waLY2iFu5OBFTXhZ72k5H717AS28/z+Cdl 7ZDw== X-Gm-Message-State: AHYfb5itjmR7XBG89SDyDP6Cuq1x5TE4ZpHtQpJ24r0lHZ8cNHl1viIW 7kxWDrIo1a2Azvuk X-Received: by 10.99.119.70 with SMTP id s67mr1780820pgc.181.1503956121134; Mon, 28 Aug 2017 14:35:21 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Date: Mon, 28 Aug 2017 14:34:47 -0700 Message-Id: <1503956111-36652-7-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503956111-36652-1-git-send-email-keescook@chromium.org> References: <1503956111-36652-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH v2 06/30] 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] Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org 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;