From patchwork Wed Feb 14 17:11:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10219487 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 95E5B601C2 for ; Wed, 14 Feb 2018 17:10:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84E5B28F53 for ; Wed, 14 Feb 2018 17:10:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7850528FF2; Wed, 14 Feb 2018 17:10:22 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY 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 E8FE028F2B for ; Wed, 14 Feb 2018 17:10:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033321AbeBNRKT (ORCPT ); Wed, 14 Feb 2018 12:10:19 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:52804 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032907AbeBNRKS (ORCPT ); Wed, 14 Feb 2018 12:10:18 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1EH76dJ081139 for ; Wed, 14 Feb 2018 17:10:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=v/+TrJWmyWs2XOoJDYTo3GvAil41RcN9MzaaRlwGA/M=; b=WF3aI2Stfvj2dttxLBw0wR2lw8eyekHTleQ4LqBJtDmoAQupPyRBrAvJ8yVi1vbobV69 LHj+MMxmyOSH7y4d8b3GjaVLRSQObWyNcUm0SJAqfXe3lchHV355e5Nz+Avl9VYoG9+4 m6htS2zaCZC+ZuYw4cWTSb9yR81yOXZS77HFmNgP3H30dtwAE0tov4TtEIw/JXu+5aYK S2jzRooyOpFGy7F61hvrBrAZ4o4mKqGyxijLiRJBtx2zo72edPeUI9iymBXCG4s2y6Qi zn0FKUW8Th7vU+jwREkCcxGQvx1UA80Zinu85FXnRTkpn0LKBVOgWA3jqgjubj8XQ17Q kg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2g4pseh183-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 14 Feb 2018 17:10:18 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w1EHAHio014853 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 14 Feb 2018 17:10:17 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w1EHAHIZ023942 for ; Wed, 14 Feb 2018 17:10:17 GMT Received: from localhost.localdomain (/202.156.140.248) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 14 Feb 2018 09:10:15 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH v2] btrfs: verify subvolid mount parameter Date: Thu, 15 Feb 2018 01:11:37 +0800 Message-Id: <20180214171137.5589-1-anand.jain@oracle.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180213161042.GV3003@twin.jikos.cz> References: <20180213161042.GV3003@twin.jikos.cz> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8804 signatures=668670 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=683 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802140202 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We aren't verifying the parameter passed to the subvolid mount option, so we won't report and fail the mount if a junk value is specified for example, -o subvolid=abc. This patch verifies the subvolid option with match_u64. Signed-off-by: Anand Jain Reviewed-by: David Sterba --- v1->v2: Title changed. Old: btrfs: manage subvolid mount option with match_u64 Change log updated. keep the %s as token verification. fs/btrfs/super.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 10f7d0fbd50f..0333b8802a02 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -976,8 +976,8 @@ static int btrfs_parse_subvol_options(const char *options, fmode_t flags, { substring_t args[MAX_OPT_ARGS]; char *opts, *orig, *p; - char *num = NULL; int error = 0; + u64 subvolid; if (!options) return 0; @@ -1007,18 +1007,15 @@ static int btrfs_parse_subvol_options(const char *options, fmode_t flags, } break; case Opt_subvolid: - num = match_strdup(&args[0]); - if (num) { - *subvol_objectid = memparse(num, NULL); - kfree(num); - /* we want the original fs_tree */ - if (!*subvol_objectid) - *subvol_objectid = - BTRFS_FS_TREE_OBJECTID; - } else { - error = -EINVAL; + error = match_u64(&args[0], &subvolid); + if (error) goto out; - } + + /* we want the original fs_tree */ + if (subvolid == 0) + subvolid = BTRFS_FS_TREE_OBJECTID; + + *subvol_objectid = subvolid; break; case Opt_subvolrootid: pr_warn("BTRFS: 'subvolrootid' mount option is deprecated and has no effect\n");