From patchwork Tue Jun 14 02:36:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Lutomirski X-Patchwork-Id: 9174901 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 7FC0E6044F for ; Tue, 14 Jun 2016 02:36:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72CA92804C for ; Tue, 14 Jun 2016 02:36:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 675EA281BE; Tue, 14 Jun 2016 02:36:15 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 19F232804C for ; Tue, 14 Jun 2016 02:36:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422921AbcFNCgL (ORCPT ); Mon, 13 Jun 2016 22:36:11 -0400 Received: from mail.kernel.org ([198.145.29.136]:58896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422844AbcFNCgK (ORCPT ); Mon, 13 Jun 2016 22:36:10 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AAAF20160; Tue, 14 Jun 2016 02:36:09 +0000 (UTC) Received: from localhost (c-71-202-137-17.hsd1.ca.comcast.net [71.202.137.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5CEF220172; Tue, 14 Jun 2016 02:36:08 +0000 (UTC) From: Andy Lutomirski To: Linux FS Devel , Al Viro Cc: Stephen Rothwell , Andrew Morton , Andy Lutomirski Subject: [PATCH v2 2/2] fs: Disallow mount options strings longer than PAGE_SIZE - 1 Date: Mon, 13 Jun 2016 19:36:05 -0700 Message-Id: <729cc8635d7927ecbe81b3bdb337e31ee61a1e14.1465871650.git.luto@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: ClamAV using ClamSMTP 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 We used to truncate the string. Make the behaviour of mount() more predictable: return -EINVAL if the string is too long. Signed-off-by: Andy Lutomirski --- fs/namespace.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 8644f1961ca6..96e6b09df7d1 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2582,8 +2582,7 @@ static void shrink_submounts(struct mount *mnt) } /* Copy the mount options string. Always returns a full page padded - * with nulls. If the input string is a full page or more, it may be - * truncated and the result will not be null-terminated. + * with nulls and guarantees that the result is null-terminated. */ void *copy_mount_options(const void __user *data) { @@ -2603,7 +2602,12 @@ void *copy_mount_options(const void __user *data) return ERR_PTR(size); } - /* If we got less than PAGE_SIZE bytes, zero out the remainder. */ + if (size >= PAGE_SIZE) { + kfree(copy); + return ERR_PTR(-EINVAL); + } + + /* Pad with zeros. */ memset(copy + size, 0, PAGE_SIZE - size); return copy; @@ -2639,10 +2643,6 @@ long do_mount(const char *dev_name, const char __user *dir_name, if ((flags & MS_MGC_MSK) == MS_MGC_VAL) flags &= ~MS_MGC_MSK; - /* Basic sanity checks */ - if (data_page) - ((char *)data_page)[PAGE_SIZE - 1] = 0; - /* ... and get the mountpoint */ retval = user_path(dir_name, &path); if (retval)