From patchwork Thu Aug 31 14:09:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9932285 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 4F25360309 for ; Thu, 31 Aug 2017 14:09:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4200D28514 for ; Thu, 31 Aug 2017 14:09:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36A8E28660; Thu, 31 Aug 2017 14:09:36 +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 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 AD96328514 for ; Thu, 31 Aug 2017 14:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751285AbdHaOJe (ORCPT ); Thu, 31 Aug 2017 10:09:34 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:51163 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751286AbdHaOJe (ORCPT ); Thu, 31 Aug 2017 10:09:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=vtEi1DYLrEQmYU0uVin6iCh0dZ4JpgBinxHhYzXdUAg=; b=d4IWLeTzso6FBXPA+NCOcU+6d KiuBn3Pfwv9MvpnsxG1OjrWxjTlKQ7Sp/wkGLJHoZ+q7QWKgtQlPyMzVvF3dT52ftlthFsk1sbWHK qGfdwR/qyQZwhFNZKNC7holJPrJ4BTRiyUfYXfHElJo7qRASj0B/1VK5WI+4ZkqshyqS7iFMdRU1g 28JEaBjkOFhzUDU3NCSPSaV/C6WZ04mYKtQeVY/B2LRayy9vf7MIN6QQh8ylOnRH/8P2bLQ1sp4LG tpaaDQfPyPVkxeyVfXYoPNfxYPGrwUuVjdW7qXAQFOpMPHnoXIEUPbcjiG9MMCvwB+gJkj3BQNCOB VivkFf47w==; Received: from hch by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1dnQA0-0007t6-GG; Thu, 31 Aug 2017 14:09:32 +0000 Date: Thu, 31 Aug 2017 07:09:32 -0700 From: Christoph Hellwig To: Brian Foster Cc: Christoph Hellwig , "Darrick J. Wong" , xfs , Jan Kara Subject: Re: [PATCH v2] xfs: don't set v3 xflags for v2 inodes Message-ID: <20170831140932.GB26555@infradead.org> References: <20170830155517.GI4757@magnolia> <20170830163825.GQ4757@magnolia> <20170831131723.GD19544@infradead.org> <20170831133420.GB21939@bfoster.bfoster> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170831133420.GB21939@bfoster.bfoster> User-Agent: Mutt/1.8.3 (2017-05-23) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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 So maybe something like this (totally untested, will attempt for a QA run over the night): From d4da594cd1c42b88673b7eae5187827a3099ec42 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Thu, 31 Aug 2017 15:14:36 +0200 Subject: xfs: don't set v3 xflags for v2 inodes Reject attempts to set XFLAGS that correspond to di_flags2 inode flags if the inode isn't a v3 inode, because di_flags2 only exists on v3. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_ioctl.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 9c0c7a920304..84a80210b2e1 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -931,7 +931,7 @@ xfs_ioc_fsgetxattr( return 0; } -STATIC void +STATIC int xfs_set_diflags( struct xfs_inode *ip, unsigned int xflags) @@ -970,11 +970,6 @@ xfs_set_diflags( if (xflags & FS_XFLAG_EXTSIZE) di_flags |= XFS_DIFLAG_EXTSIZE; } - ip->i_d.di_flags = di_flags; - - /* diflags2 only valid for v3 inodes. */ - if (ip->i_d.di_version < 3) - return; di_flags2 = (ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK); if (xflags & FS_XFLAG_DAX) @@ -982,7 +977,13 @@ xfs_set_diflags( if (xflags & FS_XFLAG_COWEXTSIZE) di_flags2 |= XFS_DIFLAG2_COWEXTSIZE; + /* diflags2 only valid for v3 inodes. */ + if (di_flags2 && ip->i_d.di_version < 3) + return -EINVAL; + + ip->i_d.di_flags = di_flags; ip->i_d.di_flags2 = di_flags2; + return 0; } STATIC void @@ -1022,6 +1023,7 @@ xfs_ioctl_setattr_xflags( struct fsxattr *fa) { struct xfs_mount *mp = ip->i_mount; + int error; /* Can't change realtime flag if any extents are allocated. */ if ((ip->i_d.di_nextents || ip->i_delayed_blks) && @@ -1052,7 +1054,10 @@ xfs_ioctl_setattr_xflags( !capable(CAP_LINUX_IMMUTABLE)) return -EPERM; - xfs_set_diflags(ip, fa->fsx_xflags); + error = xfs_set_diflags(ip, fa->fsx_xflags); + if (error) + return error; + xfs_diflags_to_linux(ip); xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);