1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * linux/fs/ext4/ioctl.c 4 * 5 * Copyright (C) 1993, 1994, 1995 6 * Remy Card (card@masi.ibp.fr) 7 * Laboratoire MASI - Institut Blaise Pascal 8 * Universite Pierre et Marie Curie (Paris VI) 9 */ 10 11 #include <linux/fs.h> 12 #include <linux/capability.h> 13 #include <linux/time.h> 14 #include <linux/compat.h> 15 #include <linux/mount.h> 16 #include <linux/file.h> 17 #include <linux/quotaops.h> 18 #include <linux/random.h> 19 #include <linux/uuid.h> 20 #include <linux/uaccess.h> 21 #include <linux/delay.h> 22 #include <linux/iversion.h> 23 #include <linux/fileattr.h> 24 #include "ext4_jbd2.h" 25 #include "ext4.h" 26 #include <linux/fsmap.h> 27 #include "fsmap.h" 28 #include <trace/events/ext4.h> 29 30 /** 31 * Swap memory between @a and @b for @len bytes. 32 * 33 * @a: pointer to first memory area 34 * @b: pointer to second memory area 35 * @len: number of bytes to swap 36 * 37 */ 38 static void memswap(void *a, void *b, size_t len) 39 { 40 unsigned char *ap, *bp; 41 42 ap = (unsigned char *)a; 43 bp = (unsigned char *)b; 44 while (len-- > 0) { 45 swap(*ap, *bp); 46 ap++; 47 bp++; 48 } 49 } 50 51 /** 52 * Swap i_data and associated attributes between @inode1 and @inode2. 53 * This function is used for the primary swap between inode1 and inode2 54 * and also to revert this primary swap in case of errors. 55 * 56 * Therefore you have to make sure, that calling this method twice 57 * will revert all changes. 58 * 59 * @inode1: pointer to first inode 60 * @inode2: pointer to second inode 61 */ 62 static void swap_inode_data(struct inode *inode1, struct inode *inode2) 63 { 64 loff_t isize; 65 struct ext4_inode_info *ei1; 66 struct ext4_inode_info *ei2; 67 unsigned long tmp; 68 69 ei1 = EXT4_I(inode1); 70 ei2 = EXT4_I(inode2); 71 72 swap(inode1->i_version, inode2->i_version); 73 swap(inode1->i_atime, inode2->i_atime); 74 swap(inode1->i_mtime, inode2->i_mtime); 75 76 memswap(ei1->i_data, ei2->i_data, sizeof(ei1->i_data)); 77 tmp = ei1->i_flags & EXT4_FL_SHOULD_SWAP; 78 ei1->i_flags = (ei2->i_flags & EXT4_FL_SHOULD_SWAP) | 79 (ei1->i_flags & ~EXT4_FL_SHOULD_SWAP); 80 ei2->i_flags = tmp | (ei2->i_flags & ~EXT4_FL_SHOULD_SWAP); 81 swap(ei1->i_disksize, ei2->i_disksize); 82 ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS); 83 ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS); 84 85 isize = i_size_read(inode1); 86 i_size_write(inode1, i_size_read(inode2)); 87 i_size_write(inode2, isize); 88 } 89 90 void ext4_reset_inode_seed(struct inode *inode) 91 { 92 struct ext4_inode_info *ei = EXT4_I(inode); 93 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 94 __le32 inum = cpu_to_le32(inode->i_ino); 95 __le32 gen = cpu_to_le32(inode->i_generation); 96 __u32 csum; 97 98 if (!ext4_has_metadata_csum(inode->i_sb)) 99 return; 100 101 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&inum, sizeof(inum)); 102 ei->i_csum_seed = ext4_chksum(sbi, csum, (__u8 *)&gen, sizeof(gen)); 103 } 104 105 /** 106 * Swap the information from the given @inode and the inode 107 * EXT4_BOOT_LOADER_INO. It will basically swap i_data and all other 108 * important fields of the inodes. 109 * 110 * @sb: the super block of the filesystem 111 * @mnt_userns: user namespace of the mount the inode was found from 112 * @inode: the inode to swap with EXT4_BOOT_LOADER_INO 113 * 114 */ 115 static long swap_inode_boot_loader(struct super_block *sb, 116 struct user_namespace *mnt_userns, 117 struct inode *inode) 118 { 119 handle_t *handle; 120 int err; 121 struct inode *inode_bl; 122 struct ext4_inode_info *ei_bl; 123 qsize_t size, size_bl, diff; 124 blkcnt_t blocks; 125 unsigned short bytes; 126 127 inode_bl = ext4_iget(sb, EXT4_BOOT_LOADER_INO, EXT4_IGET_SPECIAL); 128 if (IS_ERR(inode_bl)) 129 return PTR_ERR(inode_bl); 130 ei_bl = EXT4_I(inode_bl); 131 132 /* Protect orig inodes against a truncate and make sure, 133 * that only 1 swap_inode_boot_loader is running. */ 134 lock_two_nondirectories(inode, inode_bl); 135 136 if (inode->i_nlink != 1 || !S_ISREG(inode->i_mode) || 137 IS_SWAPFILE(inode) || IS_ENCRYPTED(inode) || 138 (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) || 139 ext4_has_inline_data(inode)) { 140 err = -EINVAL; 141 goto journal_err_out; 142 } 143 144 if (IS_RDONLY(inode) || IS_APPEND(inode) || IS_IMMUTABLE(inode) || 145 !inode_owner_or_capable(mnt_userns, inode) || 146 !capable(CAP_SYS_ADMIN)) { 147 err = -EPERM; 148 goto journal_err_out; 149 } 150 151 filemap_invalidate_lock(inode->i_mapping); 152 err = filemap_write_and_wait(inode->i_mapping); 153 if (err) 154 goto err_out; 155 156 err = filemap_write_and_wait(inode_bl->i_mapping); 157 if (err) 158 goto err_out; 159 160 /* Wait for all existing dio workers */ 161 inode_dio_wait(inode); 162 inode_dio_wait(inode_bl); 163 164 truncate_inode_pages(&inode->i_data, 0); 165 truncate_inode_pages(&inode_bl->i_data, 0); 166 167 handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2); 168 if (IS_ERR(handle)) { 169 err = -EINVAL; 170 goto err_out; 171 } 172 ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_SWAP_BOOT); 173 174 /* Protect extent tree against block allocations via delalloc */ 175 ext4_double_down_write_data_sem(inode, inode_bl); 176 177 if (inode_bl->i_nlink == 0) { 178 /* this inode has never been used as a BOOT_LOADER */ 179 set_nlink(inode_bl, 1); 180 i_uid_write(inode_bl, 0); 181 i_gid_write(inode_bl, 0); 182 inode_bl->i_flags = 0; 183 ei_bl->i_flags = 0; 184 inode_set_iversion(inode_bl, 1); 185 i_size_write(inode_bl, 0); 186 inode_bl->i_mode = S_IFREG; 187 if (ext4_has_feature_extents(sb)) { 188 ext4_set_inode_flag(inode_bl, EXT4_INODE_EXTENTS); 189 ext4_ext_tree_init(handle, inode_bl); 190 } else 191 memset(ei_bl->i_data, 0, sizeof(ei_bl->i_data)); 192 } 193 194 err = dquot_initialize(inode); 195 if (err) 196 goto err_out1; 197 198 size = (qsize_t)(inode->i_blocks) * (1 << 9) + inode->i_bytes; 199 size_bl = (qsize_t)(inode_bl->i_blocks) * (1 << 9) + inode_bl->i_bytes; 200 diff = size - size_bl; 201 swap_inode_data(inode, inode_bl); 202 203 inode->i_ctime = inode_bl->i_ctime = current_time(inode); 204 205 inode->i_generation = prandom_u32(); 206 inode_bl->i_generation = prandom_u32(); 207 ext4_reset_inode_seed(inode); 208 ext4_reset_inode_seed(inode_bl); 209 210 ext4_discard_preallocations(inode, 0); 211 212 err = ext4_mark_inode_dirty(handle, inode); 213 if (err < 0) { 214 /* No need to update quota information. */ 215 ext4_warning(inode->i_sb, 216 "couldn't mark inode #%lu dirty (err %d)", 217 inode->i_ino, err); 218 /* Revert all changes: */ 219 swap_inode_data(inode, inode_bl); 220 ext4_mark_inode_dirty(handle, inode); 221 goto err_out1; 222 } 223 224 blocks = inode_bl->i_blocks; 225 bytes = inode_bl->i_bytes; 226 inode_bl->i_blocks = inode->i_blocks; 227 inode_bl->i_bytes = inode->i_bytes; 228 err = ext4_mark_inode_dirty(handle, inode_bl); 229 if (err < 0) { 230 /* No need to update quota information. */ 231 ext4_warning(inode_bl->i_sb, 232 "couldn't mark inode #%lu dirty (err %d)", 233 inode_bl->i_ino, err); 234 goto revert; 235 } 236 237 /* Bootloader inode should not be counted into quota information. */ 238 if (diff > 0) 239 dquot_free_space(inode, diff); 240 else 241 err = dquot_alloc_space(inode, -1 * diff); 242 243 if (err < 0) { 244 revert: 245 /* Revert all changes: */ 246 inode_bl->i_blocks = blocks; 247 inode_bl->i_bytes = bytes; 248 swap_inode_data(inode, inode_bl); 249 ext4_mark_inode_dirty(handle, inode); 250 ext4_mark_inode_dirty(handle, inode_bl); 251 } 252 253 err_out1: 254 ext4_journal_stop(handle); 255 ext4_double_up_write_data_sem(inode, inode_bl); 256 257 err_out: 258 filemap_invalidate_unlock(inode->i_mapping); 259 journal_err_out: 260 unlock_two_nondirectories(inode, inode_bl); 261 iput(inode_bl); 262 return err; 263 } 264 265 #ifdef CONFIG_FS_ENCRYPTION 266 static int uuid_is_zero(__u8 u[16]) 267 { 268 int i; 269 270 for (i = 0; i < 16; i++) 271 if (u[i]) 272 return 0; 273 return 1; 274 } 275 #endif 276 277 /* 278 * If immutable is set and we are not clearing it, we're not allowed to change 279 * anything else in the inode. Don't error out if we're only trying to set 280 * immutable on an immutable file. 281 */ 282 static int ext4_ioctl_check_immutable(struct inode *inode, __u32 new_projid, 283 unsigned int flags) 284 { 285 struct ext4_inode_info *ei = EXT4_I(inode); 286 unsigned int oldflags = ei->i_flags; 287 288 if (!(oldflags & EXT4_IMMUTABLE_FL) || !(flags & EXT4_IMMUTABLE_FL)) 289 return 0; 290 291 if ((oldflags & ~EXT4_IMMUTABLE_FL) != (flags & ~EXT4_IMMUTABLE_FL)) 292 return -EPERM; 293 if (ext4_has_feature_project(inode->i_sb) && 294 __kprojid_val(ei->i_projid) != new_projid) 295 return -EPERM; 296 297 return 0; 298 } 299 300 static void ext4_dax_dontcache(struct inode *inode, unsigned int flags) 301 { 302 struct ext4_inode_info *ei = EXT4_I(inode); 303 304 if (S_ISDIR(inode->i_mode)) 305 return; 306 307 if (test_opt2(inode->i_sb, DAX_NEVER) || 308 test_opt(inode->i_sb, DAX_ALWAYS)) 309 return; 310 311 if ((ei->i_flags ^ flags) & EXT4_DAX_FL) 312 d_mark_dontcache(inode); 313 } 314 315 static bool dax_compatible(struct inode *inode, unsigned int oldflags, 316 unsigned int flags) 317 { 318 /* Allow the DAX flag to be changed on inline directories */ 319 if (S_ISDIR(inode->i_mode)) { 320 flags &= ~EXT4_INLINE_DATA_FL; 321 oldflags &= ~EXT4_INLINE_DATA_FL; 322 } 323 324 if (flags & EXT4_DAX_FL) { 325 if ((oldflags & EXT4_DAX_MUT_EXCL) || 326 ext4_test_inode_state(inode, 327 EXT4_STATE_VERITY_IN_PROGRESS)) { 328 return false; 329 } 330 } 331 332 if ((flags & EXT4_DAX_MUT_EXCL) && (oldflags & EXT4_DAX_FL)) 333 return false; 334 335 return true; 336 } 337 338 static int ext4_ioctl_setflags(struct inode *inode, 339 unsigned int flags) 340 { 341 struct ext4_inode_info *ei = EXT4_I(inode); 342 handle_t *handle = NULL; 343 int err = -EPERM, migrate = 0; 344 struct ext4_iloc iloc; 345 unsigned int oldflags, mask, i; 346 struct super_block *sb = inode->i_sb; 347 348 /* Is it quota file? Do not allow user to mess with it */ 349 if (ext4_is_quota_file(inode)) 350 goto flags_out; 351 352 oldflags = ei->i_flags; 353 /* 354 * The JOURNAL_DATA flag can only be changed by 355 * the relevant capability. 356 */ 357 if ((flags ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) { 358 if (!capable(CAP_SYS_RESOURCE)) 359 goto flags_out; 360 } 361 362 if (!dax_compatible(inode, oldflags, flags)) { 363 err = -EOPNOTSUPP; 364 goto flags_out; 365 } 366 367 if ((flags ^ oldflags) & EXT4_EXTENTS_FL) 368 migrate = 1; 369 370 if ((flags ^ oldflags) & EXT4_CASEFOLD_FL) { 371 if (!ext4_has_feature_casefold(sb)) { 372 err = -EOPNOTSUPP; 373 goto flags_out; 374 } 375 376 if (!S_ISDIR(inode->i_mode)) { 377 err = -ENOTDIR; 378 goto flags_out; 379 } 380 381 if (!ext4_empty_dir(inode)) { 382 err = -ENOTEMPTY; 383 goto flags_out; 384 } 385 } 386 387 /* 388 * Wait for all pending directio and then flush all the dirty pages 389 * for this file. The flush marks all the pages readonly, so any 390 * subsequent attempt to write to the file (particularly mmap pages) 391 * will come through the filesystem and fail. 392 */ 393 if (S_ISREG(inode->i_mode) && !IS_IMMUTABLE(inode) && 394 (flags & EXT4_IMMUTABLE_FL)) { 395 inode_dio_wait(inode); 396 err = filemap_write_and_wait(inode->i_mapping); 397 if (err) 398 goto flags_out; 399 } 400 401 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1); 402 if (IS_ERR(handle)) { 403 err = PTR_ERR(handle); 404 goto flags_out; 405 } 406 if (IS_SYNC(inode)) 407 ext4_handle_sync(handle); 408 err = ext4_reserve_inode_write(handle, inode, &iloc); 409 if (err) 410 goto flags_err; 411 412 ext4_dax_dontcache(inode, flags); 413 414 for (i = 0, mask = 1; i < 32; i++, mask <<= 1) { 415 if (!(mask & EXT4_FL_USER_MODIFIABLE)) 416 continue; 417 /* These flags get special treatment later */ 418 if (mask == EXT4_JOURNAL_DATA_FL || mask == EXT4_EXTENTS_FL) 419 continue; 420 if (mask & flags) 421 ext4_set_inode_flag(inode, i); 422 else 423 ext4_clear_inode_flag(inode, i); 424 } 425 426 ext4_set_inode_flags(inode, false); 427 428 inode->i_ctime = current_time(inode); 429 430 err = ext4_mark_iloc_dirty(handle, inode, &iloc); 431 flags_err: 432 ext4_journal_stop(handle); 433 if (err) 434 goto flags_out; 435 436 if ((flags ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) { 437 /* 438 * Changes to the journaling mode can cause unsafe changes to 439 * S_DAX if the inode is DAX 440 */ 441 if (IS_DAX(inode)) { 442 err = -EBUSY; 443 goto flags_out; 444 } 445 446 err = ext4_change_inode_journal_flag(inode, 447 flags & EXT4_JOURNAL_DATA_FL); 448 if (err) 449 goto flags_out; 450 } 451 if (migrate) { 452 if (flags & EXT4_EXTENTS_FL) 453 err = ext4_ext_migrate(inode); 454 else 455 err = ext4_ind_migrate(inode); 456 } 457 458 flags_out: 459 return err; 460 } 461 462 #ifdef CONFIG_QUOTA 463 static int ext4_ioctl_setproject(struct inode *inode, __u32 projid) 464 { 465 struct super_block *sb = inode->i_sb; 466 struct ext4_inode_info *ei = EXT4_I(inode); 467 int err, rc; 468 handle_t *handle; 469 kprojid_t kprojid; 470 struct ext4_iloc iloc; 471 struct ext4_inode *raw_inode; 472 struct dquot *transfer_to[MAXQUOTAS] = { }; 473 474 if (!ext4_has_feature_project(sb)) { 475 if (projid != EXT4_DEF_PROJID) 476 return -EOPNOTSUPP; 477 else 478 return 0; 479 } 480 481 if (EXT4_INODE_SIZE(sb) <= EXT4_GOOD_OLD_INODE_SIZE) 482 return -EOPNOTSUPP; 483 484 kprojid = make_kprojid(&init_user_ns, (projid_t)projid); 485 486 if (projid_eq(kprojid, EXT4_I(inode)->i_projid)) 487 return 0; 488 489 err = -EPERM; 490 /* Is it quota file? Do not allow user to mess with it */ 491 if (ext4_is_quota_file(inode)) 492 return err; 493 494 err = ext4_get_inode_loc(inode, &iloc); 495 if (err) 496 return err; 497 498 raw_inode = ext4_raw_inode(&iloc); 499 if (!EXT4_FITS_IN_INODE(raw_inode, ei, i_projid)) { 500 err = ext4_expand_extra_isize(inode, 501 EXT4_SB(sb)->s_want_extra_isize, 502 &iloc); 503 if (err) 504 return err; 505 } else { 506 brelse(iloc.bh); 507 } 508 509 err = dquot_initialize(inode); 510 if (err) 511 return err; 512 513 handle = ext4_journal_start(inode, EXT4_HT_QUOTA, 514 EXT4_QUOTA_INIT_BLOCKS(sb) + 515 EXT4_QUOTA_DEL_BLOCKS(sb) + 3); 516 if (IS_ERR(handle)) 517 return PTR_ERR(handle); 518 519 err = ext4_reserve_inode_write(handle, inode, &iloc); 520 if (err) 521 goto out_stop; 522 523 transfer_to[PRJQUOTA] = dqget(sb, make_kqid_projid(kprojid)); 524 if (!IS_ERR(transfer_to[PRJQUOTA])) { 525 526 /* __dquot_transfer() calls back ext4_get_inode_usage() which 527 * counts xattr inode references. 528 */ 529 down_read(&EXT4_I(inode)->xattr_sem); 530 err = __dquot_transfer(inode, transfer_to); 531 up_read(&EXT4_I(inode)->xattr_sem); 532 dqput(transfer_to[PRJQUOTA]); 533 if (err) 534 goto out_dirty; 535 } 536 537 EXT4_I(inode)->i_projid = kprojid; 538 inode->i_ctime = current_time(inode); 539 out_dirty: 540 rc = ext4_mark_iloc_dirty(handle, inode, &iloc); 541 if (!err) 542 err = rc; 543 out_stop: 544 ext4_journal_stop(handle); 545 return err; 546 } 547 #else 548 static int ext4_ioctl_setproject(struct inode *inode, __u32 projid) 549 { 550 if (projid != EXT4_DEF_PROJID) 551 return -EOPNOTSUPP; 552 return 0; 553 } 554 #endif 555 556 static int ext4_shutdown(struct super_block *sb, unsigned long arg) 557 { 558 struct ext4_sb_info *sbi = EXT4_SB(sb); 559 __u32 flags; 560 561 if (!capable(CAP_SYS_ADMIN)) 562 return -EPERM; 563 564 if (get_user(flags, (__u32 __user *)arg)) 565 return -EFAULT; 566 567 if (flags > EXT4_GOING_FLAGS_NOLOGFLUSH) 568 return -EINVAL; 569 570 if (ext4_forced_shutdown(sbi)) 571 return 0; 572 573 ext4_msg(sb, KERN_ALERT, "shut down requested (%d)", flags); 574 trace_ext4_shutdown(sb, flags); 575 576 switch (flags) { 577 case EXT4_GOING_FLAGS_DEFAULT: 578 freeze_bdev(sb->s_bdev); 579 set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags); 580 thaw_bdev(sb->s_bdev); 581 break; 582 case EXT4_GOING_FLAGS_LOGFLUSH: 583 set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags); 584 if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) { 585 (void) ext4_force_commit(sb); 586 jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN); 587 } 588 break; 589 case EXT4_GOING_FLAGS_NOLOGFLUSH: 590 set_bit(EXT4_FLAGS_SHUTDOWN, &sbi->s_ext4_flags); 591 if (sbi->s_journal && !is_journal_aborted(sbi->s_journal)) 592 jbd2_journal_abort(sbi->s_journal, -ESHUTDOWN); 593 break; 594 default: 595 return -EINVAL; 596 } 597 clear_opt(sb, DISCARD); 598 return 0; 599 } 600 601 struct getfsmap_info { 602 struct super_block *gi_sb; 603 struct fsmap_head __user *gi_data; 604 unsigned int gi_idx; 605 __u32 gi_last_flags; 606 }; 607 608 static int ext4_getfsmap_format(struct ext4_fsmap *xfm, void *priv) 609 { 610 struct getfsmap_info *info = priv; 611 struct fsmap fm; 612 613 trace_ext4_getfsmap_mapping(info->gi_sb, xfm); 614 615 info->gi_last_flags = xfm->fmr_flags; 616 ext4_fsmap_from_internal(info->gi_sb, &fm, xfm); 617 if (copy_to_user(&info->gi_data->fmh_recs[info->gi_idx++], &fm, 618 sizeof(struct fsmap))) 619 return -EFAULT; 620 621 return 0; 622 } 623 624 static int ext4_ioc_getfsmap(struct super_block *sb, 625 struct fsmap_head __user *arg) 626 { 627 struct getfsmap_info info = { NULL }; 628 struct ext4_fsmap_head xhead = {0}; 629 struct fsmap_head head; 630 bool aborted = false; 631 int error; 632 633 if (copy_from_user(&head, arg, sizeof(struct fsmap_head))) 634 return -EFAULT; 635 if (memchr_inv(head.fmh_reserved, 0, sizeof(head.fmh_reserved)) || 636 memchr_inv(head.fmh_keys[0].fmr_reserved, 0, 637 sizeof(head.fmh_keys[0].fmr_reserved)) || 638 memchr_inv(head.fmh_keys[1].fmr_reserved, 0, 639 sizeof(head.fmh_keys[1].fmr_reserved))) 640 return -EINVAL; 641 /* 642 * ext4 doesn't report file extents at all, so the only valid 643 * file offsets are the magic ones (all zeroes or all ones). 644 */ 645 if (head.fmh_keys[0].fmr_offset || 646 (head.fmh_keys[1].fmr_offset != 0 && 647 head.fmh_keys[1].fmr_offset != -1ULL)) 648 return -EINVAL; 649 650 xhead.fmh_iflags = head.fmh_iflags; 651 xhead.fmh_count = head.fmh_count; 652 ext4_fsmap_to_internal(sb, &xhead.fmh_keys[0], &head.fmh_keys[0]); 653 ext4_fsmap_to_internal(sb, &xhead.fmh_keys[1], &head.fmh_keys[1]); 654 655 trace_ext4_getfsmap_low_key(sb, &xhead.fmh_keys[0]); 656 trace_ext4_getfsmap_high_key(sb, &xhead.fmh_keys[1]); 657 658 info.gi_sb = sb; 659 info.gi_data = arg; 660 error = ext4_getfsmap(sb, &xhead, ext4_getfsmap_format, &info); 661 if (error == EXT4_QUERY_RANGE_ABORT) 662 aborted = true; 663 else if (error) 664 return error; 665 666 /* If we didn't abort, set the "last" flag in the last fmx */ 667 if (!aborted && info.gi_idx) { 668 info.gi_last_flags |= FMR_OF_LAST; 669 if (copy_to_user(&info.gi_data->fmh_recs[info.gi_idx - 1].fmr_flags, 670 &info.gi_last_flags, 671 sizeof(info.gi_last_flags))) 672 return -EFAULT; 673 } 674 675 /* copy back header */ 676 head.fmh_entries = xhead.fmh_entries; 677 head.fmh_oflags = xhead.fmh_oflags; 678 if (copy_to_user(arg, &head, sizeof(struct fsmap_head))) 679 return -EFAULT; 680 681 return 0; 682 } 683 684 static long ext4_ioctl_group_add(struct file *file, 685 struct ext4_new_group_data *input) 686 { 687 struct super_block *sb = file_inode(file)->i_sb; 688 int err, err2=0; 689 690 err = ext4_resize_begin(sb); 691 if (err) 692 return err; 693 694 if (ext4_has_feature_bigalloc(sb)) { 695 ext4_msg(sb, KERN_ERR, 696 "Online resizing not supported with bigalloc"); 697 err = -EOPNOTSUPP; 698 goto group_add_out; 699 } 700 701 err = mnt_want_write_file(file); 702 if (err) 703 goto group_add_out; 704 705 err = ext4_group_add(sb, input); 706 if (EXT4_SB(sb)->s_journal) { 707 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); 708 err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal, 0); 709 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 710 } 711 if (err == 0) 712 err = err2; 713 mnt_drop_write_file(file); 714 if (!err && ext4_has_group_desc_csum(sb) && 715 test_opt(sb, INIT_INODE_TABLE)) 716 err = ext4_register_li_request(sb, input->group); 717 group_add_out: 718 ext4_resize_end(sb); 719 return err; 720 } 721 722 int ext4_fileattr_get(struct dentry *dentry, struct fileattr *fa) 723 { 724 struct inode *inode = d_inode(dentry); 725 struct ext4_inode_info *ei = EXT4_I(inode); 726 u32 flags = ei->i_flags & EXT4_FL_USER_VISIBLE; 727 728 if (S_ISREG(inode->i_mode)) 729 flags &= ~FS_PROJINHERIT_FL; 730 731 fileattr_fill_flags(fa, flags); 732 if (ext4_has_feature_project(inode->i_sb)) 733 fa->fsx_projid = from_kprojid(&init_user_ns, ei->i_projid); 734 735 return 0; 736 } 737 738 int ext4_fileattr_set(struct user_namespace *mnt_userns, 739 struct dentry *dentry, struct fileattr *fa) 740 { 741 struct inode *inode = d_inode(dentry); 742 u32 flags = fa->flags; 743 int err = -EOPNOTSUPP; 744 745 if (flags & ~EXT4_FL_USER_VISIBLE) 746 goto out; 747 748 /* 749 * chattr(1) grabs flags via GETFLAGS, modifies the result and 750 * passes that to SETFLAGS. So we cannot easily make SETFLAGS 751 * more restrictive than just silently masking off visible but 752 * not settable flags as we always did. 753 */ 754 flags &= EXT4_FL_USER_MODIFIABLE; 755 if (ext4_mask_flags(inode->i_mode, flags) != flags) 756 goto out; 757 err = ext4_ioctl_check_immutable(inode, fa->fsx_projid, flags); 758 if (err) 759 goto out; 760 err = ext4_ioctl_setflags(inode, flags); 761 if (err) 762 goto out; 763 err = ext4_ioctl_setproject(inode, fa->fsx_projid); 764 out: 765 return err; 766 } 767 768 /* So that the fiemap access checks can't overflow on 32 bit machines. */ 769 #define FIEMAP_MAX_EXTENTS (UINT_MAX / sizeof(struct fiemap_extent)) 770 771 static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg) 772 { 773 struct fiemap fiemap; 774 struct fiemap __user *ufiemap = (struct fiemap __user *) arg; 775 struct fiemap_extent_info fieinfo = { 0, }; 776 struct inode *inode = file_inode(filp); 777 int error; 778 779 if (copy_from_user(&fiemap, ufiemap, sizeof(fiemap))) 780 return -EFAULT; 781 782 if (fiemap.fm_extent_count > FIEMAP_MAX_EXTENTS) 783 return -EINVAL; 784 785 fieinfo.fi_flags = fiemap.fm_flags; 786 fieinfo.fi_extents_max = fiemap.fm_extent_count; 787 fieinfo.fi_extents_start = ufiemap->fm_extents; 788 789 error = ext4_get_es_cache(inode, &fieinfo, fiemap.fm_start, 790 fiemap.fm_length); 791 fiemap.fm_flags = fieinfo.fi_flags; 792 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped; 793 if (copy_to_user(ufiemap, &fiemap, sizeof(fiemap))) 794 error = -EFAULT; 795 796 return error; 797 } 798 799 static int ext4_ioctl_checkpoint(struct file *filp, unsigned long arg) 800 { 801 int err = 0; 802 __u32 flags = 0; 803 unsigned int flush_flags = 0; 804 struct super_block *sb = file_inode(filp)->i_sb; 805 struct request_queue *q; 806 807 if (copy_from_user(&flags, (__u32 __user *)arg, 808 sizeof(__u32))) 809 return -EFAULT; 810 811 if (!capable(CAP_SYS_ADMIN)) 812 return -EPERM; 813 814 /* check for invalid bits set */ 815 if ((flags & ~EXT4_IOC_CHECKPOINT_FLAG_VALID) || 816 ((flags & JBD2_JOURNAL_FLUSH_DISCARD) && 817 (flags & JBD2_JOURNAL_FLUSH_ZEROOUT))) 818 return -EINVAL; 819 820 if (!EXT4_SB(sb)->s_journal) 821 return -ENODEV; 822 823 if (flags & ~EXT4_IOC_CHECKPOINT_FLAG_VALID) 824 return -EINVAL; 825 826 q = bdev_get_queue(EXT4_SB(sb)->s_journal->j_dev); 827 if (!q) 828 return -ENXIO; 829 if ((flags & JBD2_JOURNAL_FLUSH_DISCARD) && !blk_queue_discard(q)) 830 return -EOPNOTSUPP; 831 832 if (flags & EXT4_IOC_CHECKPOINT_FLAG_DRY_RUN) 833 return 0; 834 835 if (flags & EXT4_IOC_CHECKPOINT_FLAG_DISCARD) 836 flush_flags |= JBD2_JOURNAL_FLUSH_DISCARD; 837 838 if (flags & EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT) { 839 flush_flags |= JBD2_JOURNAL_FLUSH_ZEROOUT; 840 pr_info_ratelimited("warning: checkpointing journal with EXT4_IOC_CHECKPOINT_FLAG_ZEROOUT can be slow"); 841 } 842 843 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); 844 err = jbd2_journal_flush(EXT4_SB(sb)->s_journal, flush_flags); 845 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 846 847 return err; 848 } 849 850 static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 851 { 852 struct inode *inode = file_inode(filp); 853 struct super_block *sb = inode->i_sb; 854 struct user_namespace *mnt_userns = file_mnt_user_ns(filp); 855 856 ext4_debug("cmd = %u, arg = %lu\n", cmd, arg); 857 858 switch (cmd) { 859 case FS_IOC_GETFSMAP: 860 return ext4_ioc_getfsmap(sb, (void __user *)arg); 861 case EXT4_IOC_GETVERSION: 862 case EXT4_IOC_GETVERSION_OLD: 863 return put_user(inode->i_generation, (int __user *) arg); 864 case EXT4_IOC_SETVERSION: 865 case EXT4_IOC_SETVERSION_OLD: { 866 handle_t *handle; 867 struct ext4_iloc iloc; 868 __u32 generation; 869 int err; 870 871 if (!inode_owner_or_capable(mnt_userns, inode)) 872 return -EPERM; 873 874 if (ext4_has_metadata_csum(inode->i_sb)) { 875 ext4_warning(sb, "Setting inode version is not " 876 "supported with metadata_csum enabled."); 877 return -ENOTTY; 878 } 879 880 err = mnt_want_write_file(filp); 881 if (err) 882 return err; 883 if (get_user(generation, (int __user *) arg)) { 884 err = -EFAULT; 885 goto setversion_out; 886 } 887 888 inode_lock(inode); 889 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1); 890 if (IS_ERR(handle)) { 891 err = PTR_ERR(handle); 892 goto unlock_out; 893 } 894 err = ext4_reserve_inode_write(handle, inode, &iloc); 895 if (err == 0) { 896 inode->i_ctime = current_time(inode); 897 inode->i_generation = generation; 898 err = ext4_mark_iloc_dirty(handle, inode, &iloc); 899 } 900 ext4_journal_stop(handle); 901 902 unlock_out: 903 inode_unlock(inode); 904 setversion_out: 905 mnt_drop_write_file(filp); 906 return err; 907 } 908 case EXT4_IOC_GROUP_EXTEND: { 909 ext4_fsblk_t n_blocks_count; 910 int err, err2=0; 911 912 err = ext4_resize_begin(sb); 913 if (err) 914 return err; 915 916 if (get_user(n_blocks_count, (__u32 __user *)arg)) { 917 err = -EFAULT; 918 goto group_extend_out; 919 } 920 921 if (ext4_has_feature_bigalloc(sb)) { 922 ext4_msg(sb, KERN_ERR, 923 "Online resizing not supported with bigalloc"); 924 err = -EOPNOTSUPP; 925 goto group_extend_out; 926 } 927 928 err = mnt_want_write_file(filp); 929 if (err) 930 goto group_extend_out; 931 932 err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count); 933 if (EXT4_SB(sb)->s_journal) { 934 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); 935 err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal, 0); 936 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 937 } 938 if (err == 0) 939 err = err2; 940 mnt_drop_write_file(filp); 941 group_extend_out: 942 ext4_resize_end(sb); 943 return err; 944 } 945 946 case EXT4_IOC_MOVE_EXT: { 947 struct move_extent me; 948 struct fd donor; 949 int err; 950 951 if (!(filp->f_mode & FMODE_READ) || 952 !(filp->f_mode & FMODE_WRITE)) 953 return -EBADF; 954 955 if (copy_from_user(&me, 956 (struct move_extent __user *)arg, sizeof(me))) 957 return -EFAULT; 958 me.moved_len = 0; 959 960 donor = fdget(me.donor_fd); 961 if (!donor.file) 962 return -EBADF; 963 964 if (!(donor.file->f_mode & FMODE_WRITE)) { 965 err = -EBADF; 966 goto mext_out; 967 } 968 969 if (ext4_has_feature_bigalloc(sb)) { 970 ext4_msg(sb, KERN_ERR, 971 "Online defrag not supported with bigalloc"); 972 err = -EOPNOTSUPP; 973 goto mext_out; 974 } else if (IS_DAX(inode)) { 975 ext4_msg(sb, KERN_ERR, 976 "Online defrag not supported with DAX"); 977 err = -EOPNOTSUPP; 978 goto mext_out; 979 } 980 981 err = mnt_want_write_file(filp); 982 if (err) 983 goto mext_out; 984 985 err = ext4_move_extents(filp, donor.file, me.orig_start, 986 me.donor_start, me.len, &me.moved_len); 987 mnt_drop_write_file(filp); 988 989 if (copy_to_user((struct move_extent __user *)arg, 990 &me, sizeof(me))) 991 err = -EFAULT; 992 mext_out: 993 fdput(donor); 994 return err; 995 } 996 997 case EXT4_IOC_GROUP_ADD: { 998 struct ext4_new_group_data input; 999 1000 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg, 1001 sizeof(input))) 1002 return -EFAULT; 1003 1004 return ext4_ioctl_group_add(filp, &input); 1005 } 1006 1007 case EXT4_IOC_MIGRATE: 1008 { 1009 int err; 1010 if (!inode_owner_or_capable(mnt_userns, inode)) 1011 return -EACCES; 1012 1013 err = mnt_want_write_file(filp); 1014 if (err) 1015 return err; 1016 /* 1017 * inode_mutex prevent write and truncate on the file. 1018 * Read still goes through. We take i_data_sem in 1019 * ext4_ext_swap_inode_data before we switch the 1020 * inode format to prevent read. 1021 */ 1022 inode_lock((inode)); 1023 err = ext4_ext_migrate(inode); 1024 inode_unlock((inode)); 1025 mnt_drop_write_file(filp); 1026 return err; 1027 } 1028 1029 case EXT4_IOC_ALLOC_DA_BLKS: 1030 { 1031 int err; 1032 if (!inode_owner_or_capable(mnt_userns, inode)) 1033 return -EACCES; 1034 1035 err = mnt_want_write_file(filp); 1036 if (err) 1037 return err; 1038 err = ext4_alloc_da_blocks(inode); 1039 mnt_drop_write_file(filp); 1040 return err; 1041 } 1042 1043 case EXT4_IOC_SWAP_BOOT: 1044 { 1045 int err; 1046 if (!(filp->f_mode & FMODE_WRITE)) 1047 return -EBADF; 1048 err = mnt_want_write_file(filp); 1049 if (err) 1050 return err; 1051 err = swap_inode_boot_loader(sb, mnt_userns, inode); 1052 mnt_drop_write_file(filp); 1053 return err; 1054 } 1055 1056 case EXT4_IOC_RESIZE_FS: { 1057 ext4_fsblk_t n_blocks_count; 1058 int err = 0, err2 = 0; 1059 ext4_group_t o_group = EXT4_SB(sb)->s_groups_count; 1060 1061 if (copy_from_user(&n_blocks_count, (__u64 __user *)arg, 1062 sizeof(__u64))) { 1063 return -EFAULT; 1064 } 1065 1066 err = ext4_resize_begin(sb); 1067 if (err) 1068 return err; 1069 1070 err = mnt_want_write_file(filp); 1071 if (err) 1072 goto resizefs_out; 1073 1074 err = ext4_resize_fs(sb, n_blocks_count); 1075 if (EXT4_SB(sb)->s_journal) { 1076 ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_RESIZE); 1077 jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal); 1078 err2 = jbd2_journal_flush(EXT4_SB(sb)->s_journal, 0); 1079 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 1080 } 1081 if (err == 0) 1082 err = err2; 1083 mnt_drop_write_file(filp); 1084 if (!err && (o_group < EXT4_SB(sb)->s_groups_count) && 1085 ext4_has_group_desc_csum(sb) && 1086 test_opt(sb, INIT_INODE_TABLE)) 1087 err = ext4_register_li_request(sb, o_group); 1088 1089 resizefs_out: 1090 ext4_resize_end(sb); 1091 return err; 1092 } 1093 1094 case FITRIM: 1095 { 1096 struct request_queue *q = bdev_get_queue(sb->s_bdev); 1097 struct fstrim_range range; 1098 int ret = 0; 1099 1100 if (!capable(CAP_SYS_ADMIN)) 1101 return -EPERM; 1102 1103 if (!blk_queue_discard(q)) 1104 return -EOPNOTSUPP; 1105 1106 /* 1107 * We haven't replayed the journal, so we cannot use our 1108 * block-bitmap-guided storage zapping commands. 1109 */ 1110 if (test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) 1111 return -EROFS; 1112 1113 if (copy_from_user(&range, (struct fstrim_range __user *)arg, 1114 sizeof(range))) 1115 return -EFAULT; 1116 1117 ret = ext4_trim_fs(sb, &range); 1118 if (ret < 0) 1119 return ret; 1120 1121 if (copy_to_user((struct fstrim_range __user *)arg, &range, 1122 sizeof(range))) 1123 return -EFAULT; 1124 1125 return 0; 1126 } 1127 case EXT4_IOC_PRECACHE_EXTENTS: 1128 return ext4_ext_precache(inode); 1129 1130 case FS_IOC_SET_ENCRYPTION_POLICY: 1131 if (!ext4_has_feature_encrypt(sb)) 1132 return -EOPNOTSUPP; 1133 return fscrypt_ioctl_set_policy(filp, (const void __user *)arg); 1134 1135 case FS_IOC_GET_ENCRYPTION_PWSALT: { 1136 #ifdef CONFIG_FS_ENCRYPTION 1137 int err, err2; 1138 struct ext4_sb_info *sbi = EXT4_SB(sb); 1139 handle_t *handle; 1140 1141 if (!ext4_has_feature_encrypt(sb)) 1142 return -EOPNOTSUPP; 1143 if (uuid_is_zero(sbi->s_es->s_encrypt_pw_salt)) { 1144 err = mnt_want_write_file(filp); 1145 if (err) 1146 return err; 1147 handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); 1148 if (IS_ERR(handle)) { 1149 err = PTR_ERR(handle); 1150 goto pwsalt_err_exit; 1151 } 1152 err = ext4_journal_get_write_access(handle, sb, 1153 sbi->s_sbh, 1154 EXT4_JTR_NONE); 1155 if (err) 1156 goto pwsalt_err_journal; 1157 lock_buffer(sbi->s_sbh); 1158 generate_random_uuid(sbi->s_es->s_encrypt_pw_salt); 1159 ext4_superblock_csum_set(sb); 1160 unlock_buffer(sbi->s_sbh); 1161 err = ext4_handle_dirty_metadata(handle, NULL, 1162 sbi->s_sbh); 1163 pwsalt_err_journal: 1164 err2 = ext4_journal_stop(handle); 1165 if (err2 && !err) 1166 err = err2; 1167 pwsalt_err_exit: 1168 mnt_drop_write_file(filp); 1169 if (err) 1170 return err; 1171 } 1172 if (copy_to_user((void __user *) arg, 1173 sbi->s_es->s_encrypt_pw_salt, 16)) 1174 return -EFAULT; 1175 return 0; 1176 #else 1177 return -EOPNOTSUPP; 1178 #endif 1179 } 1180 case FS_IOC_GET_ENCRYPTION_POLICY: 1181 if (!ext4_has_feature_encrypt(sb)) 1182 return -EOPNOTSUPP; 1183 return fscrypt_ioctl_get_policy(filp, (void __user *)arg); 1184 1185 case FS_IOC_GET_ENCRYPTION_POLICY_EX: 1186 if (!ext4_has_feature_encrypt(sb)) 1187 return -EOPNOTSUPP; 1188 return fscrypt_ioctl_get_policy_ex(filp, (void __user *)arg); 1189 1190 case FS_IOC_ADD_ENCRYPTION_KEY: 1191 if (!ext4_has_feature_encrypt(sb)) 1192 return -EOPNOTSUPP; 1193 return fscrypt_ioctl_add_key(filp, (void __user *)arg); 1194 1195 case FS_IOC_REMOVE_ENCRYPTION_KEY: 1196 if (!ext4_has_feature_encrypt(sb)) 1197 return -EOPNOTSUPP; 1198 return fscrypt_ioctl_remove_key(filp, (void __user *)arg); 1199 1200 case FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS: 1201 if (!ext4_has_feature_encrypt(sb)) 1202 return -EOPNOTSUPP; 1203 return fscrypt_ioctl_remove_key_all_users(filp, 1204 (void __user *)arg); 1205 case FS_IOC_GET_ENCRYPTION_KEY_STATUS: 1206 if (!ext4_has_feature_encrypt(sb)) 1207 return -EOPNOTSUPP; 1208 return fscrypt_ioctl_get_key_status(filp, (void __user *)arg); 1209 1210 case FS_IOC_GET_ENCRYPTION_NONCE: 1211 if (!ext4_has_feature_encrypt(sb)) 1212 return -EOPNOTSUPP; 1213 return fscrypt_ioctl_get_nonce(filp, (void __user *)arg); 1214 1215 case EXT4_IOC_CLEAR_ES_CACHE: 1216 { 1217 if (!inode_owner_or_capable(mnt_userns, inode)) 1218 return -EACCES; 1219 ext4_clear_inode_es(inode); 1220 return 0; 1221 } 1222 1223 case EXT4_IOC_GETSTATE: 1224 { 1225 __u32 state = 0; 1226 1227 if (ext4_test_inode_state(inode, EXT4_STATE_EXT_PRECACHED)) 1228 state |= EXT4_STATE_FLAG_EXT_PRECACHED; 1229 if (ext4_test_inode_state(inode, EXT4_STATE_NEW)) 1230 state |= EXT4_STATE_FLAG_NEW; 1231 if (ext4_test_inode_state(inode, EXT4_STATE_NEWENTRY)) 1232 state |= EXT4_STATE_FLAG_NEWENTRY; 1233 if (ext4_test_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE)) 1234 state |= EXT4_STATE_FLAG_DA_ALLOC_CLOSE; 1235 1236 return put_user(state, (__u32 __user *) arg); 1237 } 1238 1239 case EXT4_IOC_GET_ES_CACHE: 1240 return ext4_ioctl_get_es_cache(filp, arg); 1241 1242 case EXT4_IOC_SHUTDOWN: 1243 return ext4_shutdown(sb, arg); 1244 1245 case FS_IOC_ENABLE_VERITY: 1246 if (!ext4_has_feature_verity(sb)) 1247 return -EOPNOTSUPP; 1248 return fsverity_ioctl_enable(filp, (const void __user *)arg); 1249 1250 case FS_IOC_MEASURE_VERITY: 1251 if (!ext4_has_feature_verity(sb)) 1252 return -EOPNOTSUPP; 1253 return fsverity_ioctl_measure(filp, (void __user *)arg); 1254 1255 case FS_IOC_READ_VERITY_METADATA: 1256 if (!ext4_has_feature_verity(sb)) 1257 return -EOPNOTSUPP; 1258 return fsverity_ioctl_read_metadata(filp, 1259 (const void __user *)arg); 1260 1261 case EXT4_IOC_CHECKPOINT: 1262 return ext4_ioctl_checkpoint(filp, arg); 1263 1264 default: 1265 return -ENOTTY; 1266 } 1267 } 1268 1269 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 1270 { 1271 return __ext4_ioctl(filp, cmd, arg); 1272 } 1273 1274 #ifdef CONFIG_COMPAT 1275 long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 1276 { 1277 /* These are just misnamed, they actually get/put from/to user an int */ 1278 switch (cmd) { 1279 case EXT4_IOC32_GETVERSION: 1280 cmd = EXT4_IOC_GETVERSION; 1281 break; 1282 case EXT4_IOC32_SETVERSION: 1283 cmd = EXT4_IOC_SETVERSION; 1284 break; 1285 case EXT4_IOC32_GROUP_EXTEND: 1286 cmd = EXT4_IOC_GROUP_EXTEND; 1287 break; 1288 case EXT4_IOC32_GETVERSION_OLD: 1289 cmd = EXT4_IOC_GETVERSION_OLD; 1290 break; 1291 case EXT4_IOC32_SETVERSION_OLD: 1292 cmd = EXT4_IOC_SETVERSION_OLD; 1293 break; 1294 case EXT4_IOC32_GETRSVSZ: 1295 cmd = EXT4_IOC_GETRSVSZ; 1296 break; 1297 case EXT4_IOC32_SETRSVSZ: 1298 cmd = EXT4_IOC_SETRSVSZ; 1299 break; 1300 case EXT4_IOC32_GROUP_ADD: { 1301 struct compat_ext4_new_group_input __user *uinput; 1302 struct ext4_new_group_data input; 1303 int err; 1304 1305 uinput = compat_ptr(arg); 1306 err = get_user(input.group, &uinput->group); 1307 err |= get_user(input.block_bitmap, &uinput->block_bitmap); 1308 err |= get_user(input.inode_bitmap, &uinput->inode_bitmap); 1309 err |= get_user(input.inode_table, &uinput->inode_table); 1310 err |= get_user(input.blocks_count, &uinput->blocks_count); 1311 err |= get_user(input.reserved_blocks, 1312 &uinput->reserved_blocks); 1313 if (err) 1314 return -EFAULT; 1315 return ext4_ioctl_group_add(file, &input); 1316 } 1317 case EXT4_IOC_MOVE_EXT: 1318 case EXT4_IOC_RESIZE_FS: 1319 case FITRIM: 1320 case EXT4_IOC_PRECACHE_EXTENTS: 1321 case FS_IOC_SET_ENCRYPTION_POLICY: 1322 case FS_IOC_GET_ENCRYPTION_PWSALT: 1323 case FS_IOC_GET_ENCRYPTION_POLICY: 1324 case FS_IOC_GET_ENCRYPTION_POLICY_EX: 1325 case FS_IOC_ADD_ENCRYPTION_KEY: 1326 case FS_IOC_REMOVE_ENCRYPTION_KEY: 1327 case FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS: 1328 case FS_IOC_GET_ENCRYPTION_KEY_STATUS: 1329 case FS_IOC_GET_ENCRYPTION_NONCE: 1330 case EXT4_IOC_SHUTDOWN: 1331 case FS_IOC_GETFSMAP: 1332 case FS_IOC_ENABLE_VERITY: 1333 case FS_IOC_MEASURE_VERITY: 1334 case FS_IOC_READ_VERITY_METADATA: 1335 case EXT4_IOC_CLEAR_ES_CACHE: 1336 case EXT4_IOC_GETSTATE: 1337 case EXT4_IOC_GET_ES_CACHE: 1338 case EXT4_IOC_CHECKPOINT: 1339 break; 1340 default: 1341 return -ENOIOCTLCMD; 1342 } 1343 return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); 1344 } 1345 #endif 1346