Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
ac27a0ec | 2 | /* |
617ba13b | 3 | * linux/fs/ext4/symlink.c |
ac27a0ec DK |
4 | * |
5 | * Only fast symlinks left here - the rest is done by generic code. AV, 1999 | |
6 | * | |
7 | * Copyright (C) 1992, 1993, 1994, 1995 | |
8 | * Remy Card (card@masi.ibp.fr) | |
9 | * Laboratoire MASI - Institut Blaise Pascal | |
10 | * Universite Pierre et Marie Curie (Paris VI) | |
11 | * | |
12 | * from | |
13 | * | |
14 | * linux/fs/minix/symlink.c | |
15 | * | |
16 | * Copyright (C) 1991, 1992 Linus Torvalds | |
17 | * | |
617ba13b | 18 | * ext4 symlink handling code |
ac27a0ec DK |
19 | */ |
20 | ||
21 | #include <linux/fs.h> | |
ac27a0ec | 22 | #include <linux/namei.h> |
3dcf5451 | 23 | #include "ext4.h" |
ac27a0ec DK |
24 | #include "xattr.h" |
25 | ||
6b255391 | 26 | static const char *ext4_encrypted_get_link(struct dentry *dentry, |
fceef393 AV |
27 | struct inode *inode, |
28 | struct delayed_call *done) | |
f348c252 TT |
29 | { |
30 | struct page *cpage = NULL; | |
31 | char *caddr, *paddr = NULL; | |
a7550b30 JK |
32 | struct fscrypt_str cstr, pstr; |
33 | struct fscrypt_symlink_data *sd; | |
f348c252 | 34 | int res; |
a7550b30 | 35 | u32 max_size = inode->i_sb->s_blocksize; |
f348c252 | 36 | |
6b255391 AV |
37 | if (!dentry) |
38 | return ERR_PTR(-ECHILD); | |
39 | ||
a7550b30 | 40 | res = fscrypt_get_encryption_info(inode); |
b7236e21 TT |
41 | if (res) |
42 | return ERR_PTR(res); | |
f348c252 TT |
43 | |
44 | if (ext4_inode_is_fast_symlink(inode)) { | |
9ec3a646 LT |
45 | caddr = (char *) EXT4_I(inode)->i_data; |
46 | max_size = sizeof(EXT4_I(inode)->i_data); | |
f348c252 TT |
47 | } else { |
48 | cpage = read_mapping_page(inode->i_mapping, 0, NULL); | |
b7236e21 | 49 | if (IS_ERR(cpage)) |
680baacb | 50 | return ERR_CAST(cpage); |
21fc61c7 | 51 | caddr = page_address(cpage); |
f348c252 TT |
52 | } |
53 | ||
54 | /* Symlink is encrypted */ | |
a7550b30 | 55 | sd = (struct fscrypt_symlink_data *)caddr; |
f348c252 | 56 | cstr.name = sd->encrypted_path; |
5a1c7f47 | 57 | cstr.len = le16_to_cpu(sd->len); |
a7550b30 | 58 | if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) { |
f348c252 | 59 | /* Symlink data on the disk is corrupted */ |
6a797d27 | 60 | res = -EFSCORRUPTED; |
f348c252 TT |
61 | goto errout; |
62 | } | |
a7550b30 JK |
63 | |
64 | res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr); | |
65 | if (res) | |
f348c252 | 66 | goto errout; |
dcce7a46 | 67 | paddr = pstr.name; |
a7550b30 JK |
68 | |
69 | res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr); | |
ef1eb3aa | 70 | if (res) |
f348c252 | 71 | goto errout; |
a7550b30 | 72 | |
f348c252 | 73 | /* Null-terminate the name */ |
ef1eb3aa | 74 | paddr[pstr.len] = '\0'; |
21fc61c7 | 75 | if (cpage) |
09cbfeaf | 76 | put_page(cpage); |
fceef393 AV |
77 | set_delayed_call(done, kfree_link, paddr); |
78 | return paddr; | |
f348c252 | 79 | errout: |
21fc61c7 | 80 | if (cpage) |
09cbfeaf | 81 | put_page(cpage); |
f348c252 TT |
82 | kfree(paddr); |
83 | return ERR_PTR(res); | |
84 | } | |
85 | ||
a7a67e8a | 86 | const struct inode_operations ext4_encrypted_symlink_inode_operations = { |
6b255391 | 87 | .get_link = ext4_encrypted_get_link, |
a7a67e8a | 88 | .setattr = ext4_setattr, |
99652ea5 | 89 | .getattr = ext4_getattr, |
a7a67e8a | 90 | .listxattr = ext4_listxattr, |
a7a67e8a | 91 | }; |
f348c252 | 92 | |
754661f1 | 93 | const struct inode_operations ext4_symlink_inode_operations = { |
6b255391 | 94 | .get_link = page_get_link, |
256a4535 | 95 | .setattr = ext4_setattr, |
99652ea5 | 96 | .getattr = ext4_getattr, |
617ba13b | 97 | .listxattr = ext4_listxattr, |
ac27a0ec DK |
98 | }; |
99 | ||
754661f1 | 100 | const struct inode_operations ext4_fast_symlink_inode_operations = { |
6b255391 | 101 | .get_link = simple_get_link, |
256a4535 | 102 | .setattr = ext4_setattr, |
99652ea5 | 103 | .getattr = ext4_getattr, |
617ba13b | 104 | .listxattr = ext4_listxattr, |
ac27a0ec | 105 | }; |