From patchwork Tue Jan 9 20:55:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10153425 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 0D2C560223 for ; Tue, 9 Jan 2018 21:04:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04B012040D for ; Tue, 9 Jan 2018 21:04:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECD28204C4; Tue, 9 Jan 2018 21:04:20 +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 1CF0A20453 for ; Tue, 9 Jan 2018 21:04:19 +0000 (UTC) Received: (qmail 10137 invoked by uid 550); 9 Jan 2018 20:57:53 -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 9490 invoked from network); 9 Jan 2018 20:57:30 -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=YYfC+DZQIpooLWprJKwbjG+yk8h1hsIjZlvBMsoOx2U=; b=JWZbhbph5Wajrv3Vj41GvN77On2Hu808IUALWtWpbxQ6PO3dNCGKGsaabI01ZLvD1d n7TdkKLjl3yjD9A5xmFvVmjMursnMVsBsfw/W8u7zBaQjyiWQ5JR47PNgO5TQqkV/DKS OHHeZgIgZ8/uBR2E1JtzikieEyV117HC9gaAA= 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=YYfC+DZQIpooLWprJKwbjG+yk8h1hsIjZlvBMsoOx2U=; b=oAF96kDozzwWn3qv6kxFWxTicSF5IrhCw21ZTFLB7UKovnGLt+ux8kZnRIyLVrQa53 7iG3EZjWNsXXFV3ANf1LUFGg++4txCr3mrmdQIsuQ1QzwOCT6cN+3IK2aBvfnydyTZwE 8iU7Y/WcAAKiQu11tMqvVgN80/Y1DZ/IiY72W9qkdIxdzy9+wDc8KzSdLioPV8F+K1KY 5n7KSakyvXixQTIcrwHhx/G711LSfscuXDgEuq06PSt3c/AQQdFpoJRJ7zD0vwJE6xqA N/lGuR6uEX0Oq31F8snjZStTMN9HEiLvVvyDNAGl7fDfVs5UgNxF/bShcXrcNMEIGGRL gUUQ== X-Gm-Message-State: AKGB3mKyDD4g2IkEQsWidrYDhQFedLOcdD12O1O2x7eAL1zRSjoYt0g8 A2KRrGvUWhqO/n+m2svsqICpNz2hpak= X-Google-Smtp-Source: ACJfBostf40lCxLXGBx3BuNjIicczxaOkbZJFPmrnR49nPUrRZMvhh3Sl2GVWDEKe6zZ9ydSewfiBg== X-Received: by 10.159.247.203 with SMTP id v11mr11808466plz.259.1515531439252; Tue, 09 Jan 2018 12:57:19 -0800 (PST) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , Alexander Viro , linux-fsdevel@vger.kernel.org, Linus Torvalds , Andrew Morton , Andy Lutomirski , Christoph Hellwig , Christoph Lameter , "David S. Miller" , Laura Abbott , Mark Rutland , "Martin K. Petersen" , Paolo Bonzini , Christian Borntraeger , Christoffer Dall , Dave Kleikamp , Jan Kara , Luis de Bethencourt , Marc Zyngier , Rik van Riel , Matthew Garrett , linux-arch@vger.kernel.org, netdev@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Date: Tue, 9 Jan 2018 12:55:38 -0800 Message-Id: <1515531365-37423-10-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515531365-37423-1-git-send-email-keescook@chromium.org> References: <1515531365-37423-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 09/36] 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 0ace128f5d23..0ee727485615 100644 --- a/fs/fhandle.c +++ b/fs/fhandle.c @@ -69,8 +69,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;