From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:59306 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755296AbdGKNrO (ORCPT ); Tue, 11 Jul 2017 09:47:14 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6BDhu4Q143815 for ; Tue, 11 Jul 2017 09:47:13 -0400 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bmb56unp9-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 11 Jul 2017 09:47:13 -0400 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 11 Jul 2017 07:47:12 -0600 From: Chandan Rajendra To: linux-fsdevel@vger.kernel.org Cc: Chandan Rajendra , viro@zeniv.linux.org.uk, abdhalee@linux.vnet.ibm.com, joe@perches.com Subject: [PATCH] get_fs_type: Validate fs type string argument Date: Tue, 11 Jul 2017 19:17:09 +0530 Message-Id: <20170711134709.29343-1-chandan@linux.vnet.ibm.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On ppc64, When a non-nul terminated string is passed as an argument to the mount(2) syscall, copy_mount_string() ends up allocating 64k (the PAGE_SIZE on ppc64) worth of space for holding the string in kernel's address space. Later, in set_precision() (invoked indirectly by get_fs_type()), we end up assigning 65535 as the value to 'struct printf_spec'->precision member. This field has a width of 16 bits and hence a truncated version of the original value ends up being assigned. This causes the "WARN_ONCE(spec->precision != prec, "precision %d too large", prec)" statement inside set_precision() to be executed. This commit fixes the bug by validating the length of the "filesystem type" argument passed to get_fs_type() function. Signed-off-by: Chandan Rajendra Reported-by: Abdul Haleem Suggested-by: Joe Perches --- fs/filesystems.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/filesystems.c b/fs/filesystems.c index a920ad2..8e309d3 100644 --- a/fs/filesystems.c +++ b/fs/filesystems.c @@ -275,6 +275,9 @@ struct file_system_type *get_fs_type(const char *name) const char *dot = strchr(name, '.'); int len = dot ? dot - name : strlen(name); + if (len >= PATH_MAX) + return NULL; + fs = __get_fs_type(name, len); if (!fs && (request_module("fs-%.*s", len, name) == 0)) { fs = __get_fs_type(name, len); -- 2.9.4