From patchwork Thu Mar 14 21:05:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10853619 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 639E717E6 for ; Thu, 14 Mar 2019 21:05:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C22D2A7A6 for ; Thu, 14 Mar 2019 21:05:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4899C2A790; Thu, 14 Mar 2019 21:05:40 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 C87172A23B for ; Thu, 14 Mar 2019 21:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727749AbfCNVFj (ORCPT ); Thu, 14 Mar 2019 17:05:39 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51438 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727366AbfCNVFj (ORCPT ); Thu, 14 Mar 2019 17:05:39 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2EKwvMg102645; Thu, 14 Mar 2019 21:05:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=1Y+TgiHXC4enoSZLJFqz6aZ+nZOyO9wBGg3LPdfcmSw=; b=LdBpQnHwKmZXYtXsEyiZnMpM5cFepb9C/B4vWgKnAcFavUBMCVdf/uyl94tnuGue2u/F J7TXeQhhefLqHRHRQFzVVM7+1zsnyTxrnHlJCqB7Jjv4saOhU/LPdVjE01LvzZ1VPgia bQVfVfeYJtxGkSNopZKOkuLklRWToWit/TE9S3t0h1FsFuYXXbobFXSanEvNuPR/YoMH 6DZFbh1heeK3QB4jGzgTbXxqMJEfbqDxgX0RsXdq2R0QvQQdp3sKQCS1rnYyGdnwdCXG +iMTVdQ5kQBILgE6lfjisK6qwNpvqYo2V0TRlxkjkL/Cu+DrcRidNgBq9IahjYN739GE Dw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2r464ruejg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Mar 2019 21:05:36 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x2EL5ZcF019905 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Mar 2019 21:05:36 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x2EL5ZqV001182; Thu, 14 Mar 2019 21:05:35 GMT Received: from localhost (/10.145.178.102) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 14 Mar 2019 21:05:35 +0000 Subject: [PATCH 17/36] xfs_scrub: check label for misleading characters From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 14 Mar 2019 14:05:35 -0700 Message-ID: <155259753535.31886.7933186379056372168.stgit@magnolia> In-Reply-To: <155259742281.31886.17157720770696604377.stgit@magnolia> References: <155259742281.31886.17157720770696604377.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9195 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903140143 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Make sure that we can retrieve the label and that it doesn't contain anything potentially misleading. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen --- scrub/phase5.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ scrub/unicrash.c | 24 ++++++++++++++++++++++++ scrub/unicrash.h | 5 +++++ 3 files changed, 83 insertions(+) diff --git a/scrub/phase5.c b/scrub/phase5.c index 6ffcec2d..49886e6f 100644 --- a/scrub/phase5.c +++ b/scrub/phase5.c @@ -11,6 +11,7 @@ #ifdef HAVE_LIBATTR # include #endif +#include #include "handle.h" #include "list.h" #include "path.h" @@ -282,6 +283,55 @@ xfs_scrub_connections( return *pmoveon ? 0 : XFS_ITERATE_INODES_ABORT; } +#ifndef FS_IOC_GETFSLABEL +# define FSLABEL_MAX 256 +# define FS_IOC_GETFSLABEL _IOR(0x94, 49, char[FSLABEL_MAX]) +#endif /* FS_IOC_GETFSLABEL */ + +/* + * Check the filesystem label for Unicode normalization problems or misleading + * sequences. + */ +static bool +xfs_scrub_fs_label( + struct scrub_ctx *ctx) +{ + char label[FSLABEL_MAX]; + struct unicrash *uc = NULL; + bool moveon = true; + int error; + + moveon = unicrash_fs_label_init(&uc, ctx); + if (!moveon) + return false; + + /* Retrieve label; quietly bail if we don't support that. */ + error = ioctl(ctx->mnt_fd, FS_IOC_GETFSLABEL, &label); + if (error) { + if (errno != EOPNOTSUPP && errno != ENOTTY) { + moveon = false; + perror(ctx->mntpoint); + } + goto out; + } + + /* Ignore empty labels. */ + if (label[0] == 0) + goto out; + + /* Otherwise check for weirdness. */ + if (uc) + moveon = unicrash_check_fs_label(uc, ctx->mntpoint, label); + else + moveon = xfs_scrub_check_name(ctx, ctx->mntpoint, + _("filesystem label"), label); + if (!moveon) + goto out; +out: + unicrash_free(uc); + return moveon; +} + /* Check directory connectivity. */ bool xfs_scan_connections( @@ -296,6 +346,10 @@ _("Filesystem has errors, skipping connectivity checks.")); return true; } + moveon = xfs_scrub_fs_label(ctx); + if (!moveon) + return false; + ret = xfs_scan_all_inodes(ctx, xfs_scrub_connections, &moveon); if (!ret) moveon = false; diff --git a/scrub/unicrash.c b/scrub/unicrash.c index a95fc305..121eedbc 100644 --- a/scrub/unicrash.c +++ b/scrub/unicrash.c @@ -465,6 +465,15 @@ unicrash_xattr_init( is_only_root_writable(bstat)); } +/* Initialize the collision detector for a filesystem label. */ +bool +unicrash_fs_label_init( + struct unicrash **ucp, + struct scrub_ctx *ctx) +{ + return unicrash_init(ucp, ctx, false, 16, true); +} + /* Free the crash detector. */ void unicrash_free( @@ -698,3 +707,18 @@ unicrash_check_xattr_name( return __unicrash_check_name(uc, descr, _("extended attribute"), attrname, 0); } + +/* + * Check the fs label for unicode normalization problems or misleading bits. + */ +bool +unicrash_check_fs_label( + struct unicrash *uc, + const char *descr, + const char *label) +{ + if (!uc) + return true; + return __unicrash_check_name(uc, descr, _("filesystem label"), + label, 0); +} diff --git a/scrub/unicrash.h b/scrub/unicrash.h index 7d7276a8..85fcabc6 100644 --- a/scrub/unicrash.h +++ b/scrub/unicrash.h @@ -17,17 +17,22 @@ bool unicrash_dir_init(struct unicrash **ucp, struct scrub_ctx *ctx, struct xfs_bstat *bstat); bool unicrash_xattr_init(struct unicrash **ucp, struct scrub_ctx *ctx, struct xfs_bstat *bstat); +bool unicrash_fs_label_init(struct unicrash **ucp, struct scrub_ctx *ctx); void unicrash_free(struct unicrash *uc); bool unicrash_check_dir_name(struct unicrash *uc, const char *descr, struct dirent *dirent); bool unicrash_check_xattr_name(struct unicrash *uc, const char *descr, const char *attrname); +bool unicrash_check_fs_label(struct unicrash *uc, const char *descr, + const char *label); #else # define unicrash_dir_init(u, c, b) (true) # define unicrash_xattr_init(u, c, b) (true) +# define unicrash_label_init(u, c) (true) # define unicrash_free(u) do {(u) = (u);} while (0) # define unicrash_check_dir_name(u, d, n) (true) # define unicrash_check_xattr_name(u, d, n) (true) +# define unicrash_check_fs_label(u, d, n) (true) #endif /* HAVE_LIBICU */ #endif /* XFS_SCRUB_UNICRASH_H_ */