From patchwork Wed Nov 6 09:15:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 1190184 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LHKs29QV"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477LXY2kXHz9sPk for ; Wed, 6 Nov 2019 20:17:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AMm0bGNgPCfnMVJcHtiAyWhLd8jFO4kE8UmWj6Vlzbc=; b=LHKs29QVIX7BiC AT0BeCf45ZtJ4IRoXLjee+mTZEmc4rB+MM19p5FpyBv/M5XRwTIVmYAJeO8uT/MxDddSp1R5bJY0t hwymoWc5Ou16XYOJnBqWX4q6M3uXItSN37byQlDoKqIJ2Kr174aQnIJxkZCAHF/Wu3Cpt0h1VvpQb 4Hnix0h3blh21AsI//fuTcq93XkorlG0gAHaZo2PQWfaZ37zDyu5IwgRqPsFXeNEjzy7+P+PdcOHO ShMxz//vT6H40a3HlkL1qE5VzXPLeqDclV0KzO+uDyuExfv2+lU2farM5c0MChJNVmamgI6V4zFoz Vw7GHDrBxBJbiVKRdhwg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSHRF-0002WH-Pb; Wed, 06 Nov 2019 09:17:17 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSHQE-0001YF-0H for linux-mtd@lists.infradead.org; Wed, 06 Nov 2019 09:16:15 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iSHPg-0002eX-I3; Wed, 06 Nov 2019 10:15:40 +0100 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1iSHPe-0000Ar-I1; Wed, 06 Nov 2019 10:15:38 +0100 From: Sascha Hauer To: linux-fsdevel@vger.kernel.org Subject: [PATCH 2/7] ubifs: move checks and preparation into setflags() Date: Wed, 6 Nov 2019 10:15:32 +0100 Message-Id: <20191106091537.32480-3-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.24.0.rc1 In-Reply-To: <20191106091537.32480-1-s.hauer@pengutronix.de> References: <20191106091537.32480-1-s.hauer@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mtd@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191106_011614_080205_C1E3C129 X-CRM114-Status: GOOD ( 14.63 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , Sascha Hauer , linux-mtd@lists.infradead.org, kernel@pengutronix.de, Jan Kara Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org setflags() can be reused for upcoming FS_IOC_FS[SG]ETXATTR ioctl support. In preparation for that move the checks and preparation into that function so we can reuse them as well. Signed-off-by: Sascha Hauer Acked-by: Richard Weinberger --- fs/ubifs/ioctl.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/fs/ubifs/ioctl.c b/fs/ubifs/ioctl.c index 5dc5abca11c7..8230dba5fd74 100644 --- a/fs/ubifs/ioctl.c +++ b/fs/ubifs/ioctl.c @@ -95,18 +95,35 @@ static int ubifs2ioctl(int ubifs_flags) return ioctl_flags; } -static int setflags(struct inode *inode, int flags) +static int setflags(struct file *file, int flags) { int oldflags, err, release; + struct inode *inode = file_inode(file); struct ubifs_inode *ui = ubifs_inode(inode); struct ubifs_info *c = inode->i_sb->s_fs_info; struct ubifs_budget_req req = { .dirtied_ino = 1, .dirtied_ino_d = ui->data_len }; - err = ubifs_budget_space(c, &req); + if (IS_RDONLY(inode)) + return -EROFS; + + if (!inode_owner_or_capable(inode)) + return -EACCES; + + /* + * Make sure the file-system is read-write and make sure it + * will not become read-only while we are changing the flags. + */ + err = mnt_want_write_file(file); if (err) return err; + dbg_gen("set flags: %#x, i_flags %#x", flags, inode->i_flags); + + err = ubifs_budget_space(c, &req); + if (err) + goto out_drop; + mutex_lock(&ui->ui_mutex); oldflags = ubifs2ioctl(ui->flags); err = vfs_ioc_setflags_prepare(inode, oldflags, flags); @@ -124,12 +141,18 @@ static int setflags(struct inode *inode, int flags) ubifs_release_budget(c, &req); if (IS_SYNC(inode)) err = write_inode_now(inode, 1); + + mnt_drop_write_file(file); + return err; out_unlock: ubifs_err(c, "can't modify inode %lu attributes", inode->i_ino); mutex_unlock(&ui->ui_mutex); ubifs_release_budget(c, &req); +out_drop: + mnt_drop_write_file(file); + return err; } @@ -146,12 +169,6 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return put_user(flags, (int __user *) arg); case FS_IOC_SETFLAGS: { - if (IS_RDONLY(inode)) - return -EROFS; - - if (!inode_owner_or_capable(inode)) - return -EACCES; - if (get_user(flags, (int __user *) arg)) return -EFAULT; @@ -161,17 +178,8 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (!S_ISDIR(inode->i_mode)) flags &= ~FS_DIRSYNC_FL; - /* - * Make sure the file-system is read-write and make sure it - * will not become read-only while we are changing the flags. - */ - err = mnt_want_write_file(file); - if (err) - return err; - dbg_gen("set flags: %#x, i_flags %#x", flags, inode->i_flags); - err = setflags(inode, flags); - mnt_drop_write_file(file); - return err; + + return setflags(file, flags); } case FS_IOC_SET_ENCRYPTION_POLICY: { struct ubifs_info *c = inode->i_sb->s_fs_info;