.. | .. |
---|
4 | 4 | */ |
---|
5 | 5 | |
---|
6 | 6 | #include <linux/blkdev.h> |
---|
7 | | -#include <linux/cred.h> |
---|
8 | | -#include <linux/eventpoll.h> |
---|
| 7 | +#include <linux/compat.h> |
---|
9 | 8 | #include <linux/file.h> |
---|
10 | 9 | #include <linux/fs.h> |
---|
11 | 10 | #include <linux/fs_stack.h> |
---|
| 11 | +#include <linux/fsnotify.h> |
---|
| 12 | +#include <linux/fsverity.h> |
---|
| 13 | +#include <linux/mmap_lock.h> |
---|
12 | 14 | #include <linux/namei.h> |
---|
13 | 15 | #include <linux/parser.h> |
---|
14 | | -#include <linux/poll.h> |
---|
15 | 16 | #include <linux/seq_file.h> |
---|
16 | | -#include <linux/syscalls.h> |
---|
17 | | -#include <linux/xattr.h> |
---|
18 | 17 | |
---|
19 | 18 | #include <uapi/linux/incrementalfs.h> |
---|
20 | 19 | |
---|
21 | 20 | #include "vfs.h" |
---|
| 21 | + |
---|
22 | 22 | #include "data_mgmt.h" |
---|
23 | 23 | #include "format.h" |
---|
24 | | -#include "integrity.h" |
---|
25 | 24 | #include "internal.h" |
---|
26 | | - |
---|
27 | | -#define INCFS_PENDING_READS_INODE 2 |
---|
28 | | -#define INCFS_LOG_INODE 3 |
---|
29 | | -#define INCFS_START_INO_RANGE 10 |
---|
30 | | -#define READ_FILE_MODE 0444 |
---|
31 | | -#define READ_EXEC_FILE_MODE 0555 |
---|
32 | | -#define READ_WRITE_FILE_MODE 0666 |
---|
| 25 | +#include "pseudo_files.h" |
---|
| 26 | +#include "sysfs.h" |
---|
| 27 | +#include "verity.h" |
---|
33 | 28 | |
---|
34 | 29 | static int incfs_remount_fs(struct super_block *sb, int *flags, char *data); |
---|
35 | 30 | |
---|
.. | .. |
---|
52 | 47 | static int read_single_page(struct file *f, struct page *page); |
---|
53 | 48 | static long dispatch_ioctl(struct file *f, unsigned int req, unsigned long arg); |
---|
54 | 49 | |
---|
55 | | -static ssize_t pending_reads_read(struct file *f, char __user *buf, size_t len, |
---|
56 | | - loff_t *ppos); |
---|
57 | | -static __poll_t pending_reads_poll(struct file *file, poll_table *wait); |
---|
58 | | -static int pending_reads_open(struct inode *inode, struct file *file); |
---|
59 | | -static int pending_reads_release(struct inode *, struct file *); |
---|
60 | | - |
---|
61 | | -static ssize_t log_read(struct file *f, char __user *buf, size_t len, |
---|
62 | | - loff_t *ppos); |
---|
63 | | -static __poll_t log_poll(struct file *file, poll_table *wait); |
---|
64 | | -static int log_open(struct inode *inode, struct file *file); |
---|
65 | | -static int log_release(struct inode *, struct file *); |
---|
| 50 | +#ifdef CONFIG_COMPAT |
---|
| 51 | +static long incfs_compat_ioctl(struct file *file, unsigned int cmd, |
---|
| 52 | + unsigned long arg); |
---|
| 53 | +#endif |
---|
66 | 54 | |
---|
67 | 55 | static struct inode *alloc_inode(struct super_block *sb); |
---|
68 | 56 | static void free_inode(struct inode *inode); |
---|
69 | 57 | static void evict_inode(struct inode *inode); |
---|
70 | 58 | |
---|
71 | 59 | static int incfs_setattr(struct dentry *dentry, struct iattr *ia); |
---|
| 60 | +static int incfs_getattr(const struct path *path, |
---|
| 61 | + struct kstat *stat, u32 request_mask, |
---|
| 62 | + unsigned int query_flags); |
---|
72 | 63 | static ssize_t incfs_getxattr(struct dentry *d, const char *name, |
---|
73 | 64 | void *value, size_t size); |
---|
74 | 65 | static ssize_t incfs_setxattr(struct dentry *d, const char *name, |
---|
.. | .. |
---|
109 | 100 | .iterate = iterate_incfs_dir, |
---|
110 | 101 | .open = file_open, |
---|
111 | 102 | .release = file_release, |
---|
112 | | - .unlocked_ioctl = dispatch_ioctl, |
---|
113 | | - .compat_ioctl = dispatch_ioctl |
---|
114 | 103 | }; |
---|
115 | 104 | |
---|
116 | 105 | static const struct dentry_operations incfs_dentry_ops = { |
---|
.. | .. |
---|
123 | 112 | /* .readpages = readpages */ |
---|
124 | 113 | }; |
---|
125 | 114 | |
---|
126 | | -static const struct file_operations incfs_file_ops = { |
---|
| 115 | +static vm_fault_t incfs_fault(struct vm_fault *vmf) |
---|
| 116 | +{ |
---|
| 117 | + vmf->flags &= ~FAULT_FLAG_ALLOW_RETRY; |
---|
| 118 | + return filemap_fault(vmf); |
---|
| 119 | +} |
---|
| 120 | + |
---|
| 121 | +static const struct vm_operations_struct incfs_file_vm_ops = { |
---|
| 122 | + .fault = incfs_fault, |
---|
| 123 | + .map_pages = filemap_map_pages, |
---|
| 124 | + .page_mkwrite = filemap_page_mkwrite, |
---|
| 125 | +}; |
---|
| 126 | + |
---|
| 127 | +/* This is used for a general mmap of a disk file */ |
---|
| 128 | + |
---|
| 129 | +static int incfs_file_mmap(struct file *file, struct vm_area_struct *vma) |
---|
| 130 | +{ |
---|
| 131 | + struct address_space *mapping = file->f_mapping; |
---|
| 132 | + |
---|
| 133 | + if (!mapping->a_ops->readpage) |
---|
| 134 | + return -ENOEXEC; |
---|
| 135 | + file_accessed(file); |
---|
| 136 | + vma->vm_ops = &incfs_file_vm_ops; |
---|
| 137 | + return 0; |
---|
| 138 | +} |
---|
| 139 | + |
---|
| 140 | +const struct file_operations incfs_file_ops = { |
---|
127 | 141 | .open = file_open, |
---|
128 | 142 | .release = file_release, |
---|
129 | 143 | .read_iter = generic_file_read_iter, |
---|
130 | | - .mmap = generic_file_mmap, |
---|
| 144 | + .mmap = incfs_file_mmap, |
---|
131 | 145 | .splice_read = generic_file_splice_read, |
---|
132 | 146 | .llseek = generic_file_llseek, |
---|
133 | 147 | .unlocked_ioctl = dispatch_ioctl, |
---|
134 | | - .compat_ioctl = dispatch_ioctl |
---|
| 148 | +#ifdef CONFIG_COMPAT |
---|
| 149 | + .compat_ioctl = incfs_compat_ioctl, |
---|
| 150 | +#endif |
---|
135 | 151 | }; |
---|
136 | 152 | |
---|
137 | | -enum FILL_PERMISSION { |
---|
138 | | - CANT_FILL = 0, |
---|
139 | | - CAN_FILL = 1, |
---|
140 | | -}; |
---|
141 | | - |
---|
142 | | -static const struct file_operations incfs_pending_read_file_ops = { |
---|
143 | | - .read = pending_reads_read, |
---|
144 | | - .poll = pending_reads_poll, |
---|
145 | | - .open = pending_reads_open, |
---|
146 | | - .release = pending_reads_release, |
---|
147 | | - .llseek = noop_llseek, |
---|
148 | | - .unlocked_ioctl = dispatch_ioctl, |
---|
149 | | - .compat_ioctl = dispatch_ioctl |
---|
150 | | -}; |
---|
151 | | - |
---|
152 | | -static const struct file_operations incfs_log_file_ops = { |
---|
153 | | - .read = log_read, |
---|
154 | | - .poll = log_poll, |
---|
155 | | - .open = log_open, |
---|
156 | | - .release = log_release, |
---|
157 | | - .llseek = noop_llseek, |
---|
158 | | - .unlocked_ioctl = dispatch_ioctl, |
---|
159 | | - .compat_ioctl = dispatch_ioctl |
---|
160 | | -}; |
---|
161 | | - |
---|
162 | | -static const struct inode_operations incfs_file_inode_ops = { |
---|
| 153 | +const struct inode_operations incfs_file_inode_ops = { |
---|
163 | 154 | .setattr = incfs_setattr, |
---|
164 | | - .getattr = simple_getattr, |
---|
| 155 | + .getattr = incfs_getattr, |
---|
165 | 156 | .listxattr = incfs_listxattr |
---|
166 | 157 | }; |
---|
167 | 158 | |
---|
168 | 159 | static int incfs_handler_getxattr(const struct xattr_handler *xh, |
---|
169 | 160 | struct dentry *d, struct inode *inode, |
---|
170 | | - const char *name, void *buffer, size_t size) |
---|
| 161 | + const char *name, void *buffer, size_t size, |
---|
| 162 | + int flags) |
---|
171 | 163 | { |
---|
172 | 164 | return incfs_getxattr(d, name, buffer, size); |
---|
173 | 165 | } |
---|
.. | .. |
---|
191 | 183 | NULL, |
---|
192 | 184 | }; |
---|
193 | 185 | |
---|
194 | | -/* State of an open .pending_reads file, unique for each file descriptor. */ |
---|
195 | | -struct pending_reads_state { |
---|
196 | | - /* A serial number of the last pending read obtained from this file. */ |
---|
197 | | - int last_pending_read_sn; |
---|
198 | | -}; |
---|
199 | | - |
---|
200 | | -/* State of an open .log file, unique for each file descriptor. */ |
---|
201 | | -struct log_file_state { |
---|
202 | | - struct read_log_state state; |
---|
203 | | -}; |
---|
204 | | - |
---|
205 | 186 | struct inode_search { |
---|
206 | 187 | unsigned long ino; |
---|
207 | 188 | |
---|
208 | 189 | struct dentry *backing_dentry; |
---|
209 | 190 | |
---|
210 | 191 | size_t size; |
---|
| 192 | + |
---|
| 193 | + bool verity; |
---|
211 | 194 | }; |
---|
212 | 195 | |
---|
213 | 196 | enum parse_parameter { |
---|
214 | 197 | Opt_read_timeout, |
---|
215 | 198 | Opt_readahead_pages, |
---|
216 | | - Opt_no_backing_file_cache, |
---|
217 | | - Opt_no_backing_file_readahead, |
---|
218 | 199 | Opt_rlog_pages, |
---|
219 | 200 | Opt_rlog_wakeup_cnt, |
---|
| 201 | + Opt_report_uid, |
---|
| 202 | + Opt_sysfs_name, |
---|
220 | 203 | Opt_err |
---|
221 | | -}; |
---|
222 | | - |
---|
223 | | -static const char pending_reads_file_name[] = INCFS_PENDING_READS_FILENAME; |
---|
224 | | -static struct mem_range pending_reads_file_name_range = { |
---|
225 | | - .data = (u8 *)pending_reads_file_name, |
---|
226 | | - .len = ARRAY_SIZE(pending_reads_file_name) - 1 |
---|
227 | | -}; |
---|
228 | | - |
---|
229 | | -static const char log_file_name[] = INCFS_LOG_FILENAME; |
---|
230 | | -static struct mem_range log_file_name_range = { |
---|
231 | | - .data = (u8 *)log_file_name, |
---|
232 | | - .len = ARRAY_SIZE(log_file_name) - 1 |
---|
233 | 204 | }; |
---|
234 | 205 | |
---|
235 | 206 | static const match_table_t option_tokens = { |
---|
236 | 207 | { Opt_read_timeout, "read_timeout_ms=%u" }, |
---|
237 | 208 | { Opt_readahead_pages, "readahead=%u" }, |
---|
238 | | - { Opt_no_backing_file_cache, "no_bf_cache=%u" }, |
---|
239 | | - { Opt_no_backing_file_readahead, "no_bf_readahead=%u" }, |
---|
240 | 209 | { Opt_rlog_pages, "rlog_pages=%u" }, |
---|
241 | 210 | { Opt_rlog_wakeup_cnt, "rlog_wakeup_cnt=%u" }, |
---|
| 211 | + { Opt_report_uid, "report_uid" }, |
---|
| 212 | + { Opt_sysfs_name, "sysfs_name=%s" }, |
---|
242 | 213 | { Opt_err, NULL } |
---|
243 | 214 | }; |
---|
| 215 | + |
---|
| 216 | +static void free_options(struct mount_options *opts) |
---|
| 217 | +{ |
---|
| 218 | + kfree(opts->sysfs_name); |
---|
| 219 | + opts->sysfs_name = NULL; |
---|
| 220 | +} |
---|
244 | 221 | |
---|
245 | 222 | static int parse_options(struct mount_options *opts, char *str) |
---|
246 | 223 | { |
---|
.. | .. |
---|
251 | 228 | if (opts == NULL) |
---|
252 | 229 | return -EFAULT; |
---|
253 | 230 | |
---|
254 | | - opts->read_timeout_ms = 1000; /* Default: 1s */ |
---|
255 | | - opts->readahead_pages = 10; |
---|
256 | | - opts->read_log_pages = 2; |
---|
257 | | - opts->read_log_wakeup_count = 10; |
---|
258 | | - opts->no_backing_file_cache = false; |
---|
259 | | - opts->no_backing_file_readahead = false; |
---|
| 231 | + *opts = (struct mount_options) { |
---|
| 232 | + .read_timeout_ms = 1000, /* Default: 1s */ |
---|
| 233 | + .readahead_pages = 10, |
---|
| 234 | + .read_log_pages = 2, |
---|
| 235 | + .read_log_wakeup_count = 10, |
---|
| 236 | + }; |
---|
| 237 | + |
---|
260 | 238 | if (str == NULL || *str == 0) |
---|
261 | 239 | return 0; |
---|
262 | 240 | |
---|
.. | .. |
---|
272 | 250 | case Opt_read_timeout: |
---|
273 | 251 | if (match_int(&args[0], &value)) |
---|
274 | 252 | return -EINVAL; |
---|
| 253 | + if (value > 3600000) |
---|
| 254 | + return -EINVAL; |
---|
275 | 255 | opts->read_timeout_ms = value; |
---|
276 | 256 | break; |
---|
277 | 257 | case Opt_readahead_pages: |
---|
278 | 258 | if (match_int(&args[0], &value)) |
---|
279 | 259 | return -EINVAL; |
---|
280 | 260 | opts->readahead_pages = value; |
---|
281 | | - break; |
---|
282 | | - case Opt_no_backing_file_cache: |
---|
283 | | - if (match_int(&args[0], &value)) |
---|
284 | | - return -EINVAL; |
---|
285 | | - opts->no_backing_file_cache = (value != 0); |
---|
286 | | - break; |
---|
287 | | - case Opt_no_backing_file_readahead: |
---|
288 | | - if (match_int(&args[0], &value)) |
---|
289 | | - return -EINVAL; |
---|
290 | | - opts->no_backing_file_readahead = (value != 0); |
---|
291 | 261 | break; |
---|
292 | 262 | case Opt_rlog_pages: |
---|
293 | 263 | if (match_int(&args[0], &value)) |
---|
.. | .. |
---|
299 | 269 | return -EINVAL; |
---|
300 | 270 | opts->read_log_wakeup_count = value; |
---|
301 | 271 | break; |
---|
| 272 | + case Opt_report_uid: |
---|
| 273 | + opts->report_uid = true; |
---|
| 274 | + break; |
---|
| 275 | + case Opt_sysfs_name: |
---|
| 276 | + opts->sysfs_name = match_strdup(&args[0]); |
---|
| 277 | + break; |
---|
302 | 278 | default: |
---|
| 279 | + free_options(opts); |
---|
303 | 280 | return -EINVAL; |
---|
304 | 281 | } |
---|
305 | 282 | } |
---|
306 | 283 | |
---|
307 | 284 | return 0; |
---|
308 | | -} |
---|
309 | | - |
---|
310 | | -static struct super_block *file_superblock(struct file *f) |
---|
311 | | -{ |
---|
312 | | - struct inode *inode = file_inode(f); |
---|
313 | | - |
---|
314 | | - return inode->i_sb; |
---|
315 | | -} |
---|
316 | | - |
---|
317 | | -static struct mount_info *get_mount_info(struct super_block *sb) |
---|
318 | | -{ |
---|
319 | | - struct mount_info *result = sb->s_fs_info; |
---|
320 | | - |
---|
321 | | - return result; |
---|
322 | 285 | } |
---|
323 | 286 | |
---|
324 | 287 | /* Read file size from the attribute. Quicker than reading the header */ |
---|
.. | .. |
---|
336 | 299 | return le64_to_cpu(attr_value); |
---|
337 | 300 | } |
---|
338 | 301 | |
---|
| 302 | +/* Read verity flag from the attribute. Quicker than reading the header */ |
---|
| 303 | +static bool read_verity_attr(struct dentry *backing_dentry) |
---|
| 304 | +{ |
---|
| 305 | + return vfs_getxattr(backing_dentry, INCFS_XATTR_VERITY_NAME, NULL, 0) |
---|
| 306 | + >= 0; |
---|
| 307 | +} |
---|
| 308 | + |
---|
339 | 309 | static int inode_test(struct inode *inode, void *opaque) |
---|
340 | 310 | { |
---|
341 | 311 | struct inode_search *search = opaque; |
---|
342 | 312 | struct inode_info *node = get_incfs_node(inode); |
---|
| 313 | + struct inode *backing_inode = d_inode(search->backing_dentry); |
---|
343 | 314 | |
---|
344 | 315 | if (!node) |
---|
345 | 316 | return 0; |
---|
346 | 317 | |
---|
347 | | - if (search->backing_dentry) { |
---|
348 | | - struct inode *backing_inode = d_inode(search->backing_dentry); |
---|
349 | | - |
---|
350 | | - return (node->n_backing_inode == backing_inode) && |
---|
351 | | - inode->i_ino == search->ino; |
---|
352 | | - } else |
---|
353 | | - return inode->i_ino == search->ino; |
---|
| 318 | + return node->n_backing_inode == backing_inode && |
---|
| 319 | + inode->i_ino == search->ino; |
---|
354 | 320 | } |
---|
355 | 321 | |
---|
356 | 322 | static int inode_set(struct inode *inode, void *opaque) |
---|
357 | 323 | { |
---|
358 | 324 | struct inode_search *search = opaque; |
---|
359 | 325 | struct inode_info *node = get_incfs_node(inode); |
---|
| 326 | + struct dentry *backing_dentry = search->backing_dentry; |
---|
| 327 | + struct inode *backing_inode = d_inode(backing_dentry); |
---|
360 | 328 | |
---|
361 | | - if (search->backing_dentry) { |
---|
362 | | - /* It's a regular inode that has corresponding backing inode */ |
---|
363 | | - struct dentry *backing_dentry = search->backing_dentry; |
---|
364 | | - struct inode *backing_inode = d_inode(backing_dentry); |
---|
| 329 | + fsstack_copy_attr_all(inode, backing_inode); |
---|
| 330 | + if (S_ISREG(inode->i_mode)) { |
---|
| 331 | + u64 size = search->size; |
---|
365 | 332 | |
---|
366 | | - fsstack_copy_attr_all(inode, backing_inode); |
---|
367 | | - if (S_ISREG(inode->i_mode)) { |
---|
368 | | - u64 size = search->size; |
---|
369 | | - |
---|
370 | | - inode->i_size = size; |
---|
371 | | - inode->i_blocks = get_blocks_count_for_size(size); |
---|
372 | | - inode->i_mapping->a_ops = &incfs_address_space_ops; |
---|
373 | | - inode->i_op = &incfs_file_inode_ops; |
---|
374 | | - inode->i_fop = &incfs_file_ops; |
---|
375 | | - inode->i_mode &= ~0222; |
---|
376 | | - } else if (S_ISDIR(inode->i_mode)) { |
---|
377 | | - inode->i_size = 0; |
---|
378 | | - inode->i_blocks = 1; |
---|
379 | | - inode->i_mapping->a_ops = &incfs_address_space_ops; |
---|
380 | | - inode->i_op = &incfs_dir_inode_ops; |
---|
381 | | - inode->i_fop = &incfs_dir_fops; |
---|
382 | | - } else { |
---|
383 | | - pr_warn_once("incfs: Unexpected inode type\n"); |
---|
384 | | - return -EBADF; |
---|
385 | | - } |
---|
386 | | - |
---|
387 | | - ihold(backing_inode); |
---|
388 | | - node->n_backing_inode = backing_inode; |
---|
389 | | - node->n_mount_info = get_mount_info(inode->i_sb); |
---|
390 | | - inode->i_ctime = backing_inode->i_ctime; |
---|
391 | | - inode->i_mtime = backing_inode->i_mtime; |
---|
392 | | - inode->i_atime = backing_inode->i_atime; |
---|
393 | | - inode->i_ino = backing_inode->i_ino; |
---|
394 | | - if (backing_inode->i_ino < INCFS_START_INO_RANGE) { |
---|
395 | | - pr_warn("incfs: ino conflict with backing FS %ld\n", |
---|
396 | | - backing_inode->i_ino); |
---|
397 | | - } |
---|
398 | | - |
---|
399 | | - return 0; |
---|
400 | | - } else if (search->ino == INCFS_PENDING_READS_INODE) { |
---|
401 | | - /* It's an inode for .pending_reads pseudo file. */ |
---|
402 | | - |
---|
403 | | - inode->i_ctime = (struct timespec64){}; |
---|
404 | | - inode->i_mtime = inode->i_ctime; |
---|
405 | | - inode->i_atime = inode->i_ctime; |
---|
406 | | - inode->i_size = 0; |
---|
407 | | - inode->i_ino = INCFS_PENDING_READS_INODE; |
---|
408 | | - inode->i_private = NULL; |
---|
409 | | - |
---|
410 | | - inode_init_owner(inode, NULL, S_IFREG | READ_WRITE_FILE_MODE); |
---|
411 | | - |
---|
| 333 | + inode->i_size = size; |
---|
| 334 | + inode->i_blocks = get_blocks_count_for_size(size); |
---|
| 335 | + inode->i_mapping->a_ops = &incfs_address_space_ops; |
---|
412 | 336 | inode->i_op = &incfs_file_inode_ops; |
---|
413 | | - inode->i_fop = &incfs_pending_read_file_ops; |
---|
414 | | - |
---|
415 | | - } else if (search->ino == INCFS_LOG_INODE) { |
---|
416 | | - /* It's an inode for .log pseudo file. */ |
---|
417 | | - |
---|
418 | | - inode->i_ctime = (struct timespec64){}; |
---|
419 | | - inode->i_mtime = inode->i_ctime; |
---|
420 | | - inode->i_atime = inode->i_ctime; |
---|
| 337 | + inode->i_fop = &incfs_file_ops; |
---|
| 338 | + inode->i_mode &= ~0222; |
---|
| 339 | + if (search->verity) |
---|
| 340 | + inode_set_flags(inode, S_VERITY, S_VERITY); |
---|
| 341 | + } else if (S_ISDIR(inode->i_mode)) { |
---|
421 | 342 | inode->i_size = 0; |
---|
422 | | - inode->i_ino = INCFS_LOG_INODE; |
---|
423 | | - inode->i_private = NULL; |
---|
424 | | - |
---|
425 | | - inode_init_owner(inode, NULL, S_IFREG | READ_WRITE_FILE_MODE); |
---|
426 | | - |
---|
427 | | - inode->i_op = &incfs_file_inode_ops; |
---|
428 | | - inode->i_fop = &incfs_log_file_ops; |
---|
429 | | - |
---|
| 343 | + inode->i_blocks = 1; |
---|
| 344 | + inode->i_mapping->a_ops = &incfs_address_space_ops; |
---|
| 345 | + inode->i_op = &incfs_dir_inode_ops; |
---|
| 346 | + inode->i_fop = &incfs_dir_fops; |
---|
430 | 347 | } else { |
---|
431 | | - /* Unknown inode requested. */ |
---|
432 | | - return -EINVAL; |
---|
| 348 | + pr_warn_once("incfs: Unexpected inode type\n"); |
---|
| 349 | + return -EBADF; |
---|
| 350 | + } |
---|
| 351 | + |
---|
| 352 | + ihold(backing_inode); |
---|
| 353 | + node->n_backing_inode = backing_inode; |
---|
| 354 | + node->n_mount_info = get_mount_info(inode->i_sb); |
---|
| 355 | + inode->i_ctime = backing_inode->i_ctime; |
---|
| 356 | + inode->i_mtime = backing_inode->i_mtime; |
---|
| 357 | + inode->i_atime = backing_inode->i_atime; |
---|
| 358 | + inode->i_ino = backing_inode->i_ino; |
---|
| 359 | + if (backing_inode->i_ino < INCFS_START_INO_RANGE) { |
---|
| 360 | + pr_warn("incfs: ino conflict with backing FS %ld\n", |
---|
| 361 | + backing_inode->i_ino); |
---|
433 | 362 | } |
---|
434 | 363 | |
---|
435 | 364 | return 0; |
---|
.. | .. |
---|
443 | 372 | .ino = backing_inode->i_ino, |
---|
444 | 373 | .backing_dentry = backing_dentry, |
---|
445 | 374 | .size = read_size_attr(backing_dentry), |
---|
446 | | - }; |
---|
447 | | - struct inode *inode = iget5_locked(sb, search.ino, inode_test, |
---|
448 | | - inode_set, &search); |
---|
449 | | - |
---|
450 | | - if (!inode) |
---|
451 | | - return ERR_PTR(-ENOMEM); |
---|
452 | | - |
---|
453 | | - if (inode->i_state & I_NEW) |
---|
454 | | - unlock_new_inode(inode); |
---|
455 | | - |
---|
456 | | - return inode; |
---|
457 | | -} |
---|
458 | | - |
---|
459 | | -static ssize_t pending_reads_read(struct file *f, char __user *buf, size_t len, |
---|
460 | | - loff_t *ppos) |
---|
461 | | -{ |
---|
462 | | - struct pending_reads_state *pr_state = f->private_data; |
---|
463 | | - struct mount_info *mi = get_mount_info(file_superblock(f)); |
---|
464 | | - struct incfs_pending_read_info *reads_buf = NULL; |
---|
465 | | - size_t reads_to_collect = len / sizeof(*reads_buf); |
---|
466 | | - int last_known_read_sn = READ_ONCE(pr_state->last_pending_read_sn); |
---|
467 | | - int new_max_sn = last_known_read_sn; |
---|
468 | | - int reads_collected = 0; |
---|
469 | | - ssize_t result = 0; |
---|
470 | | - int i = 0; |
---|
471 | | - |
---|
472 | | - if (!incfs_fresh_pending_reads_exist(mi, last_known_read_sn)) |
---|
473 | | - return 0; |
---|
474 | | - |
---|
475 | | - reads_buf = (struct incfs_pending_read_info *)get_zeroed_page(GFP_NOFS); |
---|
476 | | - if (!reads_buf) |
---|
477 | | - return -ENOMEM; |
---|
478 | | - |
---|
479 | | - reads_to_collect = |
---|
480 | | - min_t(size_t, PAGE_SIZE / sizeof(*reads_buf), reads_to_collect); |
---|
481 | | - |
---|
482 | | - reads_collected = incfs_collect_pending_reads( |
---|
483 | | - mi, last_known_read_sn, reads_buf, reads_to_collect); |
---|
484 | | - if (reads_collected < 0) { |
---|
485 | | - result = reads_collected; |
---|
486 | | - goto out; |
---|
487 | | - } |
---|
488 | | - |
---|
489 | | - for (i = 0; i < reads_collected; i++) |
---|
490 | | - if (reads_buf[i].serial_number > new_max_sn) |
---|
491 | | - new_max_sn = reads_buf[i].serial_number; |
---|
492 | | - |
---|
493 | | - /* |
---|
494 | | - * Just to make sure that we don't accidentally copy more data |
---|
495 | | - * to reads buffer than userspace can handle. |
---|
496 | | - */ |
---|
497 | | - reads_collected = min_t(size_t, reads_collected, reads_to_collect); |
---|
498 | | - result = reads_collected * sizeof(*reads_buf); |
---|
499 | | - |
---|
500 | | - /* Copy reads info to the userspace buffer */ |
---|
501 | | - if (copy_to_user(buf, reads_buf, result)) { |
---|
502 | | - result = -EFAULT; |
---|
503 | | - goto out; |
---|
504 | | - } |
---|
505 | | - |
---|
506 | | - WRITE_ONCE(pr_state->last_pending_read_sn, new_max_sn); |
---|
507 | | - *ppos = 0; |
---|
508 | | -out: |
---|
509 | | - if (reads_buf) |
---|
510 | | - free_page((unsigned long)reads_buf); |
---|
511 | | - return result; |
---|
512 | | -} |
---|
513 | | - |
---|
514 | | - |
---|
515 | | -static __poll_t pending_reads_poll(struct file *file, poll_table *wait) |
---|
516 | | -{ |
---|
517 | | - struct pending_reads_state *state = file->private_data; |
---|
518 | | - struct mount_info *mi = get_mount_info(file_superblock(file)); |
---|
519 | | - __poll_t ret = 0; |
---|
520 | | - |
---|
521 | | - poll_wait(file, &mi->mi_pending_reads_notif_wq, wait); |
---|
522 | | - if (incfs_fresh_pending_reads_exist(mi, |
---|
523 | | - state->last_pending_read_sn)) |
---|
524 | | - ret = EPOLLIN | EPOLLRDNORM; |
---|
525 | | - |
---|
526 | | - return ret; |
---|
527 | | -} |
---|
528 | | - |
---|
529 | | -static int pending_reads_open(struct inode *inode, struct file *file) |
---|
530 | | -{ |
---|
531 | | - struct pending_reads_state *state = NULL; |
---|
532 | | - |
---|
533 | | - state = kzalloc(sizeof(*state), GFP_NOFS); |
---|
534 | | - if (!state) |
---|
535 | | - return -ENOMEM; |
---|
536 | | - |
---|
537 | | - file->private_data = state; |
---|
538 | | - return 0; |
---|
539 | | -} |
---|
540 | | - |
---|
541 | | -static int pending_reads_release(struct inode *inode, struct file *file) |
---|
542 | | -{ |
---|
543 | | - kfree(file->private_data); |
---|
544 | | - return 0; |
---|
545 | | -} |
---|
546 | | - |
---|
547 | | -static struct inode *fetch_pending_reads_inode(struct super_block *sb) |
---|
548 | | -{ |
---|
549 | | - struct inode_search search = { |
---|
550 | | - .ino = INCFS_PENDING_READS_INODE |
---|
551 | | - }; |
---|
552 | | - struct inode *inode = iget5_locked(sb, search.ino, inode_test, |
---|
553 | | - inode_set, &search); |
---|
554 | | - |
---|
555 | | - if (!inode) |
---|
556 | | - return ERR_PTR(-ENOMEM); |
---|
557 | | - |
---|
558 | | - if (inode->i_state & I_NEW) |
---|
559 | | - unlock_new_inode(inode); |
---|
560 | | - |
---|
561 | | - return inode; |
---|
562 | | -} |
---|
563 | | - |
---|
564 | | -static int log_open(struct inode *inode, struct file *file) |
---|
565 | | -{ |
---|
566 | | - struct log_file_state *log_state = NULL; |
---|
567 | | - struct mount_info *mi = get_mount_info(file_superblock(file)); |
---|
568 | | - |
---|
569 | | - log_state = kzalloc(sizeof(*log_state), GFP_NOFS); |
---|
570 | | - if (!log_state) |
---|
571 | | - return -ENOMEM; |
---|
572 | | - |
---|
573 | | - log_state->state = incfs_get_log_state(mi); |
---|
574 | | - file->private_data = log_state; |
---|
575 | | - return 0; |
---|
576 | | -} |
---|
577 | | - |
---|
578 | | -static int log_release(struct inode *inode, struct file *file) |
---|
579 | | -{ |
---|
580 | | - kfree(file->private_data); |
---|
581 | | - return 0; |
---|
582 | | -} |
---|
583 | | - |
---|
584 | | -static ssize_t log_read(struct file *f, char __user *buf, size_t len, |
---|
585 | | - loff_t *ppos) |
---|
586 | | -{ |
---|
587 | | - struct log_file_state *log_state = f->private_data; |
---|
588 | | - struct mount_info *mi = get_mount_info(file_superblock(f)); |
---|
589 | | - int total_reads_collected = 0; |
---|
590 | | - int rl_size; |
---|
591 | | - ssize_t result = 0; |
---|
592 | | - struct incfs_pending_read_info *reads_buf; |
---|
593 | | - ssize_t reads_to_collect = len / sizeof(*reads_buf); |
---|
594 | | - ssize_t reads_per_page = PAGE_SIZE / sizeof(*reads_buf); |
---|
595 | | - |
---|
596 | | - rl_size = READ_ONCE(mi->mi_log.rl_size); |
---|
597 | | - if (rl_size == 0) |
---|
598 | | - return 0; |
---|
599 | | - |
---|
600 | | - reads_buf = (struct incfs_pending_read_info *)__get_free_page(GFP_NOFS); |
---|
601 | | - if (!reads_buf) |
---|
602 | | - return -ENOMEM; |
---|
603 | | - |
---|
604 | | - reads_to_collect = min_t(ssize_t, rl_size, reads_to_collect); |
---|
605 | | - while (reads_to_collect > 0) { |
---|
606 | | - struct read_log_state next_state; |
---|
607 | | - int reads_collected; |
---|
608 | | - |
---|
609 | | - memcpy(&next_state, &log_state->state, sizeof(next_state)); |
---|
610 | | - reads_collected = incfs_collect_logged_reads( |
---|
611 | | - mi, &next_state, reads_buf, |
---|
612 | | - min_t(ssize_t, reads_to_collect, reads_per_page)); |
---|
613 | | - if (reads_collected <= 0) { |
---|
614 | | - result = total_reads_collected ? |
---|
615 | | - total_reads_collected * |
---|
616 | | - sizeof(*reads_buf) : |
---|
617 | | - reads_collected; |
---|
618 | | - goto out; |
---|
619 | | - } |
---|
620 | | - if (copy_to_user(buf, reads_buf, |
---|
621 | | - reads_collected * sizeof(*reads_buf))) { |
---|
622 | | - result = total_reads_collected ? |
---|
623 | | - total_reads_collected * |
---|
624 | | - sizeof(*reads_buf) : |
---|
625 | | - -EFAULT; |
---|
626 | | - goto out; |
---|
627 | | - } |
---|
628 | | - |
---|
629 | | - memcpy(&log_state->state, &next_state, sizeof(next_state)); |
---|
630 | | - total_reads_collected += reads_collected; |
---|
631 | | - buf += reads_collected * sizeof(*reads_buf); |
---|
632 | | - reads_to_collect -= reads_collected; |
---|
633 | | - } |
---|
634 | | - |
---|
635 | | - result = total_reads_collected * sizeof(*reads_buf); |
---|
636 | | - *ppos = 0; |
---|
637 | | -out: |
---|
638 | | - if (reads_buf) |
---|
639 | | - free_page((unsigned long)reads_buf); |
---|
640 | | - return result; |
---|
641 | | -} |
---|
642 | | - |
---|
643 | | -static __poll_t log_poll(struct file *file, poll_table *wait) |
---|
644 | | -{ |
---|
645 | | - struct log_file_state *log_state = file->private_data; |
---|
646 | | - struct mount_info *mi = get_mount_info(file_superblock(file)); |
---|
647 | | - int count; |
---|
648 | | - __poll_t ret = 0; |
---|
649 | | - |
---|
650 | | - poll_wait(file, &mi->mi_log.ml_notif_wq, wait); |
---|
651 | | - count = incfs_get_uncollected_logs_count(mi, &log_state->state); |
---|
652 | | - if (count >= mi->mi_options.read_log_wakeup_count) |
---|
653 | | - ret = EPOLLIN | EPOLLRDNORM; |
---|
654 | | - |
---|
655 | | - return ret; |
---|
656 | | -} |
---|
657 | | - |
---|
658 | | -static struct inode *fetch_log_inode(struct super_block *sb) |
---|
659 | | -{ |
---|
660 | | - struct inode_search search = { |
---|
661 | | - .ino = INCFS_LOG_INODE |
---|
| 375 | + .verity = read_verity_attr(backing_dentry), |
---|
662 | 376 | }; |
---|
663 | 377 | struct inode *inode = iget5_locked(sb, search.ino, inode_test, |
---|
664 | 378 | inode_set, &search); |
---|
.. | .. |
---|
679 | 393 | struct mount_info *mi = get_mount_info(file_superblock(file)); |
---|
680 | 394 | bool root; |
---|
681 | 395 | |
---|
682 | | - if (!dir || !mi) { |
---|
| 396 | + if (!dir) { |
---|
683 | 397 | error = -EBADF; |
---|
684 | 398 | goto out; |
---|
685 | 399 | } |
---|
.. | .. |
---|
687 | 401 | root = dir->backing_dir->f_inode |
---|
688 | 402 | == d_inode(mi->mi_backing_dir_path.dentry); |
---|
689 | 403 | |
---|
690 | | - if (root && ctx->pos == 0) { |
---|
691 | | - if (!dir_emit(ctx, pending_reads_file_name, |
---|
692 | | - ARRAY_SIZE(pending_reads_file_name) - 1, |
---|
693 | | - INCFS_PENDING_READS_INODE, DT_REG)) { |
---|
694 | | - error = -EINVAL; |
---|
| 404 | + if (root) { |
---|
| 405 | + error = emit_pseudo_files(ctx); |
---|
| 406 | + if (error) |
---|
695 | 407 | goto out; |
---|
696 | | - } |
---|
697 | | - ctx->pos++; |
---|
698 | 408 | } |
---|
699 | 409 | |
---|
700 | | - if (root && ctx->pos == 1) { |
---|
701 | | - if (!dir_emit(ctx, log_file_name, |
---|
702 | | - ARRAY_SIZE(log_file_name) - 1, |
---|
703 | | - INCFS_LOG_INODE, DT_REG)) { |
---|
704 | | - error = -EINVAL; |
---|
705 | | - goto out; |
---|
706 | | - } |
---|
707 | | - ctx->pos++; |
---|
708 | | - } |
---|
709 | | - |
---|
710 | | - ctx->pos -= 2; |
---|
| 410 | + ctx->pos -= PSEUDO_FILE_COUNT; |
---|
711 | 411 | error = iterate_dir(dir->backing_dir, ctx); |
---|
712 | | - ctx->pos += 2; |
---|
| 412 | + ctx->pos += PSEUDO_FILE_COUNT; |
---|
713 | 413 | file->f_pos = dir->backing_dir->f_pos; |
---|
714 | 414 | out: |
---|
715 | 415 | if (error) |
---|
.. | .. |
---|
736 | 436 | return 0; |
---|
737 | 437 | } |
---|
738 | 438 | |
---|
739 | | -static struct dentry *incfs_lookup_dentry(struct dentry *parent, |
---|
740 | | - const char *name) |
---|
| 439 | +static struct dentry *open_or_create_special_dir(struct dentry *backing_dir, |
---|
| 440 | + const char *name, |
---|
| 441 | + bool *created) |
---|
741 | 442 | { |
---|
742 | | - struct inode *inode; |
---|
743 | | - struct dentry *result = NULL; |
---|
744 | | - |
---|
745 | | - if (!parent) |
---|
746 | | - return ERR_PTR(-EFAULT); |
---|
747 | | - |
---|
748 | | - inode = d_inode(parent); |
---|
749 | | - inode_lock_nested(inode, I_MUTEX_PARENT); |
---|
750 | | - result = lookup_one_len(name, parent, strlen(name)); |
---|
751 | | - inode_unlock(inode); |
---|
752 | | - |
---|
753 | | - if (IS_ERR(result)) |
---|
754 | | - pr_warn("%s err:%ld\n", __func__, PTR_ERR(result)); |
---|
755 | | - |
---|
756 | | - return result; |
---|
757 | | -} |
---|
758 | | - |
---|
759 | | -static struct dentry *open_or_create_index_dir(struct dentry *backing_dir) |
---|
760 | | -{ |
---|
761 | | - static const char name[] = ".index"; |
---|
762 | 443 | struct dentry *index_dentry; |
---|
763 | 444 | struct inode *backing_inode = d_inode(backing_dir); |
---|
764 | 445 | int err = 0; |
---|
.. | .. |
---|
770 | 451 | return index_dentry; |
---|
771 | 452 | } else if (d_really_is_positive(index_dentry)) { |
---|
772 | 453 | /* Index already exists. */ |
---|
| 454 | + *created = false; |
---|
773 | 455 | return index_dentry; |
---|
774 | 456 | } |
---|
775 | 457 | |
---|
.. | .. |
---|
783 | 465 | return ERR_PTR(err); |
---|
784 | 466 | } |
---|
785 | 467 | |
---|
786 | | - if (!d_really_is_positive(index_dentry)) { |
---|
| 468 | + if (!d_really_is_positive(index_dentry) || |
---|
| 469 | + unlikely(d_unhashed(index_dentry))) { |
---|
787 | 470 | dput(index_dentry); |
---|
788 | 471 | return ERR_PTR(-EINVAL); |
---|
789 | 472 | } |
---|
790 | 473 | |
---|
| 474 | + *created = true; |
---|
791 | 475 | return index_dentry; |
---|
| 476 | +} |
---|
| 477 | + |
---|
| 478 | +static int read_single_page_timeouts(struct data_file *df, struct file *f, |
---|
| 479 | + int block_index, struct mem_range range, |
---|
| 480 | + struct mem_range tmp) |
---|
| 481 | +{ |
---|
| 482 | + struct mount_info *mi = df->df_mount_info; |
---|
| 483 | + struct incfs_read_data_file_timeouts timeouts = { |
---|
| 484 | + .max_pending_time_us = U32_MAX, |
---|
| 485 | + }; |
---|
| 486 | + int uid = current_uid().val; |
---|
| 487 | + int i; |
---|
| 488 | + |
---|
| 489 | + spin_lock(&mi->mi_per_uid_read_timeouts_lock); |
---|
| 490 | + for (i = 0; i < mi->mi_per_uid_read_timeouts_size / |
---|
| 491 | + sizeof(*mi->mi_per_uid_read_timeouts); ++i) { |
---|
| 492 | + struct incfs_per_uid_read_timeouts *t = |
---|
| 493 | + &mi->mi_per_uid_read_timeouts[i]; |
---|
| 494 | + |
---|
| 495 | + if(t->uid == uid) { |
---|
| 496 | + timeouts.min_time_us = t->min_time_us; |
---|
| 497 | + timeouts.min_pending_time_us = t->min_pending_time_us; |
---|
| 498 | + timeouts.max_pending_time_us = t->max_pending_time_us; |
---|
| 499 | + break; |
---|
| 500 | + } |
---|
| 501 | + } |
---|
| 502 | + spin_unlock(&mi->mi_per_uid_read_timeouts_lock); |
---|
| 503 | + if (timeouts.max_pending_time_us == U32_MAX) { |
---|
| 504 | + u64 read_timeout_us = (u64)mi->mi_options.read_timeout_ms * |
---|
| 505 | + 1000; |
---|
| 506 | + |
---|
| 507 | + timeouts.max_pending_time_us = read_timeout_us <= U32_MAX ? |
---|
| 508 | + read_timeout_us : U32_MAX; |
---|
| 509 | + } |
---|
| 510 | + |
---|
| 511 | + return incfs_read_data_file_block(range, f, block_index, tmp, |
---|
| 512 | + &timeouts); |
---|
792 | 513 | } |
---|
793 | 514 | |
---|
794 | 515 | static int read_single_page(struct file *f, struct page *page) |
---|
.. | .. |
---|
799 | 520 | ssize_t read_result = 0; |
---|
800 | 521 | struct data_file *df = get_incfs_data_file(f); |
---|
801 | 522 | int result = 0; |
---|
802 | | - void *page_start = kmap(page); |
---|
| 523 | + void *page_start; |
---|
803 | 524 | int block_index; |
---|
804 | | - int timeout_ms; |
---|
805 | 525 | |
---|
806 | | - if (!df) |
---|
| 526 | + if (!df) { |
---|
| 527 | + SetPageError(page); |
---|
| 528 | + unlock_page(page); |
---|
807 | 529 | return -EBADF; |
---|
| 530 | + } |
---|
808 | 531 | |
---|
| 532 | + page_start = kmap(page); |
---|
809 | 533 | offset = page_offset(page); |
---|
810 | | - block_index = offset / INCFS_DATA_FILE_BLOCK_SIZE; |
---|
| 534 | + block_index = (offset + df->df_mapped_offset) / |
---|
| 535 | + INCFS_DATA_FILE_BLOCK_SIZE; |
---|
811 | 536 | size = df->df_size; |
---|
812 | | - timeout_ms = df->df_mount_info->mi_options.read_timeout_ms; |
---|
813 | 537 | |
---|
814 | 538 | if (offset < size) { |
---|
815 | 539 | struct mem_range tmp = { |
---|
816 | 540 | .len = 2 * INCFS_DATA_FILE_BLOCK_SIZE |
---|
817 | 541 | }; |
---|
818 | | - |
---|
819 | 542 | tmp.data = (u8 *)__get_free_pages(GFP_NOFS, get_order(tmp.len)); |
---|
| 543 | + if (!tmp.data) { |
---|
| 544 | + read_result = -ENOMEM; |
---|
| 545 | + goto err; |
---|
| 546 | + } |
---|
820 | 547 | bytes_to_read = min_t(loff_t, size - offset, PAGE_SIZE); |
---|
821 | | - read_result = incfs_read_data_file_block( |
---|
822 | | - range(page_start, bytes_to_read), f, block_index, |
---|
823 | | - timeout_ms, tmp); |
---|
| 548 | + |
---|
| 549 | + read_result = read_single_page_timeouts(df, f, block_index, |
---|
| 550 | + range(page_start, bytes_to_read), tmp); |
---|
824 | 551 | |
---|
825 | 552 | free_pages((unsigned long)tmp.data, get_order(tmp.len)); |
---|
826 | 553 | } else { |
---|
.. | .. |
---|
828 | 555 | read_result = 0; |
---|
829 | 556 | } |
---|
830 | 557 | |
---|
| 558 | +err: |
---|
831 | 559 | if (read_result < 0) |
---|
832 | 560 | result = read_result; |
---|
833 | 561 | else if (read_result < PAGE_SIZE) |
---|
.. | .. |
---|
844 | 572 | return result; |
---|
845 | 573 | } |
---|
846 | 574 | |
---|
847 | | -static char *file_id_to_str(incfs_uuid_t id) |
---|
848 | | -{ |
---|
849 | | - char *result = kmalloc(1 + sizeof(id.bytes) * 2, GFP_NOFS); |
---|
850 | | - char *end; |
---|
851 | | - |
---|
852 | | - if (!result) |
---|
853 | | - return NULL; |
---|
854 | | - |
---|
855 | | - end = bin2hex(result, id.bytes, sizeof(id.bytes)); |
---|
856 | | - *end = 0; |
---|
857 | | - return result; |
---|
858 | | -} |
---|
859 | | - |
---|
860 | | -static struct mem_range incfs_copy_signature_info_from_user(u8 __user *original, |
---|
861 | | - u64 size) |
---|
862 | | -{ |
---|
863 | | - u8 *result; |
---|
864 | | - |
---|
865 | | - if (!original) |
---|
866 | | - return range(NULL, 0); |
---|
867 | | - |
---|
868 | | - if (size > INCFS_MAX_SIGNATURE_SIZE) |
---|
869 | | - return range(ERR_PTR(-EFAULT), 0); |
---|
870 | | - |
---|
871 | | - result = kzalloc(size, GFP_NOFS | __GFP_COMP); |
---|
872 | | - if (!result) |
---|
873 | | - return range(ERR_PTR(-ENOMEM), 0); |
---|
874 | | - |
---|
875 | | - if (copy_from_user(result, original, size)) { |
---|
876 | | - kfree(result); |
---|
877 | | - return range(ERR_PTR(-EFAULT), 0); |
---|
878 | | - } |
---|
879 | | - |
---|
880 | | - return range(result, size); |
---|
881 | | -} |
---|
882 | | - |
---|
883 | | -static int init_new_file(struct mount_info *mi, struct dentry *dentry, |
---|
884 | | - incfs_uuid_t *uuid, u64 size, struct mem_range attr, |
---|
885 | | - u8 __user *user_signature_info, u64 signature_size) |
---|
886 | | -{ |
---|
887 | | - struct path path = {}; |
---|
888 | | - struct file *new_file; |
---|
889 | | - int error = 0; |
---|
890 | | - struct backing_file_context *bfc = NULL; |
---|
891 | | - u32 block_count; |
---|
892 | | - struct mem_range raw_signature = { NULL }; |
---|
893 | | - struct mtree *hash_tree = NULL; |
---|
894 | | - |
---|
895 | | - if (!mi || !dentry || !uuid) |
---|
896 | | - return -EFAULT; |
---|
897 | | - |
---|
898 | | - /* Resize newly created file to its true size. */ |
---|
899 | | - path = (struct path) { |
---|
900 | | - .mnt = mi->mi_backing_dir_path.mnt, |
---|
901 | | - .dentry = dentry |
---|
902 | | - }; |
---|
903 | | - new_file = dentry_open(&path, O_RDWR | O_NOATIME | O_LARGEFILE, |
---|
904 | | - current_cred()); |
---|
905 | | - |
---|
906 | | - if (IS_ERR(new_file)) { |
---|
907 | | - error = PTR_ERR(new_file); |
---|
908 | | - goto out; |
---|
909 | | - } |
---|
910 | | - |
---|
911 | | - bfc = incfs_alloc_bfc(mi, new_file); |
---|
912 | | - fput(new_file); |
---|
913 | | - if (IS_ERR(bfc)) { |
---|
914 | | - error = PTR_ERR(bfc); |
---|
915 | | - bfc = NULL; |
---|
916 | | - goto out; |
---|
917 | | - } |
---|
918 | | - |
---|
919 | | - mutex_lock(&bfc->bc_mutex); |
---|
920 | | - error = incfs_write_fh_to_backing_file(bfc, uuid, size); |
---|
921 | | - if (error) |
---|
922 | | - goto out; |
---|
923 | | - |
---|
924 | | - if (attr.data && attr.len) { |
---|
925 | | - error = incfs_write_file_attr_to_backing_file(bfc, |
---|
926 | | - attr, NULL); |
---|
927 | | - if (error) |
---|
928 | | - goto out; |
---|
929 | | - } |
---|
930 | | - |
---|
931 | | - block_count = (u32)get_blocks_count_for_size(size); |
---|
932 | | - |
---|
933 | | - if (user_signature_info) { |
---|
934 | | - raw_signature = incfs_copy_signature_info_from_user( |
---|
935 | | - user_signature_info, signature_size); |
---|
936 | | - |
---|
937 | | - if (IS_ERR(raw_signature.data)) { |
---|
938 | | - error = PTR_ERR(raw_signature.data); |
---|
939 | | - raw_signature.data = NULL; |
---|
940 | | - goto out; |
---|
941 | | - } |
---|
942 | | - |
---|
943 | | - hash_tree = incfs_alloc_mtree(raw_signature, block_count); |
---|
944 | | - if (IS_ERR(hash_tree)) { |
---|
945 | | - error = PTR_ERR(hash_tree); |
---|
946 | | - hash_tree = NULL; |
---|
947 | | - goto out; |
---|
948 | | - } |
---|
949 | | - |
---|
950 | | - error = incfs_write_signature_to_backing_file( |
---|
951 | | - bfc, raw_signature, hash_tree->hash_tree_area_size); |
---|
952 | | - if (error) |
---|
953 | | - goto out; |
---|
954 | | - |
---|
955 | | - block_count += get_blocks_count_for_size( |
---|
956 | | - hash_tree->hash_tree_area_size); |
---|
957 | | - } |
---|
958 | | - |
---|
959 | | - if (block_count) |
---|
960 | | - error = incfs_write_blockmap_to_backing_file(bfc, block_count); |
---|
961 | | - |
---|
962 | | - if (error) |
---|
963 | | - goto out; |
---|
964 | | -out: |
---|
965 | | - if (bfc) { |
---|
966 | | - mutex_unlock(&bfc->bc_mutex); |
---|
967 | | - incfs_free_bfc(bfc); |
---|
968 | | - } |
---|
969 | | - incfs_free_mtree(hash_tree); |
---|
970 | | - kfree(raw_signature.data); |
---|
971 | | - |
---|
972 | | - if (error) |
---|
973 | | - pr_debug("incfs: %s error: %d\n", __func__, error); |
---|
974 | | - return error; |
---|
975 | | -} |
---|
976 | | - |
---|
977 | | -static int incfs_link(struct dentry *what, struct dentry *where) |
---|
| 575 | +int incfs_link(struct dentry *what, struct dentry *where) |
---|
978 | 576 | { |
---|
979 | 577 | struct dentry *parent_dentry = dget_parent(where); |
---|
980 | 578 | struct inode *pinode = d_inode(parent_dentry); |
---|
.. | .. |
---|
988 | 586 | return error; |
---|
989 | 587 | } |
---|
990 | 588 | |
---|
991 | | -static int incfs_unlink(struct dentry *dentry) |
---|
| 589 | +int incfs_unlink(struct dentry *dentry) |
---|
992 | 590 | { |
---|
993 | 591 | struct dentry *parent_dentry = dget_parent(dentry); |
---|
994 | 592 | struct inode *pinode = d_inode(parent_dentry); |
---|
.. | .. |
---|
1016 | 614 | return error; |
---|
1017 | 615 | } |
---|
1018 | 616 | |
---|
1019 | | -static int dir_relative_path_resolve( |
---|
1020 | | - struct mount_info *mi, |
---|
1021 | | - const char __user *relative_path, |
---|
1022 | | - struct path *result_path) |
---|
| 617 | +static void notify_unlink(struct dentry *dentry, const char *file_id_str, |
---|
| 618 | + const char *special_directory) |
---|
1023 | 619 | { |
---|
1024 | | - struct path *base_path = &mi->mi_backing_dir_path; |
---|
1025 | | - int dir_fd = get_unused_fd_flags(0); |
---|
1026 | | - struct file *dir_f = NULL; |
---|
| 620 | + struct dentry *root = dentry; |
---|
| 621 | + struct dentry *file = NULL; |
---|
| 622 | + struct dentry *dir = NULL; |
---|
1027 | 623 | int error = 0; |
---|
| 624 | + bool take_lock = root->d_parent != root->d_parent->d_parent; |
---|
1028 | 625 | |
---|
1029 | | - if (dir_fd < 0) |
---|
1030 | | - return dir_fd; |
---|
| 626 | + while (root != root->d_parent) |
---|
| 627 | + root = root->d_parent; |
---|
1031 | 628 | |
---|
1032 | | - dir_f = dentry_open(base_path, O_RDONLY | O_NOATIME, current_cred()); |
---|
| 629 | + if (take_lock) |
---|
| 630 | + dir = incfs_lookup_dentry(root, special_directory); |
---|
| 631 | + else |
---|
| 632 | + dir = lookup_one_len(special_directory, root, |
---|
| 633 | + strlen(special_directory)); |
---|
1033 | 634 | |
---|
1034 | | - if (IS_ERR(dir_f)) { |
---|
1035 | | - error = PTR_ERR(dir_f); |
---|
| 635 | + if (IS_ERR(dir)) { |
---|
| 636 | + error = PTR_ERR(dir); |
---|
1036 | 637 | goto out; |
---|
1037 | 638 | } |
---|
1038 | | - fd_install(dir_fd, dir_f); |
---|
1039 | | - |
---|
1040 | | - if (!relative_path) { |
---|
1041 | | - /* No relative path given, just return the base dir. */ |
---|
1042 | | - *result_path = *base_path; |
---|
1043 | | - path_get(result_path); |
---|
| 639 | + if (d_is_negative(dir)) { |
---|
| 640 | + error = -ENOENT; |
---|
1044 | 641 | goto out; |
---|
1045 | 642 | } |
---|
1046 | 643 | |
---|
1047 | | - error = user_path_at_empty(dir_fd, relative_path, |
---|
1048 | | - LOOKUP_FOLLOW | LOOKUP_DIRECTORY, result_path, NULL); |
---|
| 644 | + file = incfs_lookup_dentry(dir, file_id_str); |
---|
| 645 | + if (IS_ERR(file)) { |
---|
| 646 | + error = PTR_ERR(file); |
---|
| 647 | + goto out; |
---|
| 648 | + } |
---|
| 649 | + if (d_is_negative(file)) { |
---|
| 650 | + error = -ENOENT; |
---|
| 651 | + goto out; |
---|
| 652 | + } |
---|
| 653 | + |
---|
| 654 | + fsnotify_unlink(d_inode(dir), file); |
---|
| 655 | + d_delete(file); |
---|
1049 | 656 | |
---|
1050 | 657 | out: |
---|
1051 | | - ksys_close(dir_fd); |
---|
1052 | 658 | if (error) |
---|
1053 | | - pr_debug("incfs: %s %d\n", __func__, error); |
---|
1054 | | - return error; |
---|
| 659 | + pr_warn("%s failed with error %d\n", __func__, error); |
---|
| 660 | + |
---|
| 661 | + dput(dir); |
---|
| 662 | + dput(file); |
---|
1055 | 663 | } |
---|
1056 | 664 | |
---|
1057 | | -static int validate_name(char *file_name) |
---|
| 665 | +static void maybe_delete_incomplete_file(struct file *f, |
---|
| 666 | + struct data_file *df) |
---|
1058 | 667 | { |
---|
1059 | | - struct mem_range name = range(file_name, strlen(file_name)); |
---|
1060 | | - int i = 0; |
---|
1061 | | - |
---|
1062 | | - if (name.len > INCFS_MAX_NAME_LEN) |
---|
1063 | | - return -ENAMETOOLONG; |
---|
1064 | | - |
---|
1065 | | - if (incfs_equal_ranges(pending_reads_file_name_range, name)) |
---|
1066 | | - return -EINVAL; |
---|
1067 | | - |
---|
1068 | | - for (i = 0; i < name.len; i++) |
---|
1069 | | - if (name.data[i] == '/') |
---|
1070 | | - return -EINVAL; |
---|
1071 | | - |
---|
1072 | | - return 0; |
---|
1073 | | -} |
---|
1074 | | - |
---|
1075 | | -static int chmod(struct dentry *dentry, umode_t mode) |
---|
1076 | | -{ |
---|
1077 | | - struct inode *inode = dentry->d_inode; |
---|
1078 | | - struct inode *delegated_inode = NULL; |
---|
1079 | | - struct iattr newattrs; |
---|
| 668 | + struct backing_file_context *bfc; |
---|
| 669 | + struct mount_info *mi = df->df_mount_info; |
---|
| 670 | + char *file_id_str = NULL; |
---|
| 671 | + struct dentry *incomplete_file_dentry = NULL; |
---|
| 672 | + const struct cred *old_cred = override_creds(mi->mi_owner); |
---|
1080 | 673 | int error; |
---|
1081 | 674 | |
---|
1082 | | -retry_deleg: |
---|
1083 | | - inode_lock(inode); |
---|
1084 | | - newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); |
---|
1085 | | - newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; |
---|
1086 | | - error = notify_change(dentry, &newattrs, &delegated_inode); |
---|
1087 | | - inode_unlock(inode); |
---|
1088 | | - if (delegated_inode) { |
---|
1089 | | - error = break_deleg_wait(&delegated_inode); |
---|
1090 | | - if (!error) |
---|
1091 | | - goto retry_deleg; |
---|
1092 | | - } |
---|
1093 | | - return error; |
---|
1094 | | -} |
---|
1095 | | - |
---|
1096 | | -static long ioctl_create_file(struct mount_info *mi, |
---|
1097 | | - struct incfs_new_file_args __user *usr_args) |
---|
1098 | | -{ |
---|
1099 | | - struct incfs_new_file_args args; |
---|
1100 | | - char *file_id_str = NULL; |
---|
1101 | | - struct dentry *index_file_dentry = NULL; |
---|
1102 | | - struct dentry *named_file_dentry = NULL; |
---|
1103 | | - struct path parent_dir_path = {}; |
---|
1104 | | - struct inode *index_dir_inode = NULL; |
---|
1105 | | - __le64 size_attr_value = 0; |
---|
1106 | | - char *file_name = NULL; |
---|
1107 | | - char *attr_value = NULL; |
---|
1108 | | - int error = 0; |
---|
1109 | | - bool locked = false; |
---|
1110 | | - |
---|
1111 | | - if (!mi || !mi->mi_index_dir) { |
---|
1112 | | - error = -EFAULT; |
---|
1113 | | - goto out; |
---|
1114 | | - } |
---|
1115 | | - |
---|
1116 | | - if (copy_from_user(&args, usr_args, sizeof(args)) > 0) { |
---|
1117 | | - error = -EFAULT; |
---|
1118 | | - goto out; |
---|
1119 | | - } |
---|
1120 | | - |
---|
1121 | | - file_name = strndup_user(u64_to_user_ptr(args.file_name), PATH_MAX); |
---|
1122 | | - if (IS_ERR(file_name)) { |
---|
1123 | | - error = PTR_ERR(file_name); |
---|
1124 | | - file_name = NULL; |
---|
1125 | | - goto out; |
---|
1126 | | - } |
---|
1127 | | - |
---|
1128 | | - error = validate_name(file_name); |
---|
1129 | | - if (error) |
---|
| 675 | + if (atomic_read(&df->df_data_blocks_written) < df->df_data_block_count) |
---|
1130 | 676 | goto out; |
---|
1131 | 677 | |
---|
1132 | | - file_id_str = file_id_to_str(args.file_id); |
---|
1133 | | - if (!file_id_str) { |
---|
1134 | | - error = -ENOMEM; |
---|
1135 | | - goto out; |
---|
1136 | | - } |
---|
| 678 | + /* Truncate file to remove any preallocated space */ |
---|
| 679 | + bfc = df->df_backing_file_context; |
---|
| 680 | + if (bfc) { |
---|
| 681 | + struct file *f = bfc->bc_file; |
---|
1137 | 682 | |
---|
1138 | | - error = mutex_lock_interruptible(&mi->mi_dir_struct_mutex); |
---|
1139 | | - if (error) |
---|
1140 | | - goto out; |
---|
1141 | | - locked = true; |
---|
| 683 | + if (f) { |
---|
| 684 | + loff_t size = i_size_read(file_inode(f)); |
---|
1142 | 685 | |
---|
1143 | | - /* Find a directory to put the file into. */ |
---|
1144 | | - error = dir_relative_path_resolve(mi, |
---|
1145 | | - u64_to_user_ptr(args.directory_path), |
---|
1146 | | - &parent_dir_path); |
---|
1147 | | - if (error) |
---|
1148 | | - goto out; |
---|
1149 | | - |
---|
1150 | | - if (parent_dir_path.dentry == mi->mi_index_dir) { |
---|
1151 | | - /* Can't create a file directly inside .index */ |
---|
1152 | | - error = -EBUSY; |
---|
1153 | | - goto out; |
---|
1154 | | - } |
---|
1155 | | - |
---|
1156 | | - /* Look up a dentry in the parent dir. It should be negative. */ |
---|
1157 | | - named_file_dentry = incfs_lookup_dentry(parent_dir_path.dentry, |
---|
1158 | | - file_name); |
---|
1159 | | - if (!named_file_dentry) { |
---|
1160 | | - error = -EFAULT; |
---|
1161 | | - goto out; |
---|
1162 | | - } |
---|
1163 | | - if (IS_ERR(named_file_dentry)) { |
---|
1164 | | - error = PTR_ERR(named_file_dentry); |
---|
1165 | | - named_file_dentry = NULL; |
---|
1166 | | - goto out; |
---|
1167 | | - } |
---|
1168 | | - if (d_really_is_positive(named_file_dentry)) { |
---|
1169 | | - /* File with this path already exists. */ |
---|
1170 | | - error = -EEXIST; |
---|
1171 | | - goto out; |
---|
1172 | | - } |
---|
1173 | | - /* Look up a dentry in the .index dir. It should be negative. */ |
---|
1174 | | - index_file_dentry = incfs_lookup_dentry(mi->mi_index_dir, file_id_str); |
---|
1175 | | - if (!index_file_dentry) { |
---|
1176 | | - error = -EFAULT; |
---|
1177 | | - goto out; |
---|
1178 | | - } |
---|
1179 | | - if (IS_ERR(index_file_dentry)) { |
---|
1180 | | - error = PTR_ERR(index_file_dentry); |
---|
1181 | | - index_file_dentry = NULL; |
---|
1182 | | - goto out; |
---|
1183 | | - } |
---|
1184 | | - if (d_really_is_positive(index_file_dentry)) { |
---|
1185 | | - /* File with this ID already exists in index. */ |
---|
1186 | | - error = -EEXIST; |
---|
1187 | | - goto out; |
---|
1188 | | - } |
---|
1189 | | - |
---|
1190 | | - /* Creating a file in the .index dir. */ |
---|
1191 | | - index_dir_inode = d_inode(mi->mi_index_dir); |
---|
1192 | | - inode_lock_nested(index_dir_inode, I_MUTEX_PARENT); |
---|
1193 | | - error = vfs_create(index_dir_inode, index_file_dentry, args.mode | 0222, |
---|
1194 | | - true); |
---|
1195 | | - inode_unlock(index_dir_inode); |
---|
1196 | | - |
---|
1197 | | - if (error) |
---|
1198 | | - goto out; |
---|
1199 | | - if (!d_really_is_positive(index_file_dentry)) { |
---|
1200 | | - error = -EINVAL; |
---|
1201 | | - goto out; |
---|
1202 | | - } |
---|
1203 | | - |
---|
1204 | | - error = chmod(index_file_dentry, args.mode | 0222); |
---|
1205 | | - if (error) { |
---|
1206 | | - pr_debug("incfs: chmod err: %d\n", error); |
---|
1207 | | - goto delete_index_file; |
---|
1208 | | - } |
---|
1209 | | - |
---|
1210 | | - /* Save the file's ID as an xattr for easy fetching in future. */ |
---|
1211 | | - error = vfs_setxattr(index_file_dentry, INCFS_XATTR_ID_NAME, |
---|
1212 | | - file_id_str, strlen(file_id_str), XATTR_CREATE); |
---|
1213 | | - if (error) { |
---|
1214 | | - pr_debug("incfs: vfs_setxattr err:%d\n", error); |
---|
1215 | | - goto delete_index_file; |
---|
1216 | | - } |
---|
1217 | | - |
---|
1218 | | - /* Save the file's size as an xattr for easy fetching in future. */ |
---|
1219 | | - size_attr_value = cpu_to_le64(args.size); |
---|
1220 | | - error = vfs_setxattr(index_file_dentry, INCFS_XATTR_SIZE_NAME, |
---|
1221 | | - (char *)&size_attr_value, sizeof(size_attr_value), |
---|
1222 | | - XATTR_CREATE); |
---|
1223 | | - if (error) { |
---|
1224 | | - pr_debug("incfs: vfs_setxattr err:%d\n", error); |
---|
1225 | | - goto delete_index_file; |
---|
1226 | | - } |
---|
1227 | | - |
---|
1228 | | - /* Save the file's attribute as an xattr */ |
---|
1229 | | - if (args.file_attr_len && args.file_attr) { |
---|
1230 | | - if (args.file_attr_len > INCFS_MAX_FILE_ATTR_SIZE) { |
---|
1231 | | - error = -E2BIG; |
---|
1232 | | - goto delete_index_file; |
---|
| 686 | + error = vfs_truncate(&f->f_path, size); |
---|
| 687 | + if (error) |
---|
| 688 | + /* No useful action on failure */ |
---|
| 689 | + pr_warn("incfs: Failed to truncate complete file: %d\n", |
---|
| 690 | + error); |
---|
1233 | 691 | } |
---|
1234 | | - |
---|
1235 | | - attr_value = kmalloc(args.file_attr_len, GFP_NOFS); |
---|
1236 | | - if (!attr_value) { |
---|
1237 | | - error = -ENOMEM; |
---|
1238 | | - goto delete_index_file; |
---|
1239 | | - } |
---|
1240 | | - |
---|
1241 | | - if (copy_from_user(attr_value, |
---|
1242 | | - u64_to_user_ptr(args.file_attr), |
---|
1243 | | - args.file_attr_len) > 0) { |
---|
1244 | | - error = -EFAULT; |
---|
1245 | | - goto delete_index_file; |
---|
1246 | | - } |
---|
1247 | | - |
---|
1248 | | - error = vfs_setxattr(index_file_dentry, |
---|
1249 | | - INCFS_XATTR_METADATA_NAME, |
---|
1250 | | - attr_value, args.file_attr_len, |
---|
1251 | | - XATTR_CREATE); |
---|
1252 | | - |
---|
1253 | | - if (error) |
---|
1254 | | - goto delete_index_file; |
---|
1255 | 692 | } |
---|
1256 | 693 | |
---|
1257 | | - /* Initializing a newly created file. */ |
---|
1258 | | - error = init_new_file(mi, index_file_dentry, &args.file_id, args.size, |
---|
1259 | | - range(attr_value, args.file_attr_len), |
---|
1260 | | - (u8 __user *)args.signature_info, |
---|
1261 | | - args.signature_size); |
---|
1262 | | - if (error) |
---|
1263 | | - goto delete_index_file; |
---|
1264 | | - |
---|
1265 | | - /* Linking a file with it's real name from the requested dir. */ |
---|
1266 | | - error = incfs_link(index_file_dentry, named_file_dentry); |
---|
1267 | | - |
---|
1268 | | - if (!error) |
---|
| 694 | + /* This is best effort - there is no useful action to take on failure */ |
---|
| 695 | + file_id_str = file_id_to_str(df->df_id); |
---|
| 696 | + if (!file_id_str) |
---|
1269 | 697 | goto out; |
---|
1270 | 698 | |
---|
1271 | | -delete_index_file: |
---|
1272 | | - incfs_unlink(index_file_dentry); |
---|
| 699 | + incomplete_file_dentry = incfs_lookup_dentry( |
---|
| 700 | + df->df_mount_info->mi_incomplete_dir, |
---|
| 701 | + file_id_str); |
---|
| 702 | + if (!incomplete_file_dentry || IS_ERR(incomplete_file_dentry)) { |
---|
| 703 | + incomplete_file_dentry = NULL; |
---|
| 704 | + goto out; |
---|
| 705 | + } |
---|
| 706 | + |
---|
| 707 | + if (!d_really_is_positive(incomplete_file_dentry)) |
---|
| 708 | + goto out; |
---|
| 709 | + |
---|
| 710 | + vfs_fsync(df->df_backing_file_context->bc_file, 0); |
---|
| 711 | + error = incfs_unlink(incomplete_file_dentry); |
---|
| 712 | + if (error) { |
---|
| 713 | + pr_warn("incfs: Deleting incomplete file failed: %d\n", error); |
---|
| 714 | + goto out; |
---|
| 715 | + } |
---|
| 716 | + |
---|
| 717 | + notify_unlink(f->f_path.dentry, file_id_str, INCFS_INCOMPLETE_NAME); |
---|
1273 | 718 | |
---|
1274 | 719 | out: |
---|
1275 | | - if (error) |
---|
1276 | | - pr_debug("incfs: %s err:%d\n", __func__, error); |
---|
1277 | | - |
---|
| 720 | + dput(incomplete_file_dentry); |
---|
1278 | 721 | kfree(file_id_str); |
---|
1279 | | - kfree(file_name); |
---|
1280 | | - kfree(attr_value); |
---|
1281 | | - dput(named_file_dentry); |
---|
1282 | | - dput(index_file_dentry); |
---|
1283 | | - path_put(&parent_dir_path); |
---|
1284 | | - if (locked) |
---|
1285 | | - mutex_unlock(&mi->mi_dir_struct_mutex); |
---|
1286 | | - return error; |
---|
| 722 | + revert_creds(old_cred); |
---|
1287 | 723 | } |
---|
1288 | 724 | |
---|
1289 | 725 | static long ioctl_fill_blocks(struct file *f, void __user *arg) |
---|
.. | .. |
---|
1292 | 728 | struct incfs_fill_blocks fill_blocks; |
---|
1293 | 729 | struct incfs_fill_block __user *usr_fill_block_array; |
---|
1294 | 730 | struct data_file *df = get_incfs_data_file(f); |
---|
| 731 | + struct incfs_file_data *fd = f->private_data; |
---|
1295 | 732 | const ssize_t data_buf_size = 2 * INCFS_DATA_FILE_BLOCK_SIZE; |
---|
1296 | 733 | u8 *data_buf = NULL; |
---|
1297 | 734 | ssize_t error = 0; |
---|
.. | .. |
---|
1300 | 737 | if (!df) |
---|
1301 | 738 | return -EBADF; |
---|
1302 | 739 | |
---|
1303 | | - if ((uintptr_t)f->private_data != CAN_FILL) |
---|
| 740 | + if (!fd || fd->fd_fill_permission != CAN_FILL) |
---|
1304 | 741 | return -EPERM; |
---|
1305 | 742 | |
---|
1306 | 743 | if (copy_from_user(&fill_blocks, usr_fill_blocks, sizeof(fill_blocks))) |
---|
.. | .. |
---|
1346 | 783 | if (data_buf) |
---|
1347 | 784 | free_pages((unsigned long)data_buf, get_order(data_buf_size)); |
---|
1348 | 785 | |
---|
| 786 | + maybe_delete_incomplete_file(f, df); |
---|
| 787 | + |
---|
1349 | 788 | /* |
---|
1350 | 789 | * Only report the error if no records were processed, otherwise |
---|
1351 | 790 | * just return how many were processed successfully. |
---|
.. | .. |
---|
1354 | 793 | return error; |
---|
1355 | 794 | |
---|
1356 | 795 | return i; |
---|
1357 | | -} |
---|
1358 | | - |
---|
1359 | | -static long ioctl_permit_fill(struct file *f, void __user *arg) |
---|
1360 | | -{ |
---|
1361 | | - struct incfs_permit_fill __user *usr_permit_fill = arg; |
---|
1362 | | - struct incfs_permit_fill permit_fill; |
---|
1363 | | - long error = 0; |
---|
1364 | | - struct file *file = NULL; |
---|
1365 | | - |
---|
1366 | | - if (f->f_op != &incfs_pending_read_file_ops) |
---|
1367 | | - return -EPERM; |
---|
1368 | | - |
---|
1369 | | - if (copy_from_user(&permit_fill, usr_permit_fill, sizeof(permit_fill))) |
---|
1370 | | - return -EFAULT; |
---|
1371 | | - |
---|
1372 | | - file = fget(permit_fill.file_descriptor); |
---|
1373 | | - if (IS_ERR(file)) |
---|
1374 | | - return PTR_ERR(file); |
---|
1375 | | - |
---|
1376 | | - if (file->f_op != &incfs_file_ops) { |
---|
1377 | | - error = -EPERM; |
---|
1378 | | - goto out; |
---|
1379 | | - } |
---|
1380 | | - |
---|
1381 | | - if (file->f_inode->i_sb != f->f_inode->i_sb) { |
---|
1382 | | - error = -EPERM; |
---|
1383 | | - goto out; |
---|
1384 | | - } |
---|
1385 | | - |
---|
1386 | | - switch ((uintptr_t)file->private_data) { |
---|
1387 | | - case CANT_FILL: |
---|
1388 | | - file->private_data = (void *)CAN_FILL; |
---|
1389 | | - break; |
---|
1390 | | - |
---|
1391 | | - case CAN_FILL: |
---|
1392 | | - pr_debug("CAN_FILL already set"); |
---|
1393 | | - break; |
---|
1394 | | - |
---|
1395 | | - default: |
---|
1396 | | - pr_warn("Invalid file private data"); |
---|
1397 | | - error = -EFAULT; |
---|
1398 | | - goto out; |
---|
1399 | | - } |
---|
1400 | | - |
---|
1401 | | -out: |
---|
1402 | | - fput(file); |
---|
1403 | | - return error; |
---|
1404 | 796 | } |
---|
1405 | 797 | |
---|
1406 | 798 | static long ioctl_read_file_signature(struct file *f, void __user *arg) |
---|
.. | .. |
---|
1456 | 848 | struct incfs_get_filled_blocks_args __user *args_usr_ptr = arg; |
---|
1457 | 849 | struct incfs_get_filled_blocks_args args = {}; |
---|
1458 | 850 | struct data_file *df = get_incfs_data_file(f); |
---|
| 851 | + struct incfs_file_data *fd = f->private_data; |
---|
1459 | 852 | int error; |
---|
1460 | 853 | |
---|
1461 | | - if (!df) |
---|
| 854 | + if (!df || !fd) |
---|
1462 | 855 | return -EINVAL; |
---|
1463 | 856 | |
---|
1464 | | - if ((uintptr_t)f->private_data != CAN_FILL) |
---|
| 857 | + if (fd->fd_fill_permission != CAN_FILL) |
---|
1465 | 858 | return -EPERM; |
---|
1466 | 859 | |
---|
1467 | 860 | if (copy_from_user(&args, args_usr_ptr, sizeof(args)) > 0) |
---|
1468 | 861 | return -EINVAL; |
---|
1469 | 862 | |
---|
1470 | | - error = incfs_get_filled_blocks(df, &args); |
---|
| 863 | + error = incfs_get_filled_blocks(df, fd, &args); |
---|
1471 | 864 | |
---|
1472 | 865 | if (copy_to_user(args_usr_ptr, &args, sizeof(args))) |
---|
1473 | 866 | return -EFAULT; |
---|
.. | .. |
---|
1475 | 868 | return error; |
---|
1476 | 869 | } |
---|
1477 | 870 | |
---|
| 871 | +static long ioctl_get_block_count(struct file *f, void __user *arg) |
---|
| 872 | +{ |
---|
| 873 | + struct incfs_get_block_count_args __user *args_usr_ptr = arg; |
---|
| 874 | + struct incfs_get_block_count_args args = {}; |
---|
| 875 | + struct data_file *df = get_incfs_data_file(f); |
---|
| 876 | + |
---|
| 877 | + if (!df) |
---|
| 878 | + return -EINVAL; |
---|
| 879 | + |
---|
| 880 | + args.total_data_blocks_out = df->df_data_block_count; |
---|
| 881 | + args.filled_data_blocks_out = atomic_read(&df->df_data_blocks_written); |
---|
| 882 | + args.total_hash_blocks_out = df->df_total_block_count - |
---|
| 883 | + df->df_data_block_count; |
---|
| 884 | + args.filled_hash_blocks_out = atomic_read(&df->df_hash_blocks_written); |
---|
| 885 | + |
---|
| 886 | + if (copy_to_user(args_usr_ptr, &args, sizeof(args))) |
---|
| 887 | + return -EFAULT; |
---|
| 888 | + |
---|
| 889 | + return 0; |
---|
| 890 | +} |
---|
| 891 | + |
---|
| 892 | +static int incfs_ioctl_get_flags(struct file *f, void __user *arg) |
---|
| 893 | +{ |
---|
| 894 | + u32 flags = IS_VERITY(file_inode(f)) ? FS_VERITY_FL : 0; |
---|
| 895 | + |
---|
| 896 | + return put_user(flags, (int __user *) arg); |
---|
| 897 | +} |
---|
| 898 | + |
---|
1478 | 899 | static long dispatch_ioctl(struct file *f, unsigned int req, unsigned long arg) |
---|
1479 | 900 | { |
---|
1480 | | - struct mount_info *mi = get_mount_info(file_superblock(f)); |
---|
1481 | | - |
---|
1482 | 901 | switch (req) { |
---|
1483 | | - case INCFS_IOC_CREATE_FILE: |
---|
1484 | | - return ioctl_create_file(mi, (void __user *)arg); |
---|
1485 | 902 | case INCFS_IOC_FILL_BLOCKS: |
---|
1486 | 903 | return ioctl_fill_blocks(f, (void __user *)arg); |
---|
1487 | | - case INCFS_IOC_PERMIT_FILL: |
---|
1488 | | - return ioctl_permit_fill(f, (void __user *)arg); |
---|
1489 | 904 | case INCFS_IOC_READ_FILE_SIGNATURE: |
---|
1490 | 905 | return ioctl_read_file_signature(f, (void __user *)arg); |
---|
1491 | 906 | case INCFS_IOC_GET_FILLED_BLOCKS: |
---|
1492 | 907 | return ioctl_get_filled_blocks(f, (void __user *)arg); |
---|
| 908 | + case INCFS_IOC_GET_BLOCK_COUNT: |
---|
| 909 | + return ioctl_get_block_count(f, (void __user *)arg); |
---|
| 910 | + case FS_IOC_ENABLE_VERITY: |
---|
| 911 | + return incfs_ioctl_enable_verity(f, (const void __user *)arg); |
---|
| 912 | + case FS_IOC_GETFLAGS: |
---|
| 913 | + return incfs_ioctl_get_flags(f, (void __user *) arg); |
---|
| 914 | + case FS_IOC_MEASURE_VERITY: |
---|
| 915 | + return incfs_ioctl_measure_verity(f, (void __user *)arg); |
---|
| 916 | + case FS_IOC_READ_VERITY_METADATA: |
---|
| 917 | + return incfs_ioctl_read_verity_metadata(f, (void __user *)arg); |
---|
1493 | 918 | default: |
---|
1494 | 919 | return -EINVAL; |
---|
1495 | 920 | } |
---|
1496 | 921 | } |
---|
| 922 | + |
---|
| 923 | +#ifdef CONFIG_COMPAT |
---|
| 924 | +static long incfs_compat_ioctl(struct file *file, unsigned int cmd, |
---|
| 925 | + unsigned long arg) |
---|
| 926 | +{ |
---|
| 927 | + switch (cmd) { |
---|
| 928 | + case FS_IOC32_GETFLAGS: |
---|
| 929 | + cmd = FS_IOC_GETFLAGS; |
---|
| 930 | + break; |
---|
| 931 | + case INCFS_IOC_FILL_BLOCKS: |
---|
| 932 | + case INCFS_IOC_READ_FILE_SIGNATURE: |
---|
| 933 | + case INCFS_IOC_GET_FILLED_BLOCKS: |
---|
| 934 | + case INCFS_IOC_GET_BLOCK_COUNT: |
---|
| 935 | + case FS_IOC_ENABLE_VERITY: |
---|
| 936 | + case FS_IOC_MEASURE_VERITY: |
---|
| 937 | + case FS_IOC_READ_VERITY_METADATA: |
---|
| 938 | + break; |
---|
| 939 | + default: |
---|
| 940 | + return -ENOIOCTLCMD; |
---|
| 941 | + } |
---|
| 942 | + return dispatch_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); |
---|
| 943 | +} |
---|
| 944 | +#endif |
---|
1497 | 945 | |
---|
1498 | 946 | static struct dentry *dir_lookup(struct inode *dir_inode, struct dentry *dentry, |
---|
1499 | 947 | unsigned int flags) |
---|
.. | .. |
---|
1503 | 951 | struct dentry *backing_dentry = NULL; |
---|
1504 | 952 | struct path dir_backing_path = {}; |
---|
1505 | 953 | struct inode_info *dir_info = get_incfs_node(dir_inode); |
---|
1506 | | - struct mem_range name_range = |
---|
1507 | | - range((u8 *)dentry->d_name.name, dentry->d_name.len); |
---|
1508 | 954 | int err = 0; |
---|
| 955 | + |
---|
| 956 | + if (!mi || !dir_info || !dir_info->n_backing_inode) |
---|
| 957 | + return ERR_PTR(-EBADF); |
---|
1509 | 958 | |
---|
1510 | 959 | if (d_inode(mi->mi_backing_dir_path.dentry) == |
---|
1511 | 960 | dir_info->n_backing_inode) { |
---|
1512 | 961 | /* We do lookup in the FS root. Show pseudo files. */ |
---|
1513 | | - |
---|
1514 | | - if (incfs_equal_ranges(pending_reads_file_name_range, |
---|
1515 | | - name_range)) { |
---|
1516 | | - struct inode *inode = fetch_pending_reads_inode( |
---|
1517 | | - dir_inode->i_sb); |
---|
1518 | | - |
---|
1519 | | - if (IS_ERR(inode)) { |
---|
1520 | | - err = PTR_ERR(inode); |
---|
1521 | | - goto out; |
---|
1522 | | - } |
---|
1523 | | - |
---|
1524 | | - d_add(dentry, inode); |
---|
| 962 | + err = dir_lookup_pseudo_files(dir_inode->i_sb, dentry); |
---|
| 963 | + if (err != -ENOENT) |
---|
1525 | 964 | goto out; |
---|
1526 | | - } |
---|
1527 | | - |
---|
1528 | | - if (incfs_equal_ranges(log_file_name_range, name_range)) { |
---|
1529 | | - struct inode *inode = fetch_log_inode( |
---|
1530 | | - dir_inode->i_sb); |
---|
1531 | | - |
---|
1532 | | - if (IS_ERR(inode)) { |
---|
1533 | | - err = PTR_ERR(inode); |
---|
1534 | | - goto out; |
---|
1535 | | - } |
---|
1536 | | - |
---|
1537 | | - d_add(dentry, inode); |
---|
1538 | | - goto out; |
---|
1539 | | - } |
---|
| 965 | + err = 0; |
---|
1540 | 966 | } |
---|
1541 | 967 | |
---|
1542 | 968 | dir_dentry = dget_parent(dentry); |
---|
.. | .. |
---|
1622 | 1048 | |
---|
1623 | 1049 | if (!backing_dentry) { |
---|
1624 | 1050 | err = -EBADF; |
---|
1625 | | - goto out; |
---|
| 1051 | + goto path_err; |
---|
1626 | 1052 | } |
---|
1627 | 1053 | |
---|
1628 | 1054 | if (backing_dentry->d_parent == mi->mi_index_dir) { |
---|
.. | .. |
---|
1631 | 1057 | goto out; |
---|
1632 | 1058 | } |
---|
1633 | 1059 | |
---|
| 1060 | + if (backing_dentry->d_parent == mi->mi_incomplete_dir) { |
---|
| 1061 | + /* Can't create a subdir inside .incomplete */ |
---|
| 1062 | + err = -EBUSY; |
---|
| 1063 | + goto out; |
---|
| 1064 | + } |
---|
1634 | 1065 | inode_lock_nested(dir_node->n_backing_inode, I_MUTEX_PARENT); |
---|
1635 | 1066 | err = vfs_mkdir(dir_node->n_backing_inode, backing_dentry, mode | 0222); |
---|
1636 | 1067 | inode_unlock(dir_node->n_backing_inode); |
---|
1637 | 1068 | if (!err) { |
---|
1638 | 1069 | struct inode *inode = NULL; |
---|
1639 | 1070 | |
---|
1640 | | - if (d_really_is_negative(backing_dentry)) { |
---|
| 1071 | + if (d_really_is_negative(backing_dentry) || |
---|
| 1072 | + unlikely(d_unhashed(backing_dentry))) { |
---|
1641 | 1073 | err = -EINVAL; |
---|
1642 | 1074 | goto out; |
---|
1643 | 1075 | } |
---|
.. | .. |
---|
1654 | 1086 | if (d_really_is_negative(dentry)) |
---|
1655 | 1087 | d_drop(dentry); |
---|
1656 | 1088 | path_put(&backing_path); |
---|
| 1089 | + |
---|
| 1090 | +path_err: |
---|
1657 | 1091 | mutex_unlock(&mi->mi_dir_struct_mutex); |
---|
1658 | 1092 | if (err) |
---|
1659 | 1093 | pr_debug("incfs: %s err:%d\n", __func__, err); |
---|
1660 | 1094 | return err; |
---|
1661 | 1095 | } |
---|
1662 | 1096 | |
---|
1663 | | -/* Delete file referenced by backing_dentry and also its hardlink from .index */ |
---|
1664 | | -static int final_file_delete(struct mount_info *mi, |
---|
1665 | | - struct dentry *backing_dentry) |
---|
| 1097 | +/* |
---|
| 1098 | + * Delete file referenced by backing_dentry and if appropriate its hardlink |
---|
| 1099 | + * from .index and .incomplete |
---|
| 1100 | + */ |
---|
| 1101 | +static int file_delete(struct mount_info *mi, struct dentry *dentry, |
---|
| 1102 | + struct dentry *backing_dentry, int nlink) |
---|
1666 | 1103 | { |
---|
1667 | 1104 | struct dentry *index_file_dentry = NULL; |
---|
| 1105 | + struct dentry *incomplete_file_dentry = NULL; |
---|
1668 | 1106 | /* 2 chars per byte of file ID + 1 char for \0 */ |
---|
1669 | 1107 | char file_id_str[2 * sizeof(incfs_uuid_t) + 1] = {0}; |
---|
1670 | 1108 | ssize_t uuid_size = 0; |
---|
1671 | 1109 | int error = 0; |
---|
1672 | 1110 | |
---|
1673 | 1111 | WARN_ON(!mutex_is_locked(&mi->mi_dir_struct_mutex)); |
---|
| 1112 | + |
---|
| 1113 | + if (nlink > 3) |
---|
| 1114 | + goto just_unlink; |
---|
| 1115 | + |
---|
1674 | 1116 | uuid_size = vfs_getxattr(backing_dentry, INCFS_XATTR_ID_NAME, |
---|
1675 | 1117 | file_id_str, 2 * sizeof(incfs_uuid_t)); |
---|
1676 | 1118 | if (uuid_size < 0) { |
---|
.. | .. |
---|
1686 | 1128 | index_file_dentry = incfs_lookup_dentry(mi->mi_index_dir, file_id_str); |
---|
1687 | 1129 | if (IS_ERR(index_file_dentry)) { |
---|
1688 | 1130 | error = PTR_ERR(index_file_dentry); |
---|
| 1131 | + index_file_dentry = NULL; |
---|
1689 | 1132 | goto out; |
---|
1690 | 1133 | } |
---|
1691 | 1134 | |
---|
1692 | | - error = incfs_unlink(backing_dentry); |
---|
1693 | | - if (error) |
---|
1694 | | - goto out; |
---|
| 1135 | + if (d_really_is_positive(index_file_dentry) && nlink > 0) |
---|
| 1136 | + nlink--; |
---|
1695 | 1137 | |
---|
1696 | | - if (d_really_is_positive(index_file_dentry)) |
---|
| 1138 | + if (nlink > 2) |
---|
| 1139 | + goto just_unlink; |
---|
| 1140 | + |
---|
| 1141 | + incomplete_file_dentry = incfs_lookup_dentry(mi->mi_incomplete_dir, |
---|
| 1142 | + file_id_str); |
---|
| 1143 | + if (IS_ERR(incomplete_file_dentry)) { |
---|
| 1144 | + error = PTR_ERR(incomplete_file_dentry); |
---|
| 1145 | + incomplete_file_dentry = NULL; |
---|
| 1146 | + goto out; |
---|
| 1147 | + } |
---|
| 1148 | + |
---|
| 1149 | + if (d_really_is_positive(incomplete_file_dentry) && nlink > 0) |
---|
| 1150 | + nlink--; |
---|
| 1151 | + |
---|
| 1152 | + if (nlink > 1) |
---|
| 1153 | + goto just_unlink; |
---|
| 1154 | + |
---|
| 1155 | + if (d_really_is_positive(index_file_dentry)) { |
---|
1697 | 1156 | error = incfs_unlink(index_file_dentry); |
---|
| 1157 | + if (error) |
---|
| 1158 | + goto out; |
---|
| 1159 | + notify_unlink(dentry, file_id_str, INCFS_INDEX_NAME); |
---|
| 1160 | + } |
---|
| 1161 | + |
---|
| 1162 | + if (d_really_is_positive(incomplete_file_dentry)) { |
---|
| 1163 | + error = incfs_unlink(incomplete_file_dentry); |
---|
| 1164 | + if (error) |
---|
| 1165 | + goto out; |
---|
| 1166 | + notify_unlink(dentry, file_id_str, INCFS_INCOMPLETE_NAME); |
---|
| 1167 | + } |
---|
| 1168 | + |
---|
| 1169 | +just_unlink: |
---|
| 1170 | + error = incfs_unlink(backing_dentry); |
---|
| 1171 | + |
---|
1698 | 1172 | out: |
---|
1699 | 1173 | dput(index_file_dentry); |
---|
| 1174 | + dput(incomplete_file_dentry); |
---|
1700 | 1175 | if (error) |
---|
1701 | 1176 | pr_debug("incfs: delete_file_from_index err:%d\n", error); |
---|
1702 | 1177 | return error; |
---|
.. | .. |
---|
1709 | 1184 | struct kstat stat; |
---|
1710 | 1185 | int err = 0; |
---|
1711 | 1186 | |
---|
| 1187 | + if (!mi) |
---|
| 1188 | + return -EBADF; |
---|
| 1189 | + |
---|
1712 | 1190 | err = mutex_lock_interruptible(&mi->mi_dir_struct_mutex); |
---|
1713 | 1191 | if (err) |
---|
1714 | 1192 | return err; |
---|
.. | .. |
---|
1716 | 1194 | get_incfs_backing_path(dentry, &backing_path); |
---|
1717 | 1195 | if (!backing_path.dentry) { |
---|
1718 | 1196 | err = -EBADF; |
---|
1719 | | - goto out; |
---|
| 1197 | + goto path_err; |
---|
1720 | 1198 | } |
---|
1721 | 1199 | |
---|
1722 | 1200 | if (backing_path.dentry->d_parent == mi->mi_index_dir) { |
---|
1723 | 1201 | /* Direct unlink from .index are not allowed. */ |
---|
| 1202 | + err = -EBUSY; |
---|
| 1203 | + goto out; |
---|
| 1204 | + } |
---|
| 1205 | + |
---|
| 1206 | + if (backing_path.dentry->d_parent == mi->mi_incomplete_dir) { |
---|
| 1207 | + /* Direct unlink from .incomplete are not allowed. */ |
---|
1724 | 1208 | err = -EBUSY; |
---|
1725 | 1209 | goto out; |
---|
1726 | 1210 | } |
---|
.. | .. |
---|
1730 | 1214 | if (err) |
---|
1731 | 1215 | goto out; |
---|
1732 | 1216 | |
---|
1733 | | - if (stat.nlink == 2) { |
---|
1734 | | - /* |
---|
1735 | | - * This is the last named link to this file. The only one left |
---|
1736 | | - * is in .index. Remove them both now. |
---|
1737 | | - */ |
---|
1738 | | - err = final_file_delete(mi, backing_path.dentry); |
---|
1739 | | - } else { |
---|
1740 | | - /* There are other links to this file. Remove just this one. */ |
---|
1741 | | - err = incfs_unlink(backing_path.dentry); |
---|
1742 | | - } |
---|
| 1217 | + err = file_delete(mi, dentry, backing_path.dentry, stat.nlink); |
---|
1743 | 1218 | |
---|
1744 | 1219 | d_drop(dentry); |
---|
1745 | 1220 | out: |
---|
1746 | 1221 | path_put(&backing_path); |
---|
| 1222 | +path_err: |
---|
1747 | 1223 | if (err) |
---|
1748 | 1224 | pr_debug("incfs: %s err:%d\n", __func__, err); |
---|
1749 | 1225 | mutex_unlock(&mi->mi_dir_struct_mutex); |
---|
.. | .. |
---|
1758 | 1234 | struct path backing_new_path = {}; |
---|
1759 | 1235 | int error = 0; |
---|
1760 | 1236 | |
---|
| 1237 | + if (!mi) |
---|
| 1238 | + return -EBADF; |
---|
| 1239 | + |
---|
1761 | 1240 | error = mutex_lock_interruptible(&mi->mi_dir_struct_mutex); |
---|
1762 | 1241 | if (error) |
---|
1763 | 1242 | return error; |
---|
.. | .. |
---|
1767 | 1246 | |
---|
1768 | 1247 | if (backing_new_path.dentry->d_parent == mi->mi_index_dir) { |
---|
1769 | 1248 | /* Can't link to .index */ |
---|
| 1249 | + error = -EBUSY; |
---|
| 1250 | + goto out; |
---|
| 1251 | + } |
---|
| 1252 | + |
---|
| 1253 | + if (backing_new_path.dentry->d_parent == mi->mi_incomplete_dir) { |
---|
| 1254 | + /* Can't link to .incomplete */ |
---|
1770 | 1255 | error = -EBUSY; |
---|
1771 | 1256 | goto out; |
---|
1772 | 1257 | } |
---|
.. | .. |
---|
1804 | 1289 | struct path backing_path = {}; |
---|
1805 | 1290 | int err = 0; |
---|
1806 | 1291 | |
---|
| 1292 | + if (!mi) |
---|
| 1293 | + return -EBADF; |
---|
| 1294 | + |
---|
1807 | 1295 | err = mutex_lock_interruptible(&mi->mi_dir_struct_mutex); |
---|
1808 | 1296 | if (err) |
---|
1809 | 1297 | return err; |
---|
.. | .. |
---|
1811 | 1299 | get_incfs_backing_path(dentry, &backing_path); |
---|
1812 | 1300 | if (!backing_path.dentry) { |
---|
1813 | 1301 | err = -EBADF; |
---|
1814 | | - goto out; |
---|
| 1302 | + goto path_err; |
---|
1815 | 1303 | } |
---|
1816 | 1304 | |
---|
1817 | 1305 | if (backing_path.dentry == mi->mi_index_dir) { |
---|
1818 | 1306 | /* Can't delete .index */ |
---|
| 1307 | + err = -EBUSY; |
---|
| 1308 | + goto out; |
---|
| 1309 | + } |
---|
| 1310 | + |
---|
| 1311 | + if (backing_path.dentry == mi->mi_incomplete_dir) { |
---|
| 1312 | + /* Can't delete .incomplete */ |
---|
1819 | 1313 | err = -EBUSY; |
---|
1820 | 1314 | goto out; |
---|
1821 | 1315 | } |
---|
.. | .. |
---|
1825 | 1319 | d_drop(dentry); |
---|
1826 | 1320 | out: |
---|
1827 | 1321 | path_put(&backing_path); |
---|
| 1322 | + |
---|
| 1323 | +path_err: |
---|
1828 | 1324 | if (err) |
---|
1829 | 1325 | pr_debug("incfs: %s err:%d\n", __func__, err); |
---|
1830 | 1326 | mutex_unlock(&mi->mi_dir_struct_mutex); |
---|
.. | .. |
---|
1843 | 1339 | struct dentry *trap; |
---|
1844 | 1340 | int error = 0; |
---|
1845 | 1341 | |
---|
1846 | | - if (!mi) |
---|
1847 | | - return -EBADF; |
---|
1848 | | - |
---|
1849 | 1342 | error = mutex_lock_interruptible(&mi->mi_dir_struct_mutex); |
---|
1850 | 1343 | if (error) |
---|
1851 | 1344 | return error; |
---|
1852 | 1345 | |
---|
1853 | 1346 | backing_old_dentry = get_incfs_dentry(old_dentry)->backing_path.dentry; |
---|
| 1347 | + |
---|
| 1348 | + if (!backing_old_dentry || backing_old_dentry == mi->mi_index_dir || |
---|
| 1349 | + backing_old_dentry == mi->mi_incomplete_dir) { |
---|
| 1350 | + /* Renaming .index or .incomplete not allowed */ |
---|
| 1351 | + error = -EBUSY; |
---|
| 1352 | + goto exit; |
---|
| 1353 | + } |
---|
| 1354 | + |
---|
1854 | 1355 | backing_new_dentry = get_incfs_dentry(new_dentry)->backing_path.dentry; |
---|
1855 | 1356 | dget(backing_old_dentry); |
---|
1856 | 1357 | dget(backing_new_dentry); |
---|
.. | .. |
---|
1859 | 1360 | backing_new_dir_dentry = dget_parent(backing_new_dentry); |
---|
1860 | 1361 | target_inode = d_inode(new_dentry); |
---|
1861 | 1362 | |
---|
1862 | | - if (backing_old_dir_dentry == mi->mi_index_dir) { |
---|
1863 | | - /* Direct moves from .index are not allowed. */ |
---|
| 1363 | + if (backing_old_dir_dentry == mi->mi_index_dir || |
---|
| 1364 | + backing_old_dir_dentry == mi->mi_incomplete_dir) { |
---|
| 1365 | + /* Direct moves from .index or .incomplete are not allowed. */ |
---|
1864 | 1366 | error = -EBUSY; |
---|
1865 | 1367 | goto out; |
---|
1866 | 1368 | } |
---|
.. | .. |
---|
1897 | 1399 | dput(backing_new_dentry); |
---|
1898 | 1400 | dput(backing_old_dentry); |
---|
1899 | 1401 | |
---|
| 1402 | +exit: |
---|
1900 | 1403 | mutex_unlock(&mi->mi_dir_struct_mutex); |
---|
1901 | 1404 | if (error) |
---|
1902 | 1405 | pr_debug("incfs: %s err:%d\n", __func__, error); |
---|
.. | .. |
---|
1910 | 1413 | struct file *backing_file = NULL; |
---|
1911 | 1414 | struct path backing_path = {}; |
---|
1912 | 1415 | int err = 0; |
---|
| 1416 | + int flags = O_NOATIME | O_LARGEFILE | |
---|
| 1417 | + (S_ISDIR(inode->i_mode) ? O_RDONLY : O_RDWR); |
---|
1913 | 1418 | const struct cred *old_cred; |
---|
1914 | 1419 | |
---|
| 1420 | + WARN_ON(file->private_data); |
---|
| 1421 | + |
---|
| 1422 | + if (!mi) |
---|
| 1423 | + return -EBADF; |
---|
| 1424 | + |
---|
1915 | 1425 | get_incfs_backing_path(file->f_path.dentry, &backing_path); |
---|
| 1426 | + if (!backing_path.dentry) |
---|
| 1427 | + return -EBADF; |
---|
| 1428 | + |
---|
1916 | 1429 | old_cred = override_creds(mi->mi_owner); |
---|
1917 | | - backing_file = dentry_open(&backing_path, |
---|
1918 | | - O_RDWR | O_NOATIME | O_LARGEFILE, current_cred()); |
---|
| 1430 | + backing_file = dentry_open(&backing_path, flags, current_cred()); |
---|
1919 | 1431 | revert_creds(old_cred); |
---|
1920 | 1432 | path_put(&backing_path); |
---|
1921 | 1433 | |
---|
.. | .. |
---|
1926 | 1438 | } |
---|
1927 | 1439 | |
---|
1928 | 1440 | if (S_ISREG(inode->i_mode)) { |
---|
| 1441 | + struct incfs_file_data *fd = kzalloc(sizeof(*fd), GFP_NOFS); |
---|
| 1442 | + |
---|
| 1443 | + if (!fd) { |
---|
| 1444 | + err = -ENOMEM; |
---|
| 1445 | + goto out; |
---|
| 1446 | + } |
---|
| 1447 | + |
---|
| 1448 | + *fd = (struct incfs_file_data) { |
---|
| 1449 | + .fd_fill_permission = CANT_FILL, |
---|
| 1450 | + }; |
---|
| 1451 | + file->private_data = fd; |
---|
| 1452 | + |
---|
1929 | 1453 | err = make_inode_ready_for_data_ops(mi, inode, backing_file); |
---|
1930 | | - file->private_data = (void *)CANT_FILL; |
---|
| 1454 | + if (err) |
---|
| 1455 | + goto out; |
---|
| 1456 | + |
---|
| 1457 | + err = incfs_fsverity_file_open(inode, file); |
---|
| 1458 | + if (err) |
---|
| 1459 | + goto out; |
---|
1931 | 1460 | } else if (S_ISDIR(inode->i_mode)) { |
---|
1932 | 1461 | struct dir_file *dir = NULL; |
---|
1933 | 1462 | |
---|
.. | .. |
---|
1940 | 1469 | err = -EBADF; |
---|
1941 | 1470 | |
---|
1942 | 1471 | out: |
---|
1943 | | - if (err) |
---|
1944 | | - pr_debug("incfs: %s name:%s err: %d\n", __func__, |
---|
1945 | | - file->f_path.dentry->d_name.name, err); |
---|
| 1472 | + if (err) { |
---|
| 1473 | + pr_debug("name:%s err: %d\n", |
---|
| 1474 | + file->f_path.dentry->d_name.name, err); |
---|
| 1475 | + if (S_ISREG(inode->i_mode)) |
---|
| 1476 | + kfree(file->private_data); |
---|
| 1477 | + else if (S_ISDIR(inode->i_mode)) |
---|
| 1478 | + incfs_free_dir_file(file->private_data); |
---|
| 1479 | + |
---|
| 1480 | + file->private_data = NULL; |
---|
| 1481 | + } |
---|
| 1482 | + |
---|
1946 | 1483 | if (backing_file) |
---|
1947 | 1484 | fput(backing_file); |
---|
1948 | 1485 | return err; |
---|
.. | .. |
---|
1951 | 1488 | static int file_release(struct inode *inode, struct file *file) |
---|
1952 | 1489 | { |
---|
1953 | 1490 | if (S_ISREG(inode->i_mode)) { |
---|
1954 | | - /* Do nothing. |
---|
1955 | | - * data_file is released only by inode eviction. |
---|
1956 | | - */ |
---|
| 1491 | + kfree(file->private_data); |
---|
| 1492 | + file->private_data = NULL; |
---|
1957 | 1493 | } else if (S_ISDIR(inode->i_mode)) { |
---|
1958 | 1494 | struct dir_file *dir = get_incfs_dir_file(file); |
---|
1959 | 1495 | |
---|
.. | .. |
---|
2056 | 1592 | if (ia->ia_valid & ATTR_SIZE) |
---|
2057 | 1593 | return -EINVAL; |
---|
2058 | 1594 | |
---|
| 1595 | + if ((ia->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID)) && |
---|
| 1596 | + (ia->ia_valid & ATTR_MODE)) |
---|
| 1597 | + return -EINVAL; |
---|
| 1598 | + |
---|
2059 | 1599 | if (!di) |
---|
2060 | 1600 | return -EINVAL; |
---|
2061 | 1601 | backing_dentry = di->backing_path.dentry; |
---|
.. | .. |
---|
2085 | 1625 | return simple_setattr(dentry, ia); |
---|
2086 | 1626 | } |
---|
2087 | 1627 | |
---|
| 1628 | + |
---|
| 1629 | +static int incfs_getattr(const struct path *path, |
---|
| 1630 | + struct kstat *stat, u32 request_mask, |
---|
| 1631 | + unsigned int query_flags) |
---|
| 1632 | +{ |
---|
| 1633 | + struct inode *inode = d_inode(path->dentry); |
---|
| 1634 | + |
---|
| 1635 | + generic_fillattr(inode, stat); |
---|
| 1636 | + |
---|
| 1637 | + if (inode->i_ino < INCFS_START_INO_RANGE) |
---|
| 1638 | + return 0; |
---|
| 1639 | + |
---|
| 1640 | + stat->attributes &= ~STATX_ATTR_VERITY; |
---|
| 1641 | + if (IS_VERITY(inode)) |
---|
| 1642 | + stat->attributes |= STATX_ATTR_VERITY; |
---|
| 1643 | + stat->attributes_mask |= STATX_ATTR_VERITY; |
---|
| 1644 | + |
---|
| 1645 | + if (request_mask & STATX_BLOCKS) { |
---|
| 1646 | + struct kstat backing_kstat; |
---|
| 1647 | + struct dentry_info *di = get_incfs_dentry(path->dentry); |
---|
| 1648 | + int error = 0; |
---|
| 1649 | + struct path *backing_path; |
---|
| 1650 | + |
---|
| 1651 | + if (!di) |
---|
| 1652 | + return -EFSCORRUPTED; |
---|
| 1653 | + backing_path = &di->backing_path; |
---|
| 1654 | + error = vfs_getattr(backing_path, &backing_kstat, STATX_BLOCKS, |
---|
| 1655 | + AT_STATX_SYNC_AS_STAT); |
---|
| 1656 | + if (error) |
---|
| 1657 | + return error; |
---|
| 1658 | + |
---|
| 1659 | + stat->blocks = backing_kstat.blocks; |
---|
| 1660 | + } |
---|
| 1661 | + |
---|
| 1662 | + return 0; |
---|
| 1663 | +} |
---|
| 1664 | + |
---|
2088 | 1665 | static ssize_t incfs_getxattr(struct dentry *d, const char *name, |
---|
2089 | 1666 | void *value, size_t size) |
---|
2090 | 1667 | { |
---|
.. | .. |
---|
2092 | 1669 | struct mount_info *mi = get_mount_info(d->d_sb); |
---|
2093 | 1670 | char *stored_value; |
---|
2094 | 1671 | size_t stored_size; |
---|
2095 | | - |
---|
2096 | | - if (!mi) |
---|
2097 | | - return -EBADF; |
---|
| 1672 | + int i; |
---|
2098 | 1673 | |
---|
2099 | 1674 | if (di && di->backing_path.dentry) |
---|
2100 | 1675 | return vfs_getxattr(di->backing_path.dentry, name, value, size); |
---|
.. | .. |
---|
2102 | 1677 | if (strcmp(name, "security.selinux")) |
---|
2103 | 1678 | return -ENODATA; |
---|
2104 | 1679 | |
---|
2105 | | - if (!strcmp(d->d_iname, INCFS_PENDING_READS_FILENAME)) { |
---|
2106 | | - stored_value = mi->pending_read_xattr; |
---|
2107 | | - stored_size = mi->pending_read_xattr_size; |
---|
2108 | | - } else if (!strcmp(d->d_iname, INCFS_LOG_FILENAME)) { |
---|
2109 | | - stored_value = mi->log_xattr; |
---|
2110 | | - stored_size = mi->log_xattr_size; |
---|
2111 | | - } else { |
---|
| 1680 | + for (i = 0; i < PSEUDO_FILE_COUNT; ++i) |
---|
| 1681 | + if (!strcmp(d->d_iname, incfs_pseudo_file_names[i].data)) |
---|
| 1682 | + break; |
---|
| 1683 | + if (i == PSEUDO_FILE_COUNT) |
---|
2112 | 1684 | return -ENODATA; |
---|
2113 | | - } |
---|
2114 | 1685 | |
---|
| 1686 | + stored_value = mi->pseudo_file_xattr[i].data; |
---|
| 1687 | + stored_size = mi->pseudo_file_xattr[i].len; |
---|
2115 | 1688 | if (!stored_value) |
---|
2116 | 1689 | return -ENODATA; |
---|
2117 | 1690 | |
---|
.. | .. |
---|
2120 | 1693 | |
---|
2121 | 1694 | memcpy(value, stored_value, stored_size); |
---|
2122 | 1695 | return stored_size; |
---|
2123 | | - |
---|
2124 | 1696 | } |
---|
2125 | 1697 | |
---|
2126 | 1698 | |
---|
.. | .. |
---|
2129 | 1701 | { |
---|
2130 | 1702 | struct dentry_info *di = get_incfs_dentry(d); |
---|
2131 | 1703 | struct mount_info *mi = get_mount_info(d->d_sb); |
---|
2132 | | - void **stored_value; |
---|
| 1704 | + u8 **stored_value; |
---|
2133 | 1705 | size_t *stored_size; |
---|
2134 | | - |
---|
2135 | | - if (!mi) |
---|
2136 | | - return -EBADF; |
---|
| 1706 | + int i; |
---|
2137 | 1707 | |
---|
2138 | 1708 | if (di && di->backing_path.dentry) |
---|
2139 | 1709 | return vfs_setxattr(di->backing_path.dentry, name, value, size, |
---|
.. | .. |
---|
2145 | 1715 | if (size > INCFS_MAX_FILE_ATTR_SIZE) |
---|
2146 | 1716 | return -E2BIG; |
---|
2147 | 1717 | |
---|
2148 | | - if (!strcmp(d->d_iname, INCFS_PENDING_READS_FILENAME)) { |
---|
2149 | | - stored_value = &mi->pending_read_xattr; |
---|
2150 | | - stored_size = &mi->pending_read_xattr_size; |
---|
2151 | | - } else if (!strcmp(d->d_iname, INCFS_LOG_FILENAME)) { |
---|
2152 | | - stored_value = &mi->log_xattr; |
---|
2153 | | - stored_size = &mi->log_xattr_size; |
---|
2154 | | - } else { |
---|
| 1718 | + for (i = 0; i < PSEUDO_FILE_COUNT; ++i) |
---|
| 1719 | + if (!strcmp(d->d_iname, incfs_pseudo_file_names[i].data)) |
---|
| 1720 | + break; |
---|
| 1721 | + if (i == PSEUDO_FILE_COUNT) |
---|
2155 | 1722 | return -ENODATA; |
---|
2156 | | - } |
---|
2157 | 1723 | |
---|
| 1724 | + stored_value = &mi->pseudo_file_xattr[i].data; |
---|
| 1725 | + stored_size = &mi->pseudo_file_xattr[i].len; |
---|
2158 | 1726 | kfree (*stored_value); |
---|
2159 | 1727 | *stored_value = kzalloc(size, GFP_NOFS); |
---|
2160 | 1728 | if (!*stored_value) |
---|
.. | .. |
---|
2175 | 1743 | return vfs_listxattr(di->backing_path.dentry, list, size); |
---|
2176 | 1744 | } |
---|
2177 | 1745 | |
---|
2178 | | -static int incfs_test_super(struct super_block *s, void *p) |
---|
2179 | | -{ |
---|
2180 | | - return s->s_fs_info != NULL; |
---|
2181 | | -} |
---|
2182 | | - |
---|
2183 | 1746 | struct dentry *incfs_mount_fs(struct file_system_type *type, int flags, |
---|
2184 | 1747 | const char *dev_name, void *data) |
---|
2185 | 1748 | { |
---|
2186 | 1749 | struct mount_options options = {}; |
---|
2187 | 1750 | struct mount_info *mi = NULL; |
---|
2188 | 1751 | struct path backing_dir_path = {}; |
---|
2189 | | - struct dentry *index_dir; |
---|
| 1752 | + struct dentry *index_dir = NULL; |
---|
| 1753 | + struct dentry *incomplete_dir = NULL; |
---|
2190 | 1754 | struct super_block *src_fs_sb = NULL; |
---|
2191 | 1755 | struct inode *root_inode = NULL; |
---|
2192 | | - struct super_block *sb = sget(type, incfs_test_super, set_anon_super, |
---|
2193 | | - flags, NULL); |
---|
| 1756 | + struct super_block *sb = sget(type, NULL, set_anon_super, flags, NULL); |
---|
| 1757 | + bool dir_created = false; |
---|
2194 | 1758 | int error = 0; |
---|
2195 | 1759 | |
---|
2196 | 1760 | if (IS_ERR(sb)) |
---|
.. | .. |
---|
2199 | 1763 | sb->s_op = &incfs_super_ops; |
---|
2200 | 1764 | sb->s_d_op = &incfs_dentry_ops; |
---|
2201 | 1765 | sb->s_flags |= S_NOATIME; |
---|
2202 | | - sb->s_magic = (long)INCFS_MAGIC_NUMBER; |
---|
| 1766 | + sb->s_magic = INCFS_MAGIC_NUMBER; |
---|
2203 | 1767 | sb->s_time_gran = 1; |
---|
2204 | 1768 | sb->s_blocksize = INCFS_DATA_FILE_BLOCK_SIZE; |
---|
2205 | 1769 | sb->s_blocksize_bits = blksize_bits(sb->s_blocksize); |
---|
.. | .. |
---|
2207 | 1771 | |
---|
2208 | 1772 | BUILD_BUG_ON(PAGE_SIZE != INCFS_DATA_FILE_BLOCK_SIZE); |
---|
2209 | 1773 | |
---|
| 1774 | + if (!dev_name) { |
---|
| 1775 | + pr_err("incfs: Backing dir is not set, filesystem can't be mounted.\n"); |
---|
| 1776 | + error = -ENOENT; |
---|
| 1777 | + goto err_deactivate; |
---|
| 1778 | + } |
---|
| 1779 | + |
---|
2210 | 1780 | error = parse_options(&options, (char *)data); |
---|
2211 | 1781 | if (error != 0) { |
---|
2212 | 1782 | pr_err("incfs: Options parsing error. %d\n", error); |
---|
2213 | | - goto err; |
---|
| 1783 | + goto err_deactivate; |
---|
2214 | 1784 | } |
---|
2215 | 1785 | |
---|
2216 | 1786 | sb->s_bdi->ra_pages = options.readahead_pages; |
---|
2217 | 1787 | if (!dev_name) { |
---|
2218 | 1788 | pr_err("incfs: Backing dir is not set, filesystem can't be mounted.\n"); |
---|
2219 | 1789 | error = -ENOENT; |
---|
2220 | | - goto err; |
---|
| 1790 | + goto err_free_opts; |
---|
2221 | 1791 | } |
---|
2222 | 1792 | |
---|
2223 | 1793 | error = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, |
---|
.. | .. |
---|
2226 | 1796 | !d_really_is_positive(backing_dir_path.dentry)) { |
---|
2227 | 1797 | pr_err("incfs: Error accessing: %s.\n", |
---|
2228 | 1798 | dev_name); |
---|
2229 | | - goto err; |
---|
| 1799 | + goto err_free_opts; |
---|
2230 | 1800 | } |
---|
2231 | 1801 | src_fs_sb = backing_dir_path.dentry->d_sb; |
---|
2232 | 1802 | sb->s_maxbytes = src_fs_sb->s_maxbytes; |
---|
| 1803 | + sb->s_stack_depth = src_fs_sb->s_stack_depth + 1; |
---|
2233 | 1804 | |
---|
2234 | | - if (!sb->s_fs_info) { |
---|
2235 | | - mi = incfs_alloc_mount_info(sb, &options, &backing_dir_path); |
---|
2236 | | - |
---|
2237 | | - if (IS_ERR_OR_NULL(mi)) { |
---|
2238 | | - error = PTR_ERR(mi); |
---|
2239 | | - pr_err("incfs: Error allocating mount info. %d\n", |
---|
2240 | | - error); |
---|
2241 | | - mi = NULL; |
---|
2242 | | - goto err; |
---|
2243 | | - } |
---|
2244 | | - sb->s_fs_info = mi; |
---|
2245 | | - } else { |
---|
2246 | | - mi = sb->s_fs_info; |
---|
| 1805 | + if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) { |
---|
| 1806 | + error = -EINVAL; |
---|
| 1807 | + goto err_put_path; |
---|
2247 | 1808 | } |
---|
2248 | 1809 | |
---|
2249 | | - index_dir = open_or_create_index_dir(backing_dir_path.dentry); |
---|
| 1810 | + mi = incfs_alloc_mount_info(sb, &options, &backing_dir_path); |
---|
| 1811 | + if (IS_ERR_OR_NULL(mi)) { |
---|
| 1812 | + error = PTR_ERR(mi); |
---|
| 1813 | + pr_err("incfs: Error allocating mount info. %d\n", error); |
---|
| 1814 | + goto err_put_path; |
---|
| 1815 | + } |
---|
| 1816 | + |
---|
| 1817 | + sb->s_fs_info = mi; |
---|
| 1818 | + mi->mi_backing_dir_path = backing_dir_path; |
---|
| 1819 | + index_dir = open_or_create_special_dir(backing_dir_path.dentry, |
---|
| 1820 | + INCFS_INDEX_NAME, &dir_created); |
---|
2250 | 1821 | if (IS_ERR_OR_NULL(index_dir)) { |
---|
2251 | 1822 | error = PTR_ERR(index_dir); |
---|
2252 | 1823 | pr_err("incfs: Can't find or create .index dir in %s\n", |
---|
2253 | 1824 | dev_name); |
---|
2254 | | - goto err; |
---|
| 1825 | + /* No need to null index_dir since we don't put it */ |
---|
| 1826 | + goto err_put_path; |
---|
2255 | 1827 | } |
---|
| 1828 | + |
---|
2256 | 1829 | mi->mi_index_dir = index_dir; |
---|
| 1830 | + mi->mi_index_free = dir_created; |
---|
| 1831 | + |
---|
| 1832 | + incomplete_dir = open_or_create_special_dir(backing_dir_path.dentry, |
---|
| 1833 | + INCFS_INCOMPLETE_NAME, |
---|
| 1834 | + &dir_created); |
---|
| 1835 | + if (IS_ERR_OR_NULL(incomplete_dir)) { |
---|
| 1836 | + error = PTR_ERR(incomplete_dir); |
---|
| 1837 | + pr_err("incfs: Can't find or create .incomplete dir in %s\n", |
---|
| 1838 | + dev_name); |
---|
| 1839 | + /* No need to null incomplete_dir since we don't put it */ |
---|
| 1840 | + goto err_put_path; |
---|
| 1841 | + } |
---|
| 1842 | + mi->mi_incomplete_dir = incomplete_dir; |
---|
| 1843 | + mi->mi_incomplete_free = dir_created; |
---|
2257 | 1844 | |
---|
2258 | 1845 | root_inode = fetch_regular_inode(sb, backing_dir_path.dentry); |
---|
2259 | 1846 | if (IS_ERR(root_inode)) { |
---|
2260 | 1847 | error = PTR_ERR(root_inode); |
---|
2261 | | - goto err; |
---|
| 1848 | + goto err_put_path; |
---|
2262 | 1849 | } |
---|
2263 | 1850 | |
---|
| 1851 | + sb->s_root = d_make_root(root_inode); |
---|
2264 | 1852 | if (!sb->s_root) { |
---|
2265 | | - sb->s_root = d_make_root(root_inode); |
---|
2266 | | - if (!sb->s_root) { |
---|
2267 | | - error = -ENOMEM; |
---|
2268 | | - goto err; |
---|
2269 | | - } |
---|
2270 | | - error = incfs_init_dentry(sb->s_root, &backing_dir_path); |
---|
2271 | | - if (error) |
---|
2272 | | - goto err; |
---|
| 1853 | + error = -ENOMEM; |
---|
| 1854 | + goto err_put_path; |
---|
2273 | 1855 | } |
---|
| 1856 | + error = incfs_init_dentry(sb->s_root, &backing_dir_path); |
---|
| 1857 | + if (error) |
---|
| 1858 | + goto err_put_path; |
---|
2274 | 1859 | |
---|
2275 | | - mi->mi_backing_dir_path = backing_dir_path; |
---|
| 1860 | + path_put(&backing_dir_path); |
---|
2276 | 1861 | sb->s_flags |= SB_ACTIVE; |
---|
2277 | 1862 | |
---|
2278 | 1863 | pr_debug("incfs: mount\n"); |
---|
2279 | 1864 | return dget(sb->s_root); |
---|
2280 | | -err: |
---|
2281 | | - sb->s_fs_info = NULL; |
---|
| 1865 | + |
---|
| 1866 | +err_put_path: |
---|
2282 | 1867 | path_put(&backing_dir_path); |
---|
2283 | | - incfs_free_mount_info(mi); |
---|
| 1868 | +err_free_opts: |
---|
| 1869 | + free_options(&options); |
---|
| 1870 | +err_deactivate: |
---|
2284 | 1871 | deactivate_locked_super(sb); |
---|
| 1872 | + pr_err("incfs: mount failed %d\n", error); |
---|
2285 | 1873 | return ERR_PTR(error); |
---|
2286 | 1874 | } |
---|
2287 | 1875 | |
---|
.. | .. |
---|
2291 | 1879 | struct mount_info *mi = get_mount_info(sb); |
---|
2292 | 1880 | int err = 0; |
---|
2293 | 1881 | |
---|
2294 | | - if (!mi) |
---|
2295 | | - return err; |
---|
2296 | | - |
---|
2297 | 1882 | sync_filesystem(sb); |
---|
2298 | 1883 | err = parse_options(&options, (char *)data); |
---|
2299 | 1884 | if (err) |
---|
2300 | 1885 | return err; |
---|
2301 | 1886 | |
---|
| 1887 | + if (options.report_uid != mi->mi_options.report_uid) { |
---|
| 1888 | + pr_err("incfs: Can't change report_uid mount option on remount\n"); |
---|
| 1889 | + err = -EOPNOTSUPP; |
---|
| 1890 | + goto out; |
---|
| 1891 | + } |
---|
| 1892 | + |
---|
2302 | 1893 | err = incfs_realloc_mount_info(mi, &options); |
---|
2303 | 1894 | if (err) |
---|
2304 | | - return err; |
---|
| 1895 | + goto out; |
---|
2305 | 1896 | |
---|
2306 | 1897 | pr_debug("incfs: remount\n"); |
---|
2307 | | - return 0; |
---|
| 1898 | + |
---|
| 1899 | +out: |
---|
| 1900 | + free_options(&options); |
---|
| 1901 | + return err; |
---|
2308 | 1902 | } |
---|
2309 | 1903 | |
---|
2310 | 1904 | void incfs_kill_sb(struct super_block *sb) |
---|
2311 | 1905 | { |
---|
2312 | 1906 | struct mount_info *mi = sb->s_fs_info; |
---|
| 1907 | + struct inode *dinode = NULL; |
---|
2313 | 1908 | |
---|
2314 | 1909 | pr_debug("incfs: unmount\n"); |
---|
2315 | | - vfs_rmdir(d_inode(mi->mi_backing_dir_path.dentry), mi->mi_index_dir); |
---|
| 1910 | + |
---|
| 1911 | + if (mi) { |
---|
| 1912 | + if (mi->mi_backing_dir_path.dentry) |
---|
| 1913 | + dinode = d_inode(mi->mi_backing_dir_path.dentry); |
---|
| 1914 | + |
---|
| 1915 | + if (dinode) { |
---|
| 1916 | + if (mi->mi_index_dir && mi->mi_index_free) |
---|
| 1917 | + vfs_rmdir(dinode, mi->mi_index_dir); |
---|
| 1918 | + |
---|
| 1919 | + if (mi->mi_incomplete_dir && mi->mi_incomplete_free) |
---|
| 1920 | + vfs_rmdir(dinode, mi->mi_incomplete_dir); |
---|
| 1921 | + } |
---|
| 1922 | + |
---|
| 1923 | + incfs_free_mount_info(mi); |
---|
| 1924 | + sb->s_fs_info = NULL; |
---|
| 1925 | + } |
---|
2316 | 1926 | kill_anon_super(sb); |
---|
2317 | | - incfs_free_mount_info(mi); |
---|
2318 | | - sb->s_fs_info = NULL; |
---|
2319 | 1927 | } |
---|
2320 | 1928 | |
---|
2321 | 1929 | static int show_options(struct seq_file *m, struct dentry *root) |
---|
2322 | 1930 | { |
---|
2323 | 1931 | struct mount_info *mi = get_mount_info(root->d_sb); |
---|
2324 | | - |
---|
2325 | | - if (!mi) |
---|
2326 | | - return -EBADF; |
---|
2327 | 1932 | |
---|
2328 | 1933 | seq_printf(m, ",read_timeout_ms=%u", mi->mi_options.read_timeout_ms); |
---|
2329 | 1934 | seq_printf(m, ",readahead=%u", mi->mi_options.readahead_pages); |
---|
.. | .. |
---|
2332 | 1937 | seq_printf(m, ",rlog_wakeup_cnt=%u", |
---|
2333 | 1938 | mi->mi_options.read_log_wakeup_count); |
---|
2334 | 1939 | } |
---|
2335 | | - if (mi->mi_options.no_backing_file_cache) |
---|
2336 | | - seq_puts(m, ",no_bf_cache"); |
---|
2337 | | - if (mi->mi_options.no_backing_file_readahead) |
---|
2338 | | - seq_puts(m, ",no_bf_readahead"); |
---|
| 1940 | + if (mi->mi_options.report_uid) |
---|
| 1941 | + seq_puts(m, ",report_uid"); |
---|
| 1942 | + |
---|
| 1943 | + if (mi->mi_sysfs_node) |
---|
| 1944 | + seq_printf(m, ",sysfs_name=%s", |
---|
| 1945 | + kobject_name(&mi->mi_sysfs_node->isn_sysfs_node)); |
---|
2339 | 1946 | return 0; |
---|
2340 | 1947 | } |
---|