From patchwork Thu Jul 26 17:35:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10546285 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 60A47174A for ; Thu, 26 Jul 2018 17:35:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4623D2B560 for ; Thu, 26 Jul 2018 17:35:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39F772B670; Thu, 26 Jul 2018 17:35:27 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,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 B84862B560 for ; Thu, 26 Jul 2018 17:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730250AbeGZSxO (ORCPT ); Thu, 26 Jul 2018 14:53:14 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:50460 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730781AbeGZSxO (ORCPT ); Thu, 26 Jul 2018 14:53:14 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6QHY1DO039014; Thu, 26 Jul 2018 17:35:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=UkchncDcb/s4Z1C3TiHjLKaK8Ll2zQVeVGVOSjkkYfY=; b=eCun+fgO4CojfvOEqGVLiwLKup6OkhfmSyQxoH6ecWU9Rxbo2huGP0Vuf/Wxrydiiq7p SWAxebzPe6VsPksfbKgGicn/pnwLA3Vb/1fN2gxetYekD7IV7iiUk6DEoXJhreiUjVGQ y7zQIAGu9mmFvG8w/YVy3cUWaxSboW9dfsnXTQwqfwRAJzOFGXDTOSmHxiaZlwrvkrlv jspef5OLL3sOenlz9VCN3SVOzYD4C1HFj34mKHe7M+FU/xtCwSel7w9r0sa/ToYAeZVp VTutv7KQHHr9lbu791MFVWv/AU6CQJKRisbbqM7NidW1hScB8XUcaFascR0mrWkYzUW1 Xw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2kbwfq446g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Jul 2018 17:35:21 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6QHZKpD021210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Jul 2018 17:35:21 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w6QHZKTI001358; Thu, 26 Jul 2018 17:35:20 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 26 Jul 2018 10:35:20 -0700 Subject: [PATCH 1/2] libxfs: add more bounds checking to sb sanity checks From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, billodo@redhat.com Date: Thu, 26 Jul 2018 10:35:19 -0700 Message-ID: <153262651940.8934.17525988748289196893.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8965 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807260181 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: Bill O'Donnell Current sb verifier doesn't check bounds on sb_fdblocks and sb_ifree. Add sanity checks for these parameters. Signed-off-by: Bill O'Donnell [darrick: remove the icount check, tweak the comments a little] Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: --- fs/xfs/libxfs/xfs_sb.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index b3ad15956366..b2c683588519 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -599,22 +599,16 @@ xfs_sb_to_disk( static int xfs_sb_verify( struct xfs_buf *bp, + struct xfs_sb *sb, bool check_version) { struct xfs_mount *mp = bp->b_target->bt_mount; - struct xfs_sb sb; - - /* - * Use call variant which doesn't convert quota flags from disk - * format, because xfs_mount_validate_sb checks the on-disk flags. - */ - __xfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp), false); /* * Only check the in progress field for the primary superblock as * mkfs.xfs doesn't clear it from secondary superblocks. */ - return xfs_mount_validate_sb(mp, &sb, + return xfs_mount_validate_sb(mp, sb, bp->b_maps[0].bm_bn == XFS_SB_DADDR, check_version); } @@ -637,6 +631,7 @@ xfs_sb_read_verify( { struct xfs_mount *mp = bp->b_target->bt_mount; struct xfs_dsb *dsb = XFS_BUF_TO_SBP(bp); + struct xfs_sb sb; int error; /* @@ -657,7 +652,13 @@ xfs_sb_read_verify( } } } - error = xfs_sb_verify(bp, true); + + /* + * Use call variant which doesn't convert quota flags from disk + * format, because xfs_mount_validate_sb checks the on-disk flags. + */ + __xfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp), false); + error = xfs_sb_verify(bp, &sb, true); out_error: if (error == -EFSCORRUPTED || error == -EFSBADCRC) @@ -693,9 +694,33 @@ xfs_sb_write_verify( { struct xfs_mount *mp = bp->b_target->bt_mount; struct xfs_buf_log_item *bip = bp->b_log_item; + struct xfs_sb sb; int error; - error = xfs_sb_verify(bp, false); + /* + * Use call variant which doesn't convert quota flags from disk + * format, because xfs_mount_validate_sb checks the on-disk flags. + */ + __xfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp), false); + + error = xfs_sb_verify(bp, &sb, false); + if (error) + goto err; + + /* + * Carry out additional sb sanity checks exclusively for writes. + * We don't do these checks for reads, since faulty parameters could + * be fixed in the log, and we shouldn't prohibit mounting for those + * cases. + */ + if (sb.sb_fdblocks > sb.sb_dblocks || + sb.sb_ifree > sb.sb_icount) { + xfs_notice(mp, "SB summary counter sanity check failed"); + error = -EFSCORRUPTED; + goto err; + } + +err: if (error) { xfs_verifier_error(bp, error, __this_address); return; From patchwork Thu Jul 26 17:35:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10546287 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 574B8112B for ; Thu, 26 Jul 2018 17:35:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 472C8287BF for ; Thu, 26 Jul 2018 17:35:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B47C2B645; Thu, 26 Jul 2018 17:35: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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,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 CDCDF287BF for ; Thu, 26 Jul 2018 17:35:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731294AbeGZSxY (ORCPT ); Thu, 26 Jul 2018 14:53:24 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:53842 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730781AbeGZSxY (ORCPT ); Thu, 26 Jul 2018 14:53:24 -0400 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 w6QHY3Gh039519; Thu, 26 Jul 2018 17:35:31 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=eFX1xn7ESjyWfXfTBrRdEy5bEU2Pqyh0w+7pN9w8XWo=; b=tT6xQwsHV8KZr2Bf7/hkivi6OoW4tUQQGDWsUntVG4DnguBQW4aIRJQy4GHSbUjQRvNq XiJUjdkg4RUVdaiFX4MgCA6Ojsab12+tu9zSTnLXraORxzzUsn/RX1ZlMhhdKsB30SaF lA6XRCbbb0zQVk7LjShUZARiSVYjFYij1QRsgBueiUNLbwIsbOYkSED9DbBklKuyAq1c bc/5Cmbgse8oOlsRGk6hnKNdmemaktMfAsQaY4KZlff7583S4xawWuPsYb2e1995eBHD WJ2qE81GpMR75KvUu+c4s4+efACI/mS/J0wppvxNs/K3s2eVwZYSeY9PMUIlBHj3u3iE kw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2kbv8tc5y1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Jul 2018 17:35:31 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6QHZU9v011859 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Jul 2018 17:35:30 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6QHZTGL025782; Thu, 26 Jul 2018 17:35:29 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 26 Jul 2018 10:35:29 -0700 Subject: [PATCH 2/2] xfs: verify icount in superblock write From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, billodo@redhat.com Date: Thu, 26 Jul 2018 10:35:25 -0700 Message-ID: <153262652554.8934.816888163232208002.stgit@magnolia> In-Reply-To: <153262651940.8934.17525988748289196893.stgit@magnolia> References: <153262651940.8934.17525988748289196893.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8965 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807260181 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 Add a helper predicate to check the inode count for sanity, then use it in the superblock write verifier to inspect sb_icount. Signed-off-by: Darrick J. Wong Reviewed-by: Bill O'Donnell --- fs/xfs/libxfs/xfs_sb.c | 1 + fs/xfs/libxfs/xfs_types.c | 34 ++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_types.h | 1 + 3 files changed, 36 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index b2c683588519..1659016875f9 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -714,6 +714,7 @@ xfs_sb_write_verify( * cases. */ if (sb.sb_fdblocks > sb.sb_dblocks || + !xfs_verify_icount(mp, sb.sb_icount) || sb.sb_ifree > sb.sb_icount) { xfs_notice(mp, "SB summary counter sanity check failed"); error = -EFSCORRUPTED; diff --git a/fs/xfs/libxfs/xfs_types.c b/fs/xfs/libxfs/xfs_types.c index 2e2a243cef2e..2e9c0c25ccb6 100644 --- a/fs/xfs/libxfs/xfs_types.c +++ b/fs/xfs/libxfs/xfs_types.c @@ -171,3 +171,37 @@ xfs_verify_rtbno( { return rtbno < mp->m_sb.sb_rblocks; } + +/* Calculate the range of valid icount values. */ +static void +xfs_icount_range( + struct xfs_mount *mp, + unsigned long long *min, + unsigned long long *max) +{ + unsigned long long nr_inos = 0; + xfs_agnumber_t agno; + + /* root, rtbitmap, rtsum all live in the first chunk */ + *min = XFS_INODES_PER_CHUNK; + + for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) { + xfs_agino_t first, last; + + xfs_agino_range(mp, agno, &first, &last); + nr_inos += first - last + 1; + } + *max = nr_inos; +} + +/* Sanity-checking of inode counts. */ +bool +xfs_verify_icount( + struct xfs_mount *mp, + unsigned long long icount) +{ + unsigned long long min, max; + + xfs_icount_range(mp, &min, &max); + return icount >= min && icount < max; +} diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h index 4055d62f690c..b9e6c89284c3 100644 --- a/fs/xfs/libxfs/xfs_types.h +++ b/fs/xfs/libxfs/xfs_types.h @@ -165,5 +165,6 @@ bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino); bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino); bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino); bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno); +bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount); #endif /* __XFS_TYPES_H__ */