hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/ubifs/ioctl.c
....@@ -1,21 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * This file is part of UBIFS.
34 *
45 * Copyright (C) 2006-2008 Nokia Corporation.
56 * Copyright (C) 2006, 2007 University of Szeged, Hungary
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License version 2 as published by
9
- * the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope that it will be useful, but WITHOUT
12
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
- * more details.
15
- *
16
- * You should have received a copy of the GNU General Public License along with
17
- * this program; if not, write to the Free Software Foundation, Inc., 51
18
- * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
197 *
208 * Authors: Zoltan Sogor
219 * Artem Bityutskiy (Битюцкий Артём)
....@@ -29,9 +17,13 @@
2917 #include "ubifs.h"
3018
3119 /* Need to be kept consistent with checked flags in ioctl2ubifs() */
32
-#define UBIFS_SUPPORTED_IOCTL_FLAGS \
20
+#define UBIFS_SETTABLE_IOCTL_FLAGS \
3321 (FS_COMPR_FL | FS_SYNC_FL | FS_APPEND_FL | \
3422 FS_IMMUTABLE_FL | FS_DIRSYNC_FL)
23
+
24
+/* Need to be kept consistent with checked flags in ubifs2ioctl() */
25
+#define UBIFS_GETTABLE_IOCTL_FLAGS \
26
+ (UBIFS_SETTABLE_IOCTL_FLAGS | FS_ENCRYPT_FL)
3527
3628 /**
3729 * ubifs_set_inode_flags - set VFS inode flags.
....@@ -103,6 +95,8 @@
10395 ioctl_flags |= FS_IMMUTABLE_FL;
10496 if (ubifs_flags & UBIFS_DIRSYNC_FL)
10597 ioctl_flags |= FS_DIRSYNC_FL;
98
+ if (ubifs_flags & UBIFS_CRYPT_FL)
99
+ ioctl_flags |= FS_ENCRYPT_FL;
106100
107101 return ioctl_flags;
108102 }
....@@ -113,26 +107,19 @@
113107 struct ubifs_inode *ui = ubifs_inode(inode);
114108 struct ubifs_info *c = inode->i_sb->s_fs_info;
115109 struct ubifs_budget_req req = { .dirtied_ino = 1,
116
- .dirtied_ino_d = ui->data_len };
110
+ .dirtied_ino_d = ALIGN(ui->data_len, 8) };
117111
118112 err = ubifs_budget_space(c, &req);
119113 if (err)
120114 return err;
121115
122
- /*
123
- * The IMMUTABLE and APPEND_ONLY flags can only be changed by
124
- * the relevant capability.
125
- */
126116 mutex_lock(&ui->ui_mutex);
127117 oldflags = ubifs2ioctl(ui->flags);
128
- if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
129
- if (!capable(CAP_LINUX_IMMUTABLE)) {
130
- err = -EPERM;
131
- goto out_unlock;
132
- }
133
- }
118
+ err = vfs_ioc_setflags_prepare(inode, oldflags, flags);
119
+ if (err)
120
+ goto out_unlock;
134121
135
- ui->flags &= ~ioctl2ubifs(UBIFS_SUPPORTED_IOCTL_FLAGS);
122
+ ui->flags &= ~ioctl2ubifs(UBIFS_SETTABLE_IOCTL_FLAGS);
136123 ui->flags |= ioctl2ubifs(flags);
137124 ubifs_set_inode_flags(inode);
138125 inode->i_ctime = current_time(inode);
....@@ -147,7 +134,6 @@
147134 return err;
148135
149136 out_unlock:
150
- ubifs_err(c, "can't modify inode %lu attributes", inode->i_ino);
151137 mutex_unlock(&ui->ui_mutex);
152138 ubifs_release_budget(c, &req);
153139 return err;
....@@ -175,8 +161,9 @@
175161 if (get_user(flags, (int __user *) arg))
176162 return -EFAULT;
177163
178
- if (flags & ~UBIFS_SUPPORTED_IOCTL_FLAGS)
164
+ if (flags & ~UBIFS_GETTABLE_IOCTL_FLAGS)
179165 return -EOPNOTSUPP;
166
+ flags &= UBIFS_SETTABLE_IOCTL_FLAGS;
180167
181168 if (!S_ISDIR(inode->i_mode))
182169 flags &= ~FS_DIRSYNC_FL;
....@@ -194,7 +181,6 @@
194181 return err;
195182 }
196183 case FS_IOC_SET_ENCRYPTION_POLICY: {
197
-#ifdef CONFIG_FS_ENCRYPTION
198184 struct ubifs_info *c = inode->i_sb->s_fs_info;
199185
200186 err = ubifs_enable_encryption(c);
....@@ -202,17 +188,9 @@
202188 return err;
203189
204190 return fscrypt_ioctl_set_policy(file, (const void __user *)arg);
205
-#else
206
- return -EOPNOTSUPP;
207
-#endif
208191 }
209
- case FS_IOC_GET_ENCRYPTION_POLICY: {
210
-#ifdef CONFIG_FS_ENCRYPTION
192
+ case FS_IOC_GET_ENCRYPTION_POLICY:
211193 return fscrypt_ioctl_get_policy(file, (void __user *)arg);
212
-#else
213
- return -EOPNOTSUPP;
214
-#endif
215
- }
216194
217195 case FS_IOC_GET_ENCRYPTION_POLICY_EX:
218196 return fscrypt_ioctl_get_policy_ex(file, (void __user *)arg);