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: 10153403 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 C544960223 for ; Tue, 9 Jan 2018 21:03:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC1CE20453 for ; Tue, 9 Jan 2018 21:03:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0D2A2097A; Tue, 9 Jan 2018 21:03:04 +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=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, URIBL_BLACK autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46D2520453 for ; Tue, 9 Jan 2018 21:03:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759831AbeAIVAs (ORCPT ); Tue, 9 Jan 2018 16:00:48 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:45002 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759828AbeAIU5T (ORCPT ); Tue, 9 Jan 2018 15:57:19 -0500 Received: by mail-pg0-f67.google.com with SMTP id i5so8812719pgq.11 for ; Tue, 09 Jan 2018 12:57:19 -0800 (PST) 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=jQ49dwmEGjpIInSWMVfUBpoLUpVzYoo9HjemfMl6xeIA4IJhcdIaVwBTIlwrzdPQ3y c9Y75hbJoPnQ9f3OGKTG1sC7R4lif5XEKPZfQlPB0Zp80RL5FToJlxa0vueU5WyW1t43 0bOBDTa293i4bOZj6Ir2OdaBqNgRob147IIsACzO43kTmnh9nVozFpqYL5hMk2nhMogT PADBMswHjIgoApoSfiqB96YI5koTjmh/dBAVfxxJYNoUOUkAT4kz1MEX8LI1J4LZb1P7 OLI+igEYsA/1VZIPMX0HnUXjWKol023hgsXpLguzpsZ2zT8XMfsvLj7pV4Mm802TEj9Y y8JA== X-Gm-Message-State: AKGB3mLfHb8/1HEu3Ca403Yf7MWUQhGmf7Rp2aSkALG4LW7CksTbWH4A NN+YS32i8DhzTyMrBxURbLxtIQ== 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) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id z13sm5801204pgp.28.2018.01.09.12.56.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 12:57:18 -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 Subject: [PATCH 09/36] vfs: Copy struct mount.mnt_id to userspace using put_user() 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> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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;