From patchwork Tue Jul 11 14:04:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Rajendra X-Patchwork-Id: 9834785 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 7D28F602BD for ; Tue, 11 Jul 2017 14:04:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D47D283BB for ; Tue, 11 Jul 2017 14:04:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 605352842A; Tue, 11 Jul 2017 14:04:13 +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 D164A283BB for ; Tue, 11 Jul 2017 14:04:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755900AbdGKOEL (ORCPT ); Tue, 11 Jul 2017 10:04:11 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56337 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755627AbdGKOEL (ORCPT ); Tue, 11 Jul 2017 10:04:11 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6BE3tRr028995 for ; Tue, 11 Jul 2017 10:04:10 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bmd1q7aea-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 11 Jul 2017 10:04:10 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 11 Jul 2017 08:04:06 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 11 Jul 2017 08:04:02 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v6BE42rj983508; Tue, 11 Jul 2017 07:04:02 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 73E6CBE047; Tue, 11 Jul 2017 08:04:02 -0600 (MDT) Received: from localhost.localdomain.com (unknown [9.102.3.119]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id 87722BE038; Tue, 11 Jul 2017 08:04:00 -0600 (MDT) 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 V2] get_fs_type: Validate fs type string argument Date: Tue, 11 Jul 2017 19:34:21 +0530 X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170711134709.29343-1-chandan@linux.vnet.ibm.com> References: <20170711134709.29343-1-chandan@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17071114-0020-0000-0000-00000C586F6D X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007349; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00886040; UDB=6.00442242; IPR=6.00666190; BA=6.00005468; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016177; XFM=3.00000015; UTC=2017-07-11 14:04:05 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17071114-0021-0000-0000-00005D324318 Message-Id: <20170711140421.31205-1-chandan@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-11_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=2 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1707110221 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 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 also it is signed data type. Hence an invalid value ends up getting 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 --- Changelog: v1->v2: Fix commit message. 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);