History

fscrypt: remove filesystem specific build config option

In order to have a common code base for fscrypt "post read" processing for all filesystems which support encryption, this commit removes filesystem specific build config option (e.g. CONFIG_EXT4_FS_ENCRYPTION) and replaces it with a build option (i.e. CONFIG_FS_ENCRYPTION) whose value affects all the filesystems making use of fscrypt.

Chandan Rajendra committed 7 years ago

Commit 643fa961 parent 62230e031 files · +460 −535Browse files

Showing the changes to include/linux (4 of 31 files). Show all

Unified · Split

4 files
  1. include/linux/fs.h +2 −2
  2. include/linux/fscrypt.h +408 −8
  3. include/linux/fscrypt_notsupp.h +0 −231
  4. include/linux/fscrypt_supp.h +0 −204
include/linux/fs.h+2−2
@@ -698,7 +698,7 @@ struct inode { · 697 unmodified lines
698 struct fsnotify_mark_connector __rcu *i_fsnotify_marks;698 struct fsnotify_mark_connector __rcu *i_fsnotify_marks;
699#endif699#endif
700 700
701#if IS_ENABLED(CONFIG_FS_ENCRYPTION)701#ifdef CONFIG_FS_ENCRYPTION
702 struct fscrypt_info *i_crypt_info;702 struct fscrypt_info *i_crypt_info;
703#endif703#endif
704 704
@@ -1403,7 +1403,7 @@ struct super_block { · 698 unmodified lines
1403 void *s_security;1403 void *s_security;
1404#endif1404#endif
1405 const struct xattr_handler **s_xattr;1405 const struct xattr_handler **s_xattr;
1406#if IS_ENABLED(CONFIG_FS_ENCRYPTION)1406#ifdef CONFIG_FS_ENCRYPTION
1407 const struct fscrypt_operations *s_cop;1407 const struct fscrypt_operations *s_cop;
1408#endif1408#endif
1409 struct hlist_bl_head s_roots; /* alternate root dentries for NFS */1409 struct hlist_bl_head s_roots; /* alternate root dentries for NFS */
include/linux/fscrypt.h+408−8
@@ -2,9 +2,8 @@ · 1 unmodified line
2/*2/*
3 * fscrypt.h: declarations for per-file encryption3 * fscrypt.h: declarations for per-file encryption
4 *4 *
5 * Filesystems that implement per-file encryption include this header5 * Filesystems that implement per-file encryption must include this header
6 * file with the __FS_HAS_ENCRYPTION set according to whether that filesystem6 * file.
7 * is being built with encryption support or not.
8 *7 *
9 * Copyright (C) 2015, Google, Inc.8 * Copyright (C) 2015, Google, Inc.
10 *9 *
@@ -15,6 +14,8 @@ · 4 unmodified lines
15#define _LINUX_FSCRYPT_H14#define _LINUX_FSCRYPT_H
16 15
17#include <linux/fs.h>16#include <linux/fs.h>
17#include <linux/mm.h>
18#include <linux/slab.h>
18 19
19#define FS_CRYPTO_BLOCK_SIZE 1620#define FS_CRYPTO_BLOCK_SIZE 16
20 21
@@ -42,11 +43,410 @@ struct fscrypt_name { · 21 unmodified lines
42/* Maximum value for the third parameter of fscrypt_operations.set_context(). */43/* Maximum value for the third parameter of fscrypt_operations.set_context(). */
43#define FSCRYPT_SET_CONTEXT_MAX_SIZE 2844#define FSCRYPT_SET_CONTEXT_MAX_SIZE 28
44 45
45#if __FS_HAS_ENCRYPTION46#ifdef CONFIG_FS_ENCRYPTION
46#include <linux/fscrypt_supp.h>47/*
47#else48 * fscrypt superblock flags
48#include <linux/fscrypt_notsupp.h>49 */
49#endif50#define FS_CFLG_OWN_PAGES (1U << 1)
51
52/*
53 * crypto operations for filesystems
54 */
55struct fscrypt_operations {
56 unsigned int flags;
57 const char *key_prefix;
58 int (*get_context)(struct inode *, void *, size_t);
59 int (*set_context)(struct inode *, const void *, size_t, void *);
60 bool (*dummy_context)(struct inode *);
61 bool (*empty_dir)(struct inode *);
62 unsigned int max_namelen;
63};
64
65struct fscrypt_ctx {
66 union {
67 struct {
68 struct page *bounce_page; /* Ciphertext page */
69 struct page *control_page; /* Original page */
70 } w;
71 struct {
72 struct bio *bio;
73 struct work_struct work;
74 } r;
75 struct list_head free_list; /* Free list */
76 };
77 u8 flags; /* Flags */
78};
79
80static inline bool fscrypt_has_encryption_key(const struct inode *inode)
81{
82 return (inode->i_crypt_info != NULL);
83}
84
85static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
86{
87 return inode->i_sb->s_cop->dummy_context &&
88 inode->i_sb->s_cop->dummy_context(inode);
89}
90
91/* crypto.c */
92extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
93extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t);
94extern void fscrypt_release_ctx(struct fscrypt_ctx *);
95extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
96 unsigned int, unsigned int,
97 u64, gfp_t);
98extern int fscrypt_decrypt_page(const struct inode *, struct page *, unsigned int,
99 unsigned int, u64);
100
101static inline struct page *fscrypt_control_page(struct page *page)
102{
103 return ((struct fscrypt_ctx *)page_private(page))->w.control_page;
104}
105
106extern void fscrypt_restore_control_page(struct page *);
107
108/* policy.c */
109extern int fscrypt_ioctl_set_policy(struct file *, const void __user *);
110extern int fscrypt_ioctl_get_policy(struct file *, void __user *);
111extern int fscrypt_has_permitted_context(struct inode *, struct inode *);
112extern int fscrypt_inherit_context(struct inode *, struct inode *,
113 void *, bool);
114/* keyinfo.c */
115extern int fscrypt_get_encryption_info(struct inode *);
116extern void fscrypt_put_encryption_info(struct inode *);
117
118/* fname.c */
119extern int fscrypt_setup_filename(struct inode *, const struct qstr *,
120 int lookup, struct fscrypt_name *);
121
122static inline void fscrypt_free_filename(struct fscrypt_name *fname)
123{
124 kfree(fname->crypto_buf.name);
125}
126
127extern int fscrypt_fname_alloc_buffer(const struct inode *, u32,
128 struct fscrypt_str *);
129extern void fscrypt_fname_free_buffer(struct fscrypt_str *);
130extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32,
131 const struct fscrypt_str *, struct fscrypt_str *);
132
133#define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE 32
134
135/* Extracts the second-to-last ciphertext block; see explanation below */
136#define FSCRYPT_FNAME_DIGEST(name, len) \
137 ((name) + round_down((len) - FS_CRYPTO_BLOCK_SIZE - 1, \
138 FS_CRYPTO_BLOCK_SIZE))
139
140#define FSCRYPT_FNAME_DIGEST_SIZE FS_CRYPTO_BLOCK_SIZE
141
142/**
143 * fscrypt_digested_name - alternate identifier for an on-disk filename
144 *
145 * When userspace lists an encrypted directory without access to the key,
146 * filenames whose ciphertext is longer than FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE
147 * bytes are shown in this abbreviated form (base64-encoded) rather than as the
148 * full ciphertext (base64-encoded). This is necessary to allow supporting
149 * filenames up to NAME_MAX bytes, since base64 encoding expands the length.
150 *
151 * To make it possible for filesystems to still find the correct directory entry
152 * despite not knowing the full on-disk name, we encode any filesystem-specific
153 * 'hash' and/or 'minor_hash' which the filesystem may need for its lookups,
154 * followed by the second-to-last ciphertext block of the filename. Due to the
155 * use of the CBC-CTS encryption mode, the second-to-last ciphertext block
156 * depends on the full plaintext. (Note that ciphertext stealing causes the
157 * last two blocks to appear "flipped".) This makes accidental collisions very
158 * unlikely: just a 1 in 2^128 chance for two filenames to collide even if they
159 * share the same filesystem-specific hashes.
160 *
161 * However, this scheme isn't immune to intentional collisions, which can be
162 * created by anyone able to create arbitrary plaintext filenames and view them
163 * without the key. Making the "digest" be a real cryptographic hash like
164 * SHA-256 over the full ciphertext would prevent this, although it would be
165 * less efficient and harder to implement, especially since the filesystem would
166 * need to calculate it for each directory entry examined during a search.
167 */
168struct fscrypt_digested_name {
169 u32 hash;
170 u32 minor_hash;
171 u8 digest[FSCRYPT_FNAME_DIGEST_SIZE];
172};
173
174/**
175 * fscrypt_match_name() - test whether the given name matches a directory entry
176 * @fname: the name being searched for
177 * @de_name: the name from the directory entry
178 * @de_name_len: the length of @de_name in bytes
179 *
180 * Normally @fname->disk_name will be set, and in that case we simply compare
181 * that to the name stored in the directory entry. The only exception is that
182 * if we don't have the key for an encrypted directory and a filename in it is
183 * very long, then we won't have the full disk_name and we'll instead need to
184 * match against the fscrypt_digested_name.
185 *
186 * Return: %true if the name matches, otherwise %false.
187 */
188static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
189 const u8 *de_name, u32 de_name_len)
190{
191 if (unlikely(!fname->disk_name.name)) {
192 const struct fscrypt_digested_name *n =
193 (const void *)fname->crypto_buf.name;
194 if (WARN_ON_ONCE(fname->usr_fname->name[0] != '_'))
195 return false;
196 if (de_name_len <= FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE)
197 return false;
198 return !memcmp(FSCRYPT_FNAME_DIGEST(de_name, de_name_len),
199 n->digest, FSCRYPT_FNAME_DIGEST_SIZE);
200 }
201
202 if (de_name_len != fname->disk_name.len)
203 return false;
204 return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
205}
206
207/* bio.c */
208extern void fscrypt_decrypt_bio(struct bio *);
209extern void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
210 struct bio *bio);
211extern void fscrypt_pullback_bio_page(struct page **, bool);
212extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,
213 unsigned int);
214
215/* hooks.c */
216extern int fscrypt_file_open(struct inode *inode, struct file *filp);
217extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir);
218extern int __fscrypt_prepare_rename(struct inode *old_dir,
219 struct dentry *old_dentry,
220 struct inode *new_dir,
221 struct dentry *new_dentry,
222 unsigned int flags);
223extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry);
224extern int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
225 unsigned int max_len,
226 struct fscrypt_str *disk_link);
227extern int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
228 unsigned int len,
229 struct fscrypt_str *disk_link);
230extern const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
231 unsigned int max_size,
232 struct delayed_call *done);
233#else /* !CONFIG_FS_ENCRYPTION */
234
235static inline bool fscrypt_has_encryption_key(const struct inode *inode)
236{
237 return false;
238}
239
240static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
241{
242 return false;
243}
244
245/* crypto.c */
246static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
247{
248}
249
250static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode,
251 gfp_t gfp_flags)
252{
253 return ERR_PTR(-EOPNOTSUPP);
254}
255
256static inline void fscrypt_release_ctx(struct fscrypt_ctx *ctx)
257{
258 return;
259}
260
261static inline struct page *fscrypt_encrypt_page(const struct inode *inode,
262 struct page *page,
263 unsigned int len,
264 unsigned int offs,
265 u64 lblk_num, gfp_t gfp_flags)
266{
267 return ERR_PTR(-EOPNOTSUPP);
268}
269
270static inline int fscrypt_decrypt_page(const struct inode *inode,
271 struct page *page,
272 unsigned int len, unsigned int offs,
273 u64 lblk_num)
274{
275 return -EOPNOTSUPP;
276}
277
278static inline struct page *fscrypt_control_page(struct page *page)
279{
280 WARN_ON_ONCE(1);
281 return ERR_PTR(-EINVAL);
282}
283
284static inline void fscrypt_restore_control_page(struct page *page)
285{
286 return;
287}
288
289/* policy.c */
290static inline int fscrypt_ioctl_set_policy(struct file *filp,
291 const void __user *arg)
292{
293 return -EOPNOTSUPP;
294}
295
296static inline int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
297{
298 return -EOPNOTSUPP;
299}
300
301static inline int fscrypt_has_permitted_context(struct inode *parent,
302 struct inode *child)
303{
304 return 0;
305}
306
307static inline int fscrypt_inherit_context(struct inode *parent,
308 struct inode *child,
309 void *fs_data, bool preload)
310{
311 return -EOPNOTSUPP;
312}
313
314/* keyinfo.c */
315static inline int fscrypt_get_encryption_info(struct inode *inode)
316{
317 return -EOPNOTSUPP;
318}
319
320static inline void fscrypt_put_encryption_info(struct inode *inode)
321{
322 return;
323}
324
325 /* fname.c */
326static inline int fscrypt_setup_filename(struct inode *dir,
327 const struct qstr *iname,
328 int lookup, struct fscrypt_name *fname)
329{
330 if (IS_ENCRYPTED(dir))
331 return -EOPNOTSUPP;
332
333 memset(fname, 0, sizeof(struct fscrypt_name));
334 fname->usr_fname = iname;
335 fname->disk_name.name = (unsigned char *)iname->name;
336 fname->disk_name.len = iname->len;
337 return 0;
338}
339
340static inline void fscrypt_free_filename(struct fscrypt_name *fname)
341{
342 return;
343}
344
345static inline int fscrypt_fname_alloc_buffer(const struct inode *inode,
346 u32 max_encrypted_len,
347 struct fscrypt_str *crypto_str)
348{
349 return -EOPNOTSUPP;
350}
351
352static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
353{
354 return;
355}
356
357static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
358 u32 hash, u32 minor_hash,
359 const struct fscrypt_str *iname,
360 struct fscrypt_str *oname)
361{
362 return -EOPNOTSUPP;
363}
364
365static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
366 const u8 *de_name, u32 de_name_len)
367{
368 /* Encryption support disabled; use standard comparison */
369 if (de_name_len != fname->disk_name.len)
370 return false;
371 return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
372}
373
374/* bio.c */
375static inline void fscrypt_decrypt_bio(struct bio *bio)
376{
377}
378
379static inline void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
380 struct bio *bio)
381{
382}
383
384static inline void fscrypt_pullback_bio_page(struct page **page, bool restore)
385{
386 return;
387}
388
389static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
390 sector_t pblk, unsigned int len)
391{
392 return -EOPNOTSUPP;
393}
394
395/* hooks.c */
396
397static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
398{
399 if (IS_ENCRYPTED(inode))
400 return -EOPNOTSUPP;
401 return 0;
402}
403
404static inline int __fscrypt_prepare_link(struct inode *inode,
405 struct inode *dir)
406{
407 return -EOPNOTSUPP;
408}
409
410static inline int __fscrypt_prepare_rename(struct inode *old_dir,
411 struct dentry *old_dentry,
412 struct inode *new_dir,
413 struct dentry *new_dentry,
414 unsigned int flags)
415{
416 return -EOPNOTSUPP;
417}
418
419static inline int __fscrypt_prepare_lookup(struct inode *dir,
420 struct dentry *dentry)
421{
422 return -EOPNOTSUPP;
423}
424
425static inline int __fscrypt_prepare_symlink(struct inode *dir,
426 unsigned int len,
427 unsigned int max_len,
428 struct fscrypt_str *disk_link)
429{
430 return -EOPNOTSUPP;
431}
432
433
434static inline int __fscrypt_encrypt_symlink(struct inode *inode,
435 const char *target,
436 unsigned int len,
437 struct fscrypt_str *disk_link)
438{
439 return -EOPNOTSUPP;
440}
441
442static inline const char *fscrypt_get_symlink(struct inode *inode,
443 const void *caddr,
444 unsigned int max_size,
445 struct delayed_call *done)
446{
447 return ERR_PTR(-EOPNOTSUPP);
448}
449#endif /* !CONFIG_FS_ENCRYPTION */
50 450
51/**451/**
52 * fscrypt_require_key - require an inode's encryption key452 * fscrypt_require_key - require an inode's encryption key
include/linux/fscrypt_notsupp.h+0−231
@@ -1,231 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * fscrypt_notsupp.h
4 *
5 * This stubs out the fscrypt functions for filesystems configured without
6 * encryption support.
7 *
8 * Do not include this file directly. Use fscrypt.h instead!
9 */
10#ifndef _LINUX_FSCRYPT_H
11#error "Incorrect include of linux/fscrypt_notsupp.h!"
12#endif
13
14#ifndef _LINUX_FSCRYPT_NOTSUPP_H
15#define _LINUX_FSCRYPT_NOTSUPP_H
16
17static inline bool fscrypt_has_encryption_key(const struct inode *inode)
18{
19 return false;
20}
21
22static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
23{
24 return false;
25}
26
27/* crypto.c */
28static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
29{
30}
31
32static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode,
33 gfp_t gfp_flags)
34{
35 return ERR_PTR(-EOPNOTSUPP);
36}
37
38static inline void fscrypt_release_ctx(struct fscrypt_ctx *ctx)
39{
40 return;
41}
42
43static inline struct page *fscrypt_encrypt_page(const struct inode *inode,
44 struct page *page,
45 unsigned int len,
46 unsigned int offs,
47 u64 lblk_num, gfp_t gfp_flags)
48{
49 return ERR_PTR(-EOPNOTSUPP);
50}
51
52static inline int fscrypt_decrypt_page(const struct inode *inode,
53 struct page *page,
54 unsigned int len, unsigned int offs,
55 u64 lblk_num)
56{
57 return -EOPNOTSUPP;
58}
59
60static inline struct page *fscrypt_control_page(struct page *page)
61{
62 WARN_ON_ONCE(1);
63 return ERR_PTR(-EINVAL);
64}
65
66static inline void fscrypt_restore_control_page(struct page *page)
67{
68 return;
69}
70
71/* policy.c */
72static inline int fscrypt_ioctl_set_policy(struct file *filp,
73 const void __user *arg)
74{
75 return -EOPNOTSUPP;
76}
77
78static inline int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
79{
80 return -EOPNOTSUPP;
81}
82
83static inline int fscrypt_has_permitted_context(struct inode *parent,
84 struct inode *child)
85{
86 return 0;
87}
88
89static inline int fscrypt_inherit_context(struct inode *parent,
90 struct inode *child,
91 void *fs_data, bool preload)
92{
93 return -EOPNOTSUPP;
94}
95
96/* keyinfo.c */
97static inline int fscrypt_get_encryption_info(struct inode *inode)
98{
99 return -EOPNOTSUPP;
100}
101
102static inline void fscrypt_put_encryption_info(struct inode *inode)
103{
104 return;
105}
106
107 /* fname.c */
108static inline int fscrypt_setup_filename(struct inode *dir,
109 const struct qstr *iname,
110 int lookup, struct fscrypt_name *fname)
111{
112 if (IS_ENCRYPTED(dir))
113 return -EOPNOTSUPP;
114
115 memset(fname, 0, sizeof(struct fscrypt_name));
116 fname->usr_fname = iname;
117 fname->disk_name.name = (unsigned char *)iname->name;
118 fname->disk_name.len = iname->len;
119 return 0;
120}
121
122static inline void fscrypt_free_filename(struct fscrypt_name *fname)
123{
124 return;
125}
126
127static inline int fscrypt_fname_alloc_buffer(const struct inode *inode,
128 u32 max_encrypted_len,
129 struct fscrypt_str *crypto_str)
130{
131 return -EOPNOTSUPP;
132}
133
134static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
135{
136 return;
137}
138
139static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
140 u32 hash, u32 minor_hash,
141 const struct fscrypt_str *iname,
142 struct fscrypt_str *oname)
143{
144 return -EOPNOTSUPP;
145}
146
147static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
148 const u8 *de_name, u32 de_name_len)
149{
150 /* Encryption support disabled; use standard comparison */
151 if (de_name_len != fname->disk_name.len)
152 return false;
153 return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
154}
155
156/* bio.c */
157static inline void fscrypt_decrypt_bio(struct bio *bio)
158{
159}
160
161static inline void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
162 struct bio *bio)
163{
164}
165
166static inline void fscrypt_pullback_bio_page(struct page **page, bool restore)
167{
168 return;
169}
170
171static inline int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
172 sector_t pblk, unsigned int len)
173{
174 return -EOPNOTSUPP;
175}
176
177/* hooks.c */
178
179static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
180{
181 if (IS_ENCRYPTED(inode))
182 return -EOPNOTSUPP;
183 return 0;
184}
185
186static inline int __fscrypt_prepare_link(struct inode *inode,
187 struct inode *dir)
188{
189 return -EOPNOTSUPP;
190}
191
192static inline int __fscrypt_prepare_rename(struct inode *old_dir,
193 struct dentry *old_dentry,
194 struct inode *new_dir,
195 struct dentry *new_dentry,
196 unsigned int flags)
197{
198 return -EOPNOTSUPP;
199}
200
201static inline int __fscrypt_prepare_lookup(struct inode *dir,
202 struct dentry *dentry)
203{
204 return -EOPNOTSUPP;
205}
206
207static inline int __fscrypt_prepare_symlink(struct inode *dir,
208 unsigned int len,
209 unsigned int max_len,
210 struct fscrypt_str *disk_link)
211{
212 return -EOPNOTSUPP;
213}
214
215static inline int __fscrypt_encrypt_symlink(struct inode *inode,
216 const char *target,
217 unsigned int len,
218 struct fscrypt_str *disk_link)
219{
220 return -EOPNOTSUPP;
221}
222
223static inline const char *fscrypt_get_symlink(struct inode *inode,
224 const void *caddr,
225 unsigned int max_size,
226 struct delayed_call *done)
227{
228 return ERR_PTR(-EOPNOTSUPP);
229}
230
231#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
include/linux/fscrypt_supp.h+0−204
@@ -1,204 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * fscrypt_supp.h
4 *
5 * Do not include this file directly. Use fscrypt.h instead!
6 */
7#ifndef _LINUX_FSCRYPT_H
8#error "Incorrect include of linux/fscrypt_supp.h!"
9#endif
10
11#ifndef _LINUX_FSCRYPT_SUPP_H
12#define _LINUX_FSCRYPT_SUPP_H
13
14#include <linux/mm.h>
15#include <linux/slab.h>
16
17/*
18 * fscrypt superblock flags
19 */
20#define FS_CFLG_OWN_PAGES (1U << 1)
21
22/*
23 * crypto operations for filesystems
24 */
25struct fscrypt_operations {
26 unsigned int flags;
27 const char *key_prefix;
28 int (*get_context)(struct inode *, void *, size_t);
29 int (*set_context)(struct inode *, const void *, size_t, void *);
30 bool (*dummy_context)(struct inode *);
31 bool (*empty_dir)(struct inode *);
32 unsigned int max_namelen;
33};
34
35struct fscrypt_ctx {
36 union {
37 struct {
38 struct page *bounce_page; /* Ciphertext page */
39 struct page *control_page; /* Original page */
40 } w;
41 struct {
42 struct bio *bio;
43 struct work_struct work;
44 } r;
45 struct list_head free_list; /* Free list */
46 };
47 u8 flags; /* Flags */
48};
49
50static inline bool fscrypt_has_encryption_key(const struct inode *inode)
51{
52 return (inode->i_crypt_info != NULL);
53}
54
55static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
56{
57 return inode->i_sb->s_cop->dummy_context &&
58 inode->i_sb->s_cop->dummy_context(inode);
59}
60
61/* crypto.c */
62extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
63extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t);
64extern void fscrypt_release_ctx(struct fscrypt_ctx *);
65extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
66 unsigned int, unsigned int,
67 u64, gfp_t);
68extern int fscrypt_decrypt_page(const struct inode *, struct page *, unsigned int,
69 unsigned int, u64);
70
71static inline struct page *fscrypt_control_page(struct page *page)
72{
73 return ((struct fscrypt_ctx *)page_private(page))->w.control_page;
74}
75
76extern void fscrypt_restore_control_page(struct page *);
77
78/* policy.c */
79extern int fscrypt_ioctl_set_policy(struct file *, const void __user *);
80extern int fscrypt_ioctl_get_policy(struct file *, void __user *);
81extern int fscrypt_has_permitted_context(struct inode *, struct inode *);
82extern int fscrypt_inherit_context(struct inode *, struct inode *,
83 void *, bool);
84/* keyinfo.c */
85extern int fscrypt_get_encryption_info(struct inode *);
86extern void fscrypt_put_encryption_info(struct inode *);
87
88/* fname.c */
89extern int fscrypt_setup_filename(struct inode *, const struct qstr *,
90 int lookup, struct fscrypt_name *);
91
92static inline void fscrypt_free_filename(struct fscrypt_name *fname)
93{
94 kfree(fname->crypto_buf.name);
95}
96
97extern int fscrypt_fname_alloc_buffer(const struct inode *, u32,
98 struct fscrypt_str *);
99extern void fscrypt_fname_free_buffer(struct fscrypt_str *);
100extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32,
101 const struct fscrypt_str *, struct fscrypt_str *);
102
103#define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE 32
104
105/* Extracts the second-to-last ciphertext block; see explanation below */
106#define FSCRYPT_FNAME_DIGEST(name, len) \
107 ((name) + round_down((len) - FS_CRYPTO_BLOCK_SIZE - 1, \
108 FS_CRYPTO_BLOCK_SIZE))
109
110#define FSCRYPT_FNAME_DIGEST_SIZE FS_CRYPTO_BLOCK_SIZE
111
112/**
113 * fscrypt_digested_name - alternate identifier for an on-disk filename
114 *
115 * When userspace lists an encrypted directory without access to the key,
116 * filenames whose ciphertext is longer than FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE
117 * bytes are shown in this abbreviated form (base64-encoded) rather than as the
118 * full ciphertext (base64-encoded). This is necessary to allow supporting
119 * filenames up to NAME_MAX bytes, since base64 encoding expands the length.
120 *
121 * To make it possible for filesystems to still find the correct directory entry
122 * despite not knowing the full on-disk name, we encode any filesystem-specific
123 * 'hash' and/or 'minor_hash' which the filesystem may need for its lookups,
124 * followed by the second-to-last ciphertext block of the filename. Due to the
125 * use of the CBC-CTS encryption mode, the second-to-last ciphertext block
126 * depends on the full plaintext. (Note that ciphertext stealing causes the
127 * last two blocks to appear "flipped".) This makes accidental collisions very
128 * unlikely: just a 1 in 2^128 chance for two filenames to collide even if they
129 * share the same filesystem-specific hashes.
130 *
131 * However, this scheme isn't immune to intentional collisions, which can be
132 * created by anyone able to create arbitrary plaintext filenames and view them
133 * without the key. Making the "digest" be a real cryptographic hash like
134 * SHA-256 over the full ciphertext would prevent this, although it would be
135 * less efficient and harder to implement, especially since the filesystem would
136 * need to calculate it for each directory entry examined during a search.
137 */
138struct fscrypt_digested_name {
139 u32 hash;
140 u32 minor_hash;
141 u8 digest[FSCRYPT_FNAME_DIGEST_SIZE];
142};
143
144/**
145 * fscrypt_match_name() - test whether the given name matches a directory entry
146 * @fname: the name being searched for
147 * @de_name: the name from the directory entry
148 * @de_name_len: the length of @de_name in bytes
149 *
150 * Normally @fname->disk_name will be set, and in that case we simply compare
151 * that to the name stored in the directory entry. The only exception is that
152 * if we don't have the key for an encrypted directory and a filename in it is
153 * very long, then we won't have the full disk_name and we'll instead need to
154 * match against the fscrypt_digested_name.
155 *
156 * Return: %true if the name matches, otherwise %false.
157 */
158static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
159 const u8 *de_name, u32 de_name_len)
160{
161 if (unlikely(!fname->disk_name.name)) {
162 const struct fscrypt_digested_name *n =
163 (const void *)fname->crypto_buf.name;
164 if (WARN_ON_ONCE(fname->usr_fname->name[0] != '_'))
165 return false;
166 if (de_name_len <= FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE)
167 return false;
168 return !memcmp(FSCRYPT_FNAME_DIGEST(de_name, de_name_len),
169 n->digest, FSCRYPT_FNAME_DIGEST_SIZE);
170 }
171
172 if (de_name_len != fname->disk_name.len)
173 return false;
174 return !memcmp(de_name, fname->disk_name.name, fname->disk_name.len);
175}
176
177/* bio.c */
178extern void fscrypt_decrypt_bio(struct bio *);
179extern void fscrypt_enqueue_decrypt_bio(struct fscrypt_ctx *ctx,
180 struct bio *bio);
181extern void fscrypt_pullback_bio_page(struct page **, bool);
182extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,
183 unsigned int);
184
185/* hooks.c */
186extern int fscrypt_file_open(struct inode *inode, struct file *filp);
187extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir);
188extern int __fscrypt_prepare_rename(struct inode *old_dir,
189 struct dentry *old_dentry,
190 struct inode *new_dir,
191 struct dentry *new_dentry,
192 unsigned int flags);
193extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry);
194extern int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
195 unsigned int max_len,
196 struct fscrypt_str *disk_link);
197extern int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
198 unsigned int len,
199 struct fscrypt_str *disk_link);
200extern const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
201 unsigned int max_size,
202 struct delayed_call *done);
203
204#endif /* _LINUX_FSCRYPT_SUPP_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t