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: 9962417 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 7701060208 for ; Wed, 20 Sep 2017 20:47:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E531127F89 for ; Wed, 20 Sep 2017 20:47:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8C8B28553; Wed, 20 Sep 2017 20:47:16 +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 E652D27F89 for ; Wed, 20 Sep 2017 20:47:15 +0000 (UTC) Received: (qmail 3429 invoked by uid 550); 20 Sep 2017 20:46:15 -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 3261 invoked from network); 20 Sep 2017 20:46:13 -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=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=S+to4nmuW2dHjEQ4sh+1+UmgofIAkUZJ7BGypp66uA6NBfDl3qtn2RVKeEAQdgpOv5 3EggV5t2wo+R0hOkdIyhuf/wCqjurbGDhDL7nX2Jlt3R5N7lyqUjAXRsi61VqVrz70Wm srsWsv3xs7CxWVFPecf2o8rXyHJE+7wyXVdmtdPP8d68YB5B8pfCDKbq01qcr+mNWF69 peILEzjCtZwBUgy2tT0lBUU/p3jfMmByEq0imELGbz+PFfT+e/u53haY4Vsncuk01Rge L8cx2nRqQyk7rCMBK774fgq3zw38wc/6xbOGWRUrp5P6F/z7ED/btQgbqqmb3O7/kfzg IwTQ== X-Gm-Message-State: AHPjjUj5pAcaDaVIIdeCQ2gUh/9iP1gUWFxFnfqVh7yVwrs0igWkNFq5 l/aJBm6gtHw6esxZUoHbITiMbfPh5Pw= 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) 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 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> Subject: [kernel-hardening] [PATCH v3 06/31] 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;