From patchwork Fri Jun 10 20:11:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Lutomirski X-Patchwork-Id: 9170417 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 3B627607DA for ; Fri, 10 Jun 2016 20:11:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29389281F9 for ; Fri, 10 Jun 2016 20:11:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DF89282F9; Fri, 10 Jun 2016 20:11:37 +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 BB0FC282F9 for ; Fri, 10 Jun 2016 20:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752616AbcFJULf (ORCPT ); Fri, 10 Jun 2016 16:11:35 -0400 Received: from mail.kernel.org ([198.145.29.136]:59840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751985AbcFJULd (ORCPT ); Fri, 10 Jun 2016 16:11:33 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0755A20295; Fri, 10 Jun 2016 20:11:32 +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 3E7CD202A1; Fri, 10 Jun 2016 20:11:31 +0000 (UTC) From: Andy Lutomirski To: Linux FS Devel , Al Viro Cc: Stephen Rothwell , Andrew Morton , Andy Lutomirski Subject: [PATCH 2/2] fs: Disallow mount options strings longer than PAGE_SIZE - 1 Date: Fri, 10 Jun 2016 13:11:25 -0700 Message-Id: <0f95d6c681d1aa81ea62991ea031441688b70318.1465589343.git.luto@kernel.org> X-Mailer: git-send-email 2.5.5 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 dfb5f370f2fa..0467f461dbd8 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) { @@ -2601,7 +2600,12 @@ void *copy_mount_options(const void __user *data) if (size < 0) 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); return copy; @@ -2637,10 +2641,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)