From patchwork Mon Aug 28 21:34:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9926287 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 357DB60383 for ; Mon, 28 Aug 2017 21:38:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29660287DB for ; Mon, 28 Aug 2017 21:38:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E5FD287D2; Mon, 28 Aug 2017 21:38: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=-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 E0AFE287D5 for ; Mon, 28 Aug 2017 21:38:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751323AbdH1ViJ (ORCPT ); Mon, 28 Aug 2017 17:38:09 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:36130 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751437AbdH1VfV (ORCPT ); Mon, 28 Aug 2017 17:35:21 -0400 Received: by mail-pg0-f43.google.com with SMTP id r133so4954510pgr.3 for ; Mon, 28 Aug 2017 14:35:21 -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=Tgn6VbASwLM+qGuBrrJQbVmVCM8g67KgN4UYUfMShzDmvZbsyC/kQOmPgho+puZ+Gl Jv5XzA7S/meeX+QiBEQFy8VZq1cD2ifSo2rf/XS6W8iFXWdTTD7TGVDrEEEa7zjRkL4k nvWXfah72tUVGs5G0pkgvxbFWg3wIQJRBdWxM= 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=TaqTknE7r1/QihY8SibJJBqcLojxcL27lQ3N3xLBDs4Qt0FQ2R3pdhGbOvYAnULKXF pJXdZt12P1lN89lP9XpaBrrf0I06cLzHYGNILk02B0XlZ9xIlwFLZoOQGN8o1dIMGZpv L75XPQwZobk8twkky9UIeWO6JVZkjvna5AIr1rirI+7TYGCIBqUM0whSKnvuiNJCzSYn OLD4Ig4SAfuldzEMnoj+VubustinIPGk29YnDr1USJjkLCn7i88vJzN7uN9as2MgiTj0 c2tlsBtaASeY0cINjB8SyAbovgKqLTfhpOajc69ArrxtL9XxD0NnBYJnVUwcISGrBRIK 1Pwg== X-Gm-Message-State: AHYfb5gisHdXZc+BQNg/32PKsL9uIfj5j3M/oy3ckZbHOMBAa0LX7Kg2 D7727btIx96iy2E1QOBniQ== X-Received: by 10.99.119.70 with SMTP id s67mr1780820pgc.181.1503956121134; Mon, 28 Aug 2017 14:35:21 -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 h70sm2499062pfc.92.2017.08.28.14.35.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Aug 2017 14:35:19 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , Alexander Viro , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Subject: [PATCH v2 06/30] vfs: Copy struct mount.mnt_id to userspace using put_user() Date: Mon, 28 Aug 2017 14:34:47 -0700 Message-Id: <1503956111-36652-7-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503956111-36652-1-git-send-email-keescook@chromium.org> References: <1503956111-36652-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;