hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/linux/fscrypt.h
....@@ -15,13 +15,12 @@
1515
1616 #include <linux/fs.h>
1717 #include <linux/mm.h>
18
-#include <linux/parser.h>
1918 #include <linux/slab.h>
2019 #include <uapi/linux/fscrypt.h>
2120
2221 #define FS_CRYPTO_BLOCK_SIZE 16
2322
24
-union fscrypt_context;
23
+union fscrypt_policy;
2524 struct fscrypt_info;
2625 struct seq_file;
2726
....@@ -36,7 +35,7 @@
3635 u32 hash;
3736 u32 minor_hash;
3837 struct fscrypt_str crypto_buf;
39
- bool is_ciphertext_name;
38
+ bool is_nokey_name;
4039 };
4140
4241 #define FSTR_INIT(n, l) { .name = n, .len = l }
....@@ -62,23 +61,33 @@
6261 int (*get_context)(struct inode *inode, void *ctx, size_t len);
6362 int (*set_context)(struct inode *inode, const void *ctx, size_t len,
6463 void *fs_data);
65
- const union fscrypt_context *(*get_dummy_context)(
66
- struct super_block *sb);
64
+ const union fscrypt_policy *(*get_dummy_policy)(struct super_block *sb);
6765 bool (*empty_dir)(struct inode *inode);
6866 unsigned int max_namelen;
6967 bool (*has_stable_inodes)(struct super_block *sb);
7068 void (*get_ino_and_lblk_bits)(struct super_block *sb,
7169 int *ino_bits_ret, int *lblk_bits_ret);
72
- bool (*inline_crypt_enabled)(struct super_block *sb);
7370 int (*get_num_devices)(struct super_block *sb);
7471 void (*get_devices)(struct super_block *sb,
7572 struct request_queue **devs);
73
+
74
+ ANDROID_KABI_RESERVE(1);
75
+ ANDROID_KABI_RESERVE(2);
76
+ ANDROID_KABI_RESERVE(3);
77
+ ANDROID_KABI_RESERVE(4);
78
+
79
+ ANDROID_OEM_DATA_ARRAY(1, 4);
7680 };
7781
78
-static inline bool fscrypt_has_encryption_key(const struct inode *inode)
82
+static inline struct fscrypt_info *fscrypt_get_info(const struct inode *inode)
7983 {
80
- /* pairs with cmpxchg_release() in fscrypt_get_encryption_info() */
81
- return READ_ONCE(inode->i_crypt_info) != NULL;
84
+ /*
85
+ * Pairs with the cmpxchg_release() in fscrypt_setup_encryption_info().
86
+ * I.e., another task may publish ->i_crypt_info concurrently, executing
87
+ * a RELEASE barrier. We need to use smp_load_acquire() here to safely
88
+ * ACQUIRE the memory the other task published.
89
+ */
90
+ return smp_load_acquire(&inode->i_crypt_info);
8291 }
8392
8493 /**
....@@ -97,24 +106,16 @@
97106 return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode);
98107 }
99108
100
-static inline const union fscrypt_context *
101
-fscrypt_get_dummy_context(struct super_block *sb)
102
-{
103
- if (!sb->s_cop->get_dummy_context)
104
- return NULL;
105
- return sb->s_cop->get_dummy_context(sb);
106
-}
107
-
108109 /*
109
- * When d_splice_alias() moves a directory's encrypted alias to its decrypted
110
- * alias as a result of the encryption key being added, DCACHE_ENCRYPTED_NAME
111
- * must be cleared. Note that we don't have to support arbitrary moves of this
112
- * flag because fscrypt doesn't allow encrypted aliases to be the source or
113
- * target of a rename().
110
+ * When d_splice_alias() moves a directory's no-key alias to its plaintext alias
111
+ * as a result of the encryption key being added, DCACHE_NOKEY_NAME must be
112
+ * cleared. Note that we don't have to support arbitrary moves of this flag
113
+ * because fscrypt doesn't allow no-key names to be the source or target of a
114
+ * rename().
114115 */
115116 static inline void fscrypt_handle_d_move(struct dentry *dentry)
116117 {
117
- dentry->d_flags &= ~DCACHE_ENCRYPTED_NAME;
118
+ dentry->d_flags &= ~DCACHE_NOKEY_NAME;
118119 }
119120
120121 /**
....@@ -143,7 +144,7 @@
143144 */
144145 static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)
145146 {
146
- return dentry->d_flags & DCACHE_ENCRYPTED_NAME;
147
+ return dentry->d_flags & DCACHE_NOKEY_NAME;
147148 }
148149
149150 /* crypto.c */
....@@ -174,7 +175,6 @@
174175 }
175176
176177 void fscrypt_free_bounce_page(struct page *bounce_page);
177
-int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags);
178178
179179 /* policy.c */
180180 int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg);
....@@ -182,36 +182,33 @@
182182 int fscrypt_ioctl_get_policy_ex(struct file *filp, void __user *arg);
183183 int fscrypt_ioctl_get_nonce(struct file *filp, void __user *arg);
184184 int fscrypt_has_permitted_context(struct inode *parent, struct inode *child);
185
-int fscrypt_inherit_context(struct inode *parent, struct inode *child,
186
- void *fs_data, bool preload);
185
+int fscrypt_set_context(struct inode *inode, void *fs_data);
187186
188
-struct fscrypt_dummy_context {
189
- const union fscrypt_context *ctx;
187
+struct fscrypt_dummy_policy {
188
+ const union fscrypt_policy *policy;
190189 };
191190
192
-int fscrypt_set_test_dummy_encryption(struct super_block *sb,
193
- const substring_t *arg,
194
- struct fscrypt_dummy_context *dummy_ctx);
191
+int fscrypt_set_test_dummy_encryption(struct super_block *sb, const char *arg,
192
+ struct fscrypt_dummy_policy *dummy_policy);
195193 void fscrypt_show_test_dummy_encryption(struct seq_file *seq, char sep,
196194 struct super_block *sb);
197195 static inline void
198
-fscrypt_free_dummy_context(struct fscrypt_dummy_context *dummy_ctx)
196
+fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy)
199197 {
200
- kfree(dummy_ctx->ctx);
201
- dummy_ctx->ctx = NULL;
198
+ kfree(dummy_policy->policy);
199
+ dummy_policy->policy = NULL;
202200 }
203201
204202 /* keyring.c */
205
-void fscrypt_sb_free(struct super_block *sb);
203
+void fscrypt_destroy_keyring(struct super_block *sb);
206204 int fscrypt_ioctl_add_key(struct file *filp, void __user *arg);
207205 int fscrypt_ioctl_remove_key(struct file *filp, void __user *arg);
208206 int fscrypt_ioctl_remove_key_all_users(struct file *filp, void __user *arg);
209207 int fscrypt_ioctl_get_key_status(struct file *filp, void __user *arg);
210
-int fscrypt_register_key_removal_notifier(struct notifier_block *nb);
211
-int fscrypt_unregister_key_removal_notifier(struct notifier_block *nb);
212208
213209 /* keysetup.c */
214
-int fscrypt_get_encryption_info(struct inode *inode);
210
+int fscrypt_prepare_new_inode(struct inode *dir, struct inode *inode,
211
+ bool *encrypt_ret);
215212 void fscrypt_put_encryption_info(struct inode *inode);
216213 void fscrypt_free_inode(struct inode *inode);
217214 int fscrypt_drop_inode(struct inode *inode);
....@@ -225,7 +222,7 @@
225222 kfree(fname->crypto_buf.name);
226223 }
227224
228
-int fscrypt_fname_alloc_buffer(const struct inode *inode, u32 max_encrypted_len,
225
+int fscrypt_fname_alloc_buffer(u32 max_encrypted_len,
229226 struct fscrypt_str *crypto_str);
230227 void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str);
231228 int fscrypt_fname_disk_to_usr(const struct inode *inode,
....@@ -235,6 +232,7 @@
235232 bool fscrypt_match_name(const struct fscrypt_name *fname,
236233 const u8 *de_name, u32 de_name_len);
237234 u64 fscrypt_fname_siphash(const struct inode *dir, const struct qstr *name);
235
+int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags);
238236
239237 /* bio.c */
240238 void fscrypt_decrypt_bio(struct bio *bio);
....@@ -250,34 +248,34 @@
250248 unsigned int flags);
251249 int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
252250 struct fscrypt_name *fname);
251
+int __fscrypt_prepare_readdir(struct inode *dir);
252
+int __fscrypt_prepare_setattr(struct dentry *dentry, struct iattr *attr);
253253 int fscrypt_prepare_setflags(struct inode *inode,
254254 unsigned int oldflags, unsigned int flags);
255
-int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
256
- unsigned int max_len,
257
- struct fscrypt_str *disk_link);
255
+int fscrypt_prepare_symlink(struct inode *dir, const char *target,
256
+ unsigned int len, unsigned int max_len,
257
+ struct fscrypt_str *disk_link);
258258 int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
259259 unsigned int len, struct fscrypt_str *disk_link);
260260 const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
261261 unsigned int max_size,
262262 struct delayed_call *done);
263263 int fscrypt_symlink_getattr(const struct path *path, struct kstat *stat);
264
-
264
+static inline void fscrypt_set_ops(struct super_block *sb,
265
+ const struct fscrypt_operations *s_cop)
266
+{
267
+ sb->s_cop = s_cop;
268
+}
265269 #else /* !CONFIG_FS_ENCRYPTION */
266270
267
-static inline bool fscrypt_has_encryption_key(const struct inode *inode)
271
+static inline struct fscrypt_info *fscrypt_get_info(const struct inode *inode)
268272 {
269
- return false;
273
+ return NULL;
270274 }
271275
272276 static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
273277 {
274278 return false;
275
-}
276
-
277
-static inline const union fscrypt_context *
278
-fscrypt_get_dummy_context(struct super_block *sb)
279
-{
280
- return NULL;
281279 }
282280
283281 static inline void fscrypt_handle_d_move(struct dentry *dentry)
....@@ -370,14 +368,12 @@
370368 return 0;
371369 }
372370
373
-static inline int fscrypt_inherit_context(struct inode *parent,
374
- struct inode *child,
375
- void *fs_data, bool preload)
371
+static inline int fscrypt_set_context(struct inode *inode, void *fs_data)
376372 {
377373 return -EOPNOTSUPP;
378374 }
379375
380
-struct fscrypt_dummy_context {
376
+struct fscrypt_dummy_policy {
381377 };
382378
383379 static inline void fscrypt_show_test_dummy_encryption(struct seq_file *seq,
....@@ -387,12 +383,12 @@
387383 }
388384
389385 static inline void
390
-fscrypt_free_dummy_context(struct fscrypt_dummy_context *dummy_ctx)
386
+fscrypt_free_dummy_policy(struct fscrypt_dummy_policy *dummy_policy)
391387 {
392388 }
393389
394390 /* keyring.c */
395
-static inline void fscrypt_sb_free(struct super_block *sb)
391
+static inline void fscrypt_destroy_keyring(struct super_block *sb)
396392 {
397393 }
398394
....@@ -418,22 +414,15 @@
418414 return -EOPNOTSUPP;
419415 }
420416
421
-static inline int fscrypt_register_key_removal_notifier(
422
- struct notifier_block *nb)
423
-{
424
- return 0;
425
-}
426
-
427
-static inline int fscrypt_unregister_key_removal_notifier(
428
- struct notifier_block *nb)
429
-{
430
- return 0;
431
-}
432
-
433417 /* keysetup.c */
434
-static inline int fscrypt_get_encryption_info(struct inode *inode)
418
+
419
+static inline int fscrypt_prepare_new_inode(struct inode *dir,
420
+ struct inode *inode,
421
+ bool *encrypt_ret)
435422 {
436
- return -EOPNOTSUPP;
423
+ if (IS_ENCRYPTED(dir))
424
+ return -EOPNOTSUPP;
425
+ return 0;
437426 }
438427
439428 static inline void fscrypt_put_encryption_info(struct inode *inode)
....@@ -470,8 +459,7 @@
470459 return;
471460 }
472461
473
-static inline int fscrypt_fname_alloc_buffer(const struct inode *inode,
474
- u32 max_encrypted_len,
462
+static inline int fscrypt_fname_alloc_buffer(u32 max_encrypted_len,
475463 struct fscrypt_str *crypto_str)
476464 {
477465 return -EOPNOTSUPP;
....@@ -504,6 +492,12 @@
504492 {
505493 WARN_ON_ONCE(1);
506494 return 0;
495
+}
496
+
497
+static inline int fscrypt_d_revalidate(struct dentry *dentry,
498
+ unsigned int flags)
499
+{
500
+ return 1;
507501 }
508502
509503 /* bio.c */
....@@ -548,6 +542,17 @@
548542 return -EOPNOTSUPP;
549543 }
550544
545
+static inline int __fscrypt_prepare_readdir(struct inode *dir)
546
+{
547
+ return -EOPNOTSUPP;
548
+}
549
+
550
+static inline int __fscrypt_prepare_setattr(struct dentry *dentry,
551
+ struct iattr *attr)
552
+{
553
+ return -EOPNOTSUPP;
554
+}
555
+
551556 static inline int fscrypt_prepare_setflags(struct inode *inode,
552557 unsigned int oldflags,
553558 unsigned int flags)
....@@ -555,14 +560,20 @@
555560 return 0;
556561 }
557562
558
-static inline int __fscrypt_prepare_symlink(struct inode *dir,
559
- unsigned int len,
560
- unsigned int max_len,
561
- struct fscrypt_str *disk_link)
563
+static inline int fscrypt_prepare_symlink(struct inode *dir,
564
+ const char *target,
565
+ unsigned int len,
566
+ unsigned int max_len,
567
+ struct fscrypt_str *disk_link)
562568 {
563
- return -EOPNOTSUPP;
569
+ if (IS_ENCRYPTED(dir))
570
+ return -EOPNOTSUPP;
571
+ disk_link->name = (unsigned char *)target;
572
+ disk_link->len = len + 1;
573
+ if (disk_link->len > max_len)
574
+ return -ENAMETOOLONG;
575
+ return 0;
564576 }
565
-
566577
567578 static inline int __fscrypt_encrypt_symlink(struct inode *inode,
568579 const char *target,
....@@ -586,42 +597,41 @@
586597 return -EOPNOTSUPP;
587598 }
588599
600
+static inline void fscrypt_set_ops(struct super_block *sb,
601
+ const struct fscrypt_operations *s_cop)
602
+{
603
+}
604
+
589605 #endif /* !CONFIG_FS_ENCRYPTION */
590606
591607 /* inline_crypt.c */
592608 #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
593
-extern bool fscrypt_inode_uses_inline_crypto(const struct inode *inode);
594609
595
-extern bool fscrypt_inode_uses_fs_layer_crypto(const struct inode *inode);
610
+bool __fscrypt_inode_uses_inline_crypto(const struct inode *inode);
596611
597
-extern void fscrypt_set_bio_crypt_ctx(struct bio *bio,
598
- const struct inode *inode,
599
- u64 first_lblk, gfp_t gfp_mask);
612
+void fscrypt_set_bio_crypt_ctx(struct bio *bio,
613
+ const struct inode *inode, u64 first_lblk,
614
+ gfp_t gfp_mask);
600615
601
-extern void fscrypt_set_bio_crypt_ctx_bh(struct bio *bio,
602
- const struct buffer_head *first_bh,
603
- gfp_t gfp_mask);
616
+void fscrypt_set_bio_crypt_ctx_bh(struct bio *bio,
617
+ const struct buffer_head *first_bh,
618
+ gfp_t gfp_mask);
604619
605
-extern bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,
606
- u64 next_lblk);
620
+bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,
621
+ u64 next_lblk);
607622
608
-extern bool fscrypt_mergeable_bio_bh(struct bio *bio,
609
- const struct buffer_head *next_bh);
623
+bool fscrypt_mergeable_bio_bh(struct bio *bio,
624
+ const struct buffer_head *next_bh);
610625
611626 bool fscrypt_dio_supported(struct kiocb *iocb, struct iov_iter *iter);
612627
613
-int fscrypt_limit_dio_pages(const struct inode *inode, loff_t pos,
614
- int nr_pages);
628
+u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks);
615629
616630 #else /* CONFIG_FS_ENCRYPTION_INLINE_CRYPT */
617
-static inline bool fscrypt_inode_uses_inline_crypto(const struct inode *inode)
631
+
632
+static inline bool __fscrypt_inode_uses_inline_crypto(const struct inode *inode)
618633 {
619634 return false;
620
-}
621
-
622
-static inline bool fscrypt_inode_uses_fs_layer_crypto(const struct inode *inode)
623
-{
624
- return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode);
625635 }
626636
627637 static inline void fscrypt_set_bio_crypt_ctx(struct bio *bio,
....@@ -654,10 +664,10 @@
654664 return !fscrypt_needs_contents_encryption(inode);
655665 }
656666
657
-static inline int fscrypt_limit_dio_pages(const struct inode *inode, loff_t pos,
658
- int nr_pages)
667
+static inline u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk,
668
+ u64 nr_blocks)
659669 {
660
- return nr_pages;
670
+ return nr_blocks;
661671 }
662672 #endif /* !CONFIG_FS_ENCRYPTION_INLINE_CRYPT */
663673
....@@ -676,29 +686,47 @@
676686 #endif
677687
678688 /**
679
- * fscrypt_require_key() - require an inode's encryption key
680
- * @inode: the inode we need the key for
689
+ * fscrypt_inode_uses_inline_crypto() - test whether an inode uses inline
690
+ * encryption
691
+ * @inode: an inode. If encrypted, its key must be set up.
681692 *
682
- * If the inode is encrypted, set up its encryption key if not already done.
683
- * Then require that the key be present and return -ENOKEY otherwise.
684
- *
685
- * No locks are needed, and the key will live as long as the struct inode --- so
686
- * it won't go away from under you.
687
- *
688
- * Return: 0 on success, -ENOKEY if the key is missing, or another -errno code
689
- * if a problem occurred while setting up the encryption key.
693
+ * Return: true if the inode requires file contents encryption and if the
694
+ * encryption should be done in the block layer via blk-crypto rather
695
+ * than in the filesystem layer.
690696 */
691
-static inline int fscrypt_require_key(struct inode *inode)
697
+static inline bool fscrypt_inode_uses_inline_crypto(const struct inode *inode)
692698 {
693
- if (IS_ENCRYPTED(inode)) {
694
- int err = fscrypt_get_encryption_info(inode);
699
+ return fscrypt_needs_contents_encryption(inode) &&
700
+ __fscrypt_inode_uses_inline_crypto(inode);
701
+}
695702
696
- if (err)
697
- return err;
698
- if (!fscrypt_has_encryption_key(inode))
699
- return -ENOKEY;
700
- }
701
- return 0;
703
+/**
704
+ * fscrypt_inode_uses_fs_layer_crypto() - test whether an inode uses fs-layer
705
+ * encryption
706
+ * @inode: an inode. If encrypted, its key must be set up.
707
+ *
708
+ * Return: true if the inode requires file contents encryption and if the
709
+ * encryption should be done in the filesystem layer rather than in the
710
+ * block layer via blk-crypto.
711
+ */
712
+static inline bool fscrypt_inode_uses_fs_layer_crypto(const struct inode *inode)
713
+{
714
+ return fscrypt_needs_contents_encryption(inode) &&
715
+ !__fscrypt_inode_uses_inline_crypto(inode);
716
+}
717
+
718
+/**
719
+ * fscrypt_has_encryption_key() - check whether an inode has had its key set up
720
+ * @inode: the inode to check
721
+ *
722
+ * Return: %true if the inode has had its encryption key set up, else %false.
723
+ *
724
+ * Usually this should be preceded by fscrypt_get_encryption_info() to try to
725
+ * set up the key first.
726
+ */
727
+static inline bool fscrypt_has_encryption_key(const struct inode *inode)
728
+{
729
+ return fscrypt_get_info(inode) != NULL;
702730 }
703731
704732 /**
....@@ -710,8 +738,7 @@
710738 *
711739 * A new link can only be added to an encrypted directory if the directory's
712740 * encryption key is available --- since otherwise we'd have no way to encrypt
713
- * the filename. Therefore, we first set up the directory's encryption key (if
714
- * not already done) and return an error if it's unavailable.
741
+ * the filename.
715742 *
716743 * We also verify that the link will not violate the constraint that all files
717744 * in an encrypted directory tree use the same encryption policy.
....@@ -771,18 +798,20 @@
771798 * @fname: (output) the name to use to search the on-disk directory
772799 *
773800 * Prepare for ->lookup() in a directory which may be encrypted by determining
774
- * the name that will actually be used to search the directory on-disk. Lookups
775
- * can be done with or without the directory's encryption key; without the key,
776
- * filenames are presented in encrypted form. Therefore, we'll try to set up
777
- * the directory's encryption key, but even without it the lookup can continue.
801
+ * the name that will actually be used to search the directory on-disk. If the
802
+ * directory's encryption policy is supported by this kernel and its encryption
803
+ * key is available, then the lookup is assumed to be by plaintext name;
804
+ * otherwise, it is assumed to be by no-key name.
778805 *
779
- * After calling this function, a filesystem should ensure that it's dentry
780
- * operations contain fscrypt_d_revalidate if DCACHE_ENCRYPTED_NAME was set,
781
- * so that the dentry can be invalidated if the key is later added.
806
+ * This will set DCACHE_NOKEY_NAME on the dentry if the lookup is by no-key
807
+ * name. In this case the filesystem must assign the dentry a dentry_operations
808
+ * which contains fscrypt_d_revalidate (or contains a d_revalidate method that
809
+ * calls fscrypt_d_revalidate), so that the dentry will be invalidated if the
810
+ * directory's encryption key is later added.
782811 *
783
- * Return: 0 on success; -ENOENT if key is unavailable but the filename isn't a
784
- * correctly formed encoded ciphertext name, so a negative dentry should be
785
- * created; or another -errno code.
812
+ * Return: 0 on success; -ENOENT if the directory's key is unavailable but the
813
+ * filename isn't a valid no-key name, so a negative dentry should be created;
814
+ * or another -errno code.
786815 */
787816 static inline int fscrypt_prepare_lookup(struct inode *dir,
788817 struct dentry *dentry,
....@@ -795,6 +824,26 @@
795824 fname->usr_fname = &dentry->d_name;
796825 fname->disk_name.name = (unsigned char *)dentry->d_name.name;
797826 fname->disk_name.len = dentry->d_name.len;
827
+ return 0;
828
+}
829
+
830
+/**
831
+ * fscrypt_prepare_readdir() - prepare to read a possibly-encrypted directory
832
+ * @dir: the directory inode
833
+ *
834
+ * If the directory is encrypted and it doesn't already have its encryption key
835
+ * set up, try to set it up so that the filenames will be listed in plaintext
836
+ * form rather than in no-key form.
837
+ *
838
+ * Return: 0 on success; -errno on error. Note that the encryption key being
839
+ * unavailable is not considered an error. It is also not an error if
840
+ * the encryption policy is unsupported by this kernel; that is treated
841
+ * like the key being unavailable, so that files can still be deleted.
842
+ */
843
+static inline int fscrypt_prepare_readdir(struct inode *dir)
844
+{
845
+ if (IS_ENCRYPTED(dir))
846
+ return __fscrypt_prepare_readdir(dir);
798847 return 0;
799848 }
800849
....@@ -819,47 +868,8 @@
819868 static inline int fscrypt_prepare_setattr(struct dentry *dentry,
820869 struct iattr *attr)
821870 {
822
- if (attr->ia_valid & ATTR_SIZE)
823
- return fscrypt_require_key(d_inode(dentry));
824
- return 0;
825
-}
826
-
827
-/**
828
- * fscrypt_prepare_symlink() - prepare to create a possibly-encrypted symlink
829
- * @dir: directory in which the symlink is being created
830
- * @target: plaintext symlink target
831
- * @len: length of @target excluding null terminator
832
- * @max_len: space the filesystem has available to store the symlink target
833
- * @disk_link: (out) the on-disk symlink target being prepared
834
- *
835
- * This function computes the size the symlink target will require on-disk,
836
- * stores it in @disk_link->len, and validates it against @max_len. An
837
- * encrypted symlink may be longer than the original.
838
- *
839
- * Additionally, @disk_link->name is set to @target if the symlink will be
840
- * unencrypted, but left NULL if the symlink will be encrypted. For encrypted
841
- * symlinks, the filesystem must call fscrypt_encrypt_symlink() to create the
842
- * on-disk target later. (The reason for the two-step process is that some
843
- * filesystems need to know the size of the symlink target before creating the
844
- * inode, e.g. to determine whether it will be a "fast" or "slow" symlink.)
845
- *
846
- * Return: 0 on success, -ENAMETOOLONG if the symlink target is too long,
847
- * -ENOKEY if the encryption key is missing, or another -errno code if a problem
848
- * occurred while setting up the encryption key.
849
- */
850
-static inline int fscrypt_prepare_symlink(struct inode *dir,
851
- const char *target,
852
- unsigned int len,
853
- unsigned int max_len,
854
- struct fscrypt_str *disk_link)
855
-{
856
- if (IS_ENCRYPTED(dir) || fscrypt_get_dummy_context(dir->i_sb) != NULL)
857
- return __fscrypt_prepare_symlink(dir, len, max_len, disk_link);
858
-
859
- disk_link->name = (unsigned char *)target;
860
- disk_link->len = len + 1;
861
- if (disk_link->len > max_len)
862
- return -ENAMETOOLONG;
871
+ if (IS_ENCRYPTED(d_inode(dentry)))
872
+ return __fscrypt_prepare_setattr(dentry, attr);
863873 return 0;
864874 }
865875