Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp250461pxb; Wed, 3 Feb 2021 04:49:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5TcfULuyO4l6U4hrkIw0qB4C8P1d6iH8KhjDMwqhFgCI0x5f5L/c1zgX+uFfCGXEl1qAf X-Received: by 2002:aa7:d696:: with SMTP id d22mr2683781edr.361.1612356570934; Wed, 03 Feb 2021 04:49:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612356570; cv=none; d=google.com; s=arc-20160816; b=Y1GaLJIxP1GYdXc8n9bXju0PEkC1wtbjwvPGn8JckWSnqAxIra0Kbqklds4Xb2iDjo hLtgYa4QGqS4PaOoo/iRdZO0MexpxFCJHy+fOUm0KgFk/AuDpLF6adVd8ID1HYeQ9fsx pc1Z2LQfFeLOay/OmGYIe9UEiMEDeWt15DdBxOy+evb0u3en3Rp9PCkuJp+9Ywh0YupM sM4lBqf0Qh3wp1wyxuzBvDnDq7bUeEd1oPYbEVzcTqesdyxPSuI0UCCe3rjoCj1RrqDj PWbzQ+JTaLQEFJ++BVcKonBC9jE0ZVkYSHZdReCjzhj2/wT1hqBUuagarYBglXqrPqkI raOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lO3+6IJT04iMcewcGdHLjCrHBvAdLlNE5bp9CQJEzSM=; b=I3WD9xnSpFYZKdCBQE3+F4SWJZ67NyHlS5kB7Qjm4aAFpzkZmspWdncsYJIXSWDI/F Jv190HhlmLGkk6DAcBnex6XLbGm0ZG8e9a+35sS0BX+vTc0Ev1wQ60etyocD2z6kNAQw zEpF2Ov0emUTU6733u7ZiKtxpP0fT4ryddv2WKWjUzZuyYgF5k/ygzEjomAYWK/UcujB KibA8lmVFF+UaQvoShVrJ/Xo6kJ7iQyh54QPeJmxeYlJ71IELvTT3zOnEXAF5Ht2EfmN b7M7jeCk3aNaSQdWYHdO276xcnMSkbZG6PPYNe58vFaFCmrVQLk88JZ6ICdm3yWIK7wW jUFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e5S0OHVY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r8si1174559ejc.517.2021.02.03.04.49.05; Wed, 03 Feb 2021 04:49:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e5S0OHVY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbhBCMsI (ORCPT + 99 others); Wed, 3 Feb 2021 07:48:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40718 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbhBCMnX (ORCPT ); Wed, 3 Feb 2021 07:43:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612356116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lO3+6IJT04iMcewcGdHLjCrHBvAdLlNE5bp9CQJEzSM=; b=e5S0OHVYNGX5aycIr9snbMyZuWzJH3BO2xBgeXBkAWDHX38wrzLrgp26CvEp/x7oCC7+nh nlTjlQc3v5cPWqNZSa5eS0RG5RHyDXhzGrMbgoYR32r62Y3UR9RxHMCKPAmG+FIw24W1gR 9PCu0flIDDSYC1UqjJ9xC80ot0O6fH8= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-526-aotxAZPcNSGERBJ8JZry2A-1; Wed, 03 Feb 2021 07:41:55 -0500 X-MC-Unique: aotxAZPcNSGERBJ8JZry2A-1 Received: by mail-ed1-f71.google.com with SMTP id x13so11443961edi.7 for ; Wed, 03 Feb 2021 04:41:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lO3+6IJT04iMcewcGdHLjCrHBvAdLlNE5bp9CQJEzSM=; b=cbODo8jXmXu4CfwwhtO35+ygQ/aDyntLg3tPeJMF2nZpScXu3D+QpQ0uNk036p2KdG 8jJr9ml25C49k3XqHC2x5gyu+pbkKrSnHExj0wfqh0eYUyAiDDEtvOyXozHUt+kKf/MS YH+Yizjw282mI96H88BR2PUoXB1Av0GKd3z4ikOyqkrBVLtbwUff/Fxx72pIDRUYa/+L MGdGtsM+kGOElwkkThZfHRxTc/ajLFRGUaDYiT7uxg8RcQFVyBU77/fKq7N7BTzp+KCK cFjNInFcMriRAUuPH9sK8TX56ERbGIOaY6Wvi1c64QKWKc/EExlLqz/g1DMMP/66sANd lhaA== X-Gm-Message-State: AOAM533X/eZn/3tDH+gqBTrpzXd/g/yzMg5Eoa0d5lucjiWsD8ODMmPT zoY0r5ElQk6b0ibm9JTtR4UMGePKuQ3crZ/15fbrfCKxwWpLtuawPuzbudmRHnqnlK7WF4+04w6 FgWMKxGKQ6UgD92eGGU8AUk8/ X-Received: by 2002:a17:906:39d0:: with SMTP id i16mr3005972eje.18.1612356113917; Wed, 03 Feb 2021 04:41:53 -0800 (PST) X-Received: by 2002:a17:906:39d0:: with SMTP id i16mr3005958eje.18.1612356113726; Wed, 03 Feb 2021 04:41:53 -0800 (PST) Received: from miu.piliscsaba.redhat.com (catv-86-101-169-67.catv.broadband.hu. [86.101.169.67]) by smtp.gmail.com with ESMTPSA id u9sm953320ejc.57.2021.02.03.04.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 04:41:52 -0800 (PST) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Richard Weinberger Subject: [PATCH 17/18] ubifs: convert to miscattr Date: Wed, 3 Feb 2021 13:41:11 +0100 Message-Id: <20210203124112.1182614-18-mszeredi@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210203124112.1182614-1-mszeredi@redhat.com> References: <20210203124112.1182614-1-mszeredi@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the miscattr API to let the VFS handle locking, permission checking and conversion. Signed-off-by: Miklos Szeredi Cc: Richard Weinberger --- fs/ubifs/dir.c | 2 ++ fs/ubifs/file.c | 2 ++ fs/ubifs/ioctl.c | 73 ++++++++++++++++++++---------------------------- fs/ubifs/ubifs.h | 2 ++ 4 files changed, 36 insertions(+), 43 deletions(-) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 9a6b8660425a..0e25e4c352eb 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -1635,6 +1635,8 @@ const struct inode_operations ubifs_dir_inode_operations = { .listxattr = ubifs_listxattr, .update_time = ubifs_update_time, .tmpfile = ubifs_tmpfile, + .miscattr_get = ubifs_miscattr_get, + .miscattr_set = ubifs_miscattr_set, }; const struct file_operations ubifs_dir_operations = { diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 2bc7780d2963..3761bdc801bd 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -1647,6 +1647,8 @@ const struct inode_operations ubifs_file_inode_operations = { .getattr = ubifs_getattr, .listxattr = ubifs_listxattr, .update_time = ubifs_update_time, + .miscattr_get = ubifs_miscattr_get, + .miscattr_set = ubifs_miscattr_set, }; const struct inode_operations ubifs_symlink_inode_operations = { diff --git a/fs/ubifs/ioctl.c b/fs/ubifs/ioctl.c index 4363d85a3fd4..901530c56259 100644 --- a/fs/ubifs/ioctl.c +++ b/fs/ubifs/ioctl.c @@ -14,6 +14,7 @@ #include #include +#include #include "ubifs.h" /* Need to be kept consistent with checked flags in ioctl2ubifs() */ @@ -103,7 +104,7 @@ static int ubifs2ioctl(int ubifs_flags) static int setflags(struct inode *inode, int flags) { - int oldflags, err, release; + int err, release; 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, @@ -114,11 +115,6 @@ static int setflags(struct inode *inode, int flags) return err; mutex_lock(&ui->ui_mutex); - oldflags = ubifs2ioctl(ui->flags); - err = vfs_ioc_setflags_prepare(inode, oldflags, flags); - if (err) - goto out_unlock; - ui->flags &= ~ioctl2ubifs(UBIFS_SETTABLE_IOCTL_FLAGS); ui->flags |= ioctl2ubifs(flags); ubifs_set_inode_flags(inode); @@ -132,54 +128,45 @@ static int setflags(struct inode *inode, int flags) if (IS_SYNC(inode)) err = write_inode_now(inode, 1); return err; - -out_unlock: - mutex_unlock(&ui->ui_mutex); - ubifs_release_budget(c, &req); - return err; } -long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +int ubifs_miscattr_get(struct dentry *dentry, struct miscattr *ma) { - int flags, err; - struct inode *inode = file_inode(file); + struct inode *inode = d_inode(dentry); + int flags = ubifs2ioctl(ubifs_inode(inode)->flags); - switch (cmd) { - case FS_IOC_GETFLAGS: - flags = ubifs2ioctl(ubifs_inode(inode)->flags); + dbg_gen("get flags: %#x, i_flags %#x", flags, inode->i_flags); + miscattr_fill_flags(ma, flags); - dbg_gen("get flags: %#x, i_flags %#x", flags, inode->i_flags); - return put_user(flags, (int __user *) arg); + return 0; +} - case FS_IOC_SETFLAGS: { - if (IS_RDONLY(inode)) - return -EROFS; +int ubifs_miscattr_set(struct dentry *dentry, struct miscattr *ma) +{ + struct inode *inode = d_inode(dentry); + int flags = ma->flags; - if (!inode_owner_or_capable(inode)) - return -EACCES; + if (miscattr_has_xattr(ma)) + return -EOPNOTSUPP; - if (get_user(flags, (int __user *) arg)) - return -EFAULT; + if (flags & ~UBIFS_GETTABLE_IOCTL_FLAGS) + return -EOPNOTSUPP; - if (flags & ~UBIFS_GETTABLE_IOCTL_FLAGS) - return -EOPNOTSUPP; - flags &= UBIFS_SETTABLE_IOCTL_FLAGS; + flags &= UBIFS_SETTABLE_IOCTL_FLAGS; - if (!S_ISDIR(inode->i_mode)) - flags &= ~FS_DIRSYNC_FL; + 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; - } + dbg_gen("set flags: %#x, i_flags %#x", flags, inode->i_flags); + return setflags(inode, flags); +} + +long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + int err; + struct inode *inode = file_inode(file); + + switch (cmd) { case FS_IOC_SET_ENCRYPTION_POLICY: { struct ubifs_info *c = inode->i_sb->s_fs_info; diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index fc2cdde3b549..404ec58254e9 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -2052,6 +2052,8 @@ int ubifs_recover_size(struct ubifs_info *c, bool in_place); void ubifs_destroy_size_tree(struct ubifs_info *c); /* ioctl.c */ +int ubifs_miscattr_get(struct dentry *dentry, struct miscattr *ma); +int ubifs_miscattr_set(struct dentry *dentry, struct miscattr *ma); long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); void ubifs_set_inode_flags(struct inode *inode); #ifdef CONFIG_COMPAT -- 2.26.2