From patchwork Wed Sep 20 20:45:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9962487 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 2A42260208 for ; Wed, 20 Sep 2017 20:50:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C30429178 for ; Wed, 20 Sep 2017 20:50:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1131329233; Wed, 20 Sep 2017 20:50:55 +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 9D03829178 for ; Wed, 20 Sep 2017 20:50:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751858AbdITUqG (ORCPT ); Wed, 20 Sep 2017 16:46:06 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:46875 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751825AbdITUqC (ORCPT ); Wed, 20 Sep 2017 16:46:02 -0400 Received: by mail-pf0-f171.google.com with SMTP id r68so2115265pfj.3 for ; Wed, 20 Sep 2017 13:46:02 -0700 (PDT) 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=hjNQ5NMmJ5Of4XDVARaOl907lggYVZ5uHzxPaSMpDcLOH3ouV7COV2RymEFfwXIwcE dc8aGAeWX0+L/Qs/6uqRTMEBfuBO2aPc9Q8+yej4GOQ4MJo25E0Cxa+fuSeSrjRGFDKx ULKmjVFILk7k1xzVberYW8aDxGHPqqZbt5alw= 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=rrS5+U2ofBHMlQ0riKJqhuaw9gAGiJOjty4CgdX15UxiqhBxR5woRy1rwYbNRDWXCJ lU5ILMoPwA9kCTDM4vVszwmG+C7nVQ3NRN2msGwIdaO0NLH6cHRvsEYejvJotKk8Wu9X t5MOgEaRXmfVLyAwkNQjsfdsPyVrRvbgLa7g+k1E/7QGliNUGMxntbsnZM017Rv9B0ww J9BWJijmW2PJO3ajeVICLomdMmk24G5QmdERsJt14r6EiaznJolcEqYkN5ReH45CsHx9 sAkOLcshk2/GDqtMuLQf1iYbKk+EQQp/8e1zrEP0LRRhDFUJo6SSWYYrs6jnkXRPY9bt aS9Q== X-Gm-Message-State: AHPjjUiUbOeTC/kB7tYXraFrHPdJWgSRhh1rfYOnw6AJwpACQT0Mpye+ 6WoJ194GCj7D4p1KEkXE6MTmFg== X-Google-Smtp-Source: AOwi7QBQxBxW6CiwDwHyxAioBQ4iDn9rEdZKZbnUou3AZbvR9AnCwwjvv8xGEFacqVp47e0oGTZvzw== X-Received: by 10.99.119.133 with SMTP id s127mr3486949pgc.271.1505940361948; Wed, 20 Sep 2017 13:46:01 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id l66sm8177273pfl.156.2017.09.20.13.45.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Sep 2017 13:46:00 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , Alexander Viro , linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Subject: [PATCH v3 06/31] vfs: Copy struct mount.mnt_id to userspace using put_user() Date: Wed, 20 Sep 2017 13:45:12 -0700 Message-Id: <1505940337-79069-7-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505940337-79069-1-git-send-email-keescook@chromium.org> References: <1505940337-79069-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 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;