| .. | .. |
|---|
| 35 | 35 | static int ext4_dx_readdir(struct file *, struct dir_context *); |
|---|
| 36 | 36 | |
|---|
| 37 | 37 | /** |
|---|
| 38 | + * is_dx_dir() - check if a directory is using htree indexing |
|---|
| 39 | + * @inode: directory inode |
|---|
| 40 | + * |
|---|
| 38 | 41 | * Check if the given dir-inode refers to an htree-indexed directory |
|---|
| 39 | 42 | * (or a directory which could potentially get converted to use htree |
|---|
| 40 | 43 | * indexing). |
|---|
| .. | .. |
|---|
| 97 | 100 | else if (unlikely(rlen < ext4_dir_rec_len(de->name_len, |
|---|
| 98 | 101 | fake ? NULL : dir))) |
|---|
| 99 | 102 | error_msg = "rec_len is too small for name_len"; |
|---|
| 100 | | - else if (unlikely(((char *) de - buf) + rlen > size)) |
|---|
| 103 | + else if (unlikely(next_offset > size)) |
|---|
| 101 | 104 | error_msg = "directory entry overrun"; |
|---|
| 102 | 105 | else if (unlikely(next_offset > size - ext4_dir_rec_len(1, |
|---|
| 103 | 106 | next_fake ? NULL : dir) && |
|---|
| .. | .. |
|---|
| 136 | 139 | struct buffer_head *bh = NULL; |
|---|
| 137 | 140 | struct fscrypt_str fstr = FSTR_INIT(NULL, 0); |
|---|
| 138 | 141 | |
|---|
| 139 | | - if (IS_ENCRYPTED(inode)) { |
|---|
| 140 | | - err = fscrypt_get_encryption_info(inode); |
|---|
| 141 | | - if (err) |
|---|
| 142 | | - return err; |
|---|
| 143 | | - } |
|---|
| 142 | + err = fscrypt_prepare_readdir(inode); |
|---|
| 143 | + if (err) |
|---|
| 144 | + return err; |
|---|
| 144 | 145 | |
|---|
| 145 | 146 | if (is_dx_dir(inode)) { |
|---|
| 146 | 147 | err = ext4_dx_readdir(file, ctx); |
|---|
| .. | .. |
|---|
| 166 | 167 | } |
|---|
| 167 | 168 | |
|---|
| 168 | 169 | if (IS_ENCRYPTED(inode)) { |
|---|
| 169 | | - err = fscrypt_fname_alloc_buffer(inode, EXT4_NAME_LEN, &fstr); |
|---|
| 170 | + err = fscrypt_fname_alloc_buffer(EXT4_NAME_LEN, &fstr); |
|---|
| 170 | 171 | if (err < 0) |
|---|
| 171 | 172 | return err; |
|---|
| 172 | 173 | } |
|---|
| .. | .. |
|---|
| 218 | 219 | |
|---|
| 219 | 220 | /* Check the checksum */ |
|---|
| 220 | 221 | if (!buffer_verified(bh) && |
|---|
| 221 | | - !ext4_dirent_csum_verify(inode, |
|---|
| 222 | | - (struct ext4_dir_entry *)bh->b_data)) { |
|---|
| 222 | + !ext4_dirblock_csum_verify(inode, bh)) { |
|---|
| 223 | 223 | EXT4_ERROR_FILE(file, 0, "directory fails checksum " |
|---|
| 224 | 224 | "at offset %llu", |
|---|
| 225 | 225 | (unsigned long long)ctx->pos); |
|---|
| .. | .. |
|---|
| 414 | 414 | __u32 inode; |
|---|
| 415 | 415 | __u8 name_len; |
|---|
| 416 | 416 | __u8 file_type; |
|---|
| 417 | | - char name[0]; |
|---|
| 417 | + char name[]; |
|---|
| 418 | 418 | }; |
|---|
| 419 | 419 | |
|---|
| 420 | 420 | /* |
|---|
| .. | .. |
|---|
| 486 | 486 | new_fn->name_len = ent_name->len; |
|---|
| 487 | 487 | new_fn->file_type = dirent->file_type; |
|---|
| 488 | 488 | memcpy(new_fn->name, ent_name->name, ent_name->len); |
|---|
| 489 | | - new_fn->name[ent_name->len] = 0; |
|---|
| 490 | 489 | |
|---|
| 491 | 490 | while (*p) { |
|---|
| 492 | 491 | parent = *p; |
|---|
| .. | .. |
|---|
| 639 | 638 | return ret < 0 ? ret : 0; |
|---|
| 640 | 639 | } |
|---|
| 641 | 640 | |
|---|
| 642 | | -static int ext4_dir_open(struct inode * inode, struct file * filp) |
|---|
| 643 | | -{ |
|---|
| 644 | | - if (IS_ENCRYPTED(inode)) |
|---|
| 645 | | - return fscrypt_get_encryption_info(inode) ? -EACCES : 0; |
|---|
| 646 | | - return 0; |
|---|
| 647 | | -} |
|---|
| 648 | | - |
|---|
| 649 | 641 | static int ext4_release_dir(struct inode *inode, struct file *filp) |
|---|
| 650 | 642 | { |
|---|
| 651 | 643 | if (filp->private_data) |
|---|
| .. | .. |
|---|
| 687 | 679 | .compat_ioctl = ext4_compat_ioctl, |
|---|
| 688 | 680 | #endif |
|---|
| 689 | 681 | .fsync = ext4_sync_file, |
|---|
| 690 | | - .open = ext4_dir_open, |
|---|
| 691 | 682 | .release = ext4_release_dir, |
|---|
| 692 | 683 | }; |
|---|