From patchwork Thu Jan 11 02:02:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10156505 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 9E1EC605BA for ; Thu, 11 Jan 2018 02:06:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D9C52870B for ; Thu, 11 Jan 2018 02:06:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81A0928710; Thu, 11 Jan 2018 02:06:59 +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 904EE2870B for ; Thu, 11 Jan 2018 02:06:58 +0000 (UTC) Received: (qmail 30438 invoked by uid 550); 11 Jan 2018 02:03: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 30111 invoked from network); 11 Jan 2018 02:03:43 -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=FxPVLo7D5euDvATB0Q+y27QSEAdf6d6XsYKzwdF7Kxg7E62VRgHgXYG1RrrVgoN8bU j9q839SyDf+suV8ZOt7rMpO4LU0TLuaF0TLmhFEELTeVrx46LkIbK6/ZpVH2Jwa5z0sy lYnWVMLAu0UZiJTsXwrTzxM35RYMQARrPOmEY= 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=LyCGbYUqrB3tg7PxBJW4/7pD9bV5NCJJybGd3TPbT736FPxGodbwXpLY4MshVNUxdR yD5r8ycms2t6QjWBlKnzaFp4MbUMihiGszbIb6mOGsARXyQHbjlNXev5XVfkJNe37e8m VROMXfuYPfOBJJnCf8gkPzQDFg2yAeDeOsqQuNCXhdyq2CabLrJPjEdOQBiy237rI2bA lkFYKufW+mpsJhfBOtLJxGWO1rpl9qzPuh79N2+uEKXOBJ8vZw9N/IvJXkVQbRpv28IL gboqMAPewx9TVpgh7jKHm9Can4+06SLSAF5J4DXPS0OMBydvcV5cyq4pSneBA9z89Kf8 23vg== X-Gm-Message-State: AKGB3mKB8RVOV/KWOjYQANvGJrEU3IzcEpkNWhPHTyHjaKufz9Hs9u5l ft+XLNcQTrrBV2n437FerY79SA== X-Google-Smtp-Source: ACJfBosWfqxr803EtBuD/0EIVevWGYO7xlqpVBMUefRzhgvjWiP4ZB3jjwuBUI0cdQYvDMCc7THDcw== X-Received: by 10.99.148.26 with SMTP id m26mr16305288pge.157.1515636211936; Wed, 10 Jan 2018 18:03:31 -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: Wed, 10 Jan 2018 18:02:44 -0800 Message-Id: <1515636190-24061-13-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515636190-24061-1-git-send-email-keescook@chromium.org> References: <1515636190-24061-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 12/38] 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;