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;