diff options
author | Eric Biggers <ebiggers@google.com> | 2018-04-30 18:51:44 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2018-05-20 16:21:03 -0400 |
commit | e12ee6836a3fd3c6ebc9b2dc8a7974af592340d0 (patch) | |
tree | 64b030404b24cab9026483250f29aaca36741c5c | |
parent | 0c4cdb27caa40167a7369a986afcde3d1d913b06 (diff) |
fscrypt: make fscrypt_operations.max_namelen an integer
Now ->max_namelen() is only called to limit the filename length when
adding NUL padding, and only for real filenames -- not symlink targets.
It also didn't give the correct length for symlink targets anyway since
it forgot to subtract 'sizeof(struct fscrypt_symlink_data)'.
Thus, change ->max_namelen from a function to a simple 'unsigned int'
that gives the filesystem's maximum filename length.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | fs/crypto/fname.c | 2 | ||||
-rw-r--r-- | fs/ext4/super.c | 8 | ||||
-rw-r--r-- | fs/f2fs/super.c | 8 | ||||
-rw-r--r-- | fs/ubifs/crypto.c | 10 | ||||
-rw-r--r-- | include/linux/fscrypt_supp.h | 2 |
5 files changed, 5 insertions, 25 deletions
diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c index c4eb3a235ae4..39091fc31e98 100644 --- a/fs/crypto/fname.c +++ b/fs/crypto/fname.c | |||
@@ -334,7 +334,7 @@ int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname, | |||
334 | 334 | ||
335 | if (dir->i_crypt_info) { | 335 | if (dir->i_crypt_info) { |
336 | if (!fscrypt_fname_encrypted_size(dir, iname->len, | 336 | if (!fscrypt_fname_encrypted_size(dir, iname->len, |
337 | dir->i_sb->s_cop->max_namelen(dir), | 337 | dir->i_sb->s_cop->max_namelen, |
338 | &fname->crypto_buf.len)) | 338 | &fname->crypto_buf.len)) |
339 | return -ENAMETOOLONG; | 339 | return -ENAMETOOLONG; |
340 | fname->crypto_buf.name = kmalloc(fname->crypto_buf.len, | 340 | fname->crypto_buf.name = kmalloc(fname->crypto_buf.len, |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index eb104e8476f0..502c36da292c 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -1237,19 +1237,13 @@ static bool ext4_dummy_context(struct inode *inode) | |||
1237 | return DUMMY_ENCRYPTION_ENABLED(EXT4_SB(inode->i_sb)); | 1237 | return DUMMY_ENCRYPTION_ENABLED(EXT4_SB(inode->i_sb)); |
1238 | } | 1238 | } |
1239 | 1239 | ||
1240 | static unsigned ext4_max_namelen(struct inode *inode) | ||
1241 | { | ||
1242 | return S_ISLNK(inode->i_mode) ? inode->i_sb->s_blocksize : | ||
1243 | EXT4_NAME_LEN; | ||
1244 | } | ||
1245 | |||
1246 | static const struct fscrypt_operations ext4_cryptops = { | 1240 | static const struct fscrypt_operations ext4_cryptops = { |
1247 | .key_prefix = "ext4:", | 1241 | .key_prefix = "ext4:", |
1248 | .get_context = ext4_get_context, | 1242 | .get_context = ext4_get_context, |
1249 | .set_context = ext4_set_context, | 1243 | .set_context = ext4_set_context, |
1250 | .dummy_context = ext4_dummy_context, | 1244 | .dummy_context = ext4_dummy_context, |
1251 | .empty_dir = ext4_empty_dir, | 1245 | .empty_dir = ext4_empty_dir, |
1252 | .max_namelen = ext4_max_namelen, | 1246 | .max_namelen = EXT4_NAME_LEN, |
1253 | }; | 1247 | }; |
1254 | #endif | 1248 | #endif |
1255 | 1249 | ||
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 42d564c5ccd0..970ae27f401c 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -1930,19 +1930,13 @@ static bool f2fs_dummy_context(struct inode *inode) | |||
1930 | return DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(inode)); | 1930 | return DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(inode)); |
1931 | } | 1931 | } |
1932 | 1932 | ||
1933 | static unsigned f2fs_max_namelen(struct inode *inode) | ||
1934 | { | ||
1935 | return S_ISLNK(inode->i_mode) ? | ||
1936 | inode->i_sb->s_blocksize : F2FS_NAME_LEN; | ||
1937 | } | ||
1938 | |||
1939 | static const struct fscrypt_operations f2fs_cryptops = { | 1933 | static const struct fscrypt_operations f2fs_cryptops = { |
1940 | .key_prefix = "f2fs:", | 1934 | .key_prefix = "f2fs:", |
1941 | .get_context = f2fs_get_context, | 1935 | .get_context = f2fs_get_context, |
1942 | .set_context = f2fs_set_context, | 1936 | .set_context = f2fs_set_context, |
1943 | .dummy_context = f2fs_dummy_context, | 1937 | .dummy_context = f2fs_dummy_context, |
1944 | .empty_dir = f2fs_empty_dir, | 1938 | .empty_dir = f2fs_empty_dir, |
1945 | .max_namelen = f2fs_max_namelen, | 1939 | .max_namelen = F2FS_NAME_LEN, |
1946 | }; | 1940 | }; |
1947 | #endif | 1941 | #endif |
1948 | 1942 | ||
diff --git a/fs/ubifs/crypto.c b/fs/ubifs/crypto.c index 616a688f5d8f..55c508fe8131 100644 --- a/fs/ubifs/crypto.c +++ b/fs/ubifs/crypto.c | |||
@@ -24,14 +24,6 @@ static bool ubifs_crypt_empty_dir(struct inode *inode) | |||
24 | return ubifs_check_dir_empty(inode) == 0; | 24 | return ubifs_check_dir_empty(inode) == 0; |
25 | } | 25 | } |
26 | 26 | ||
27 | static unsigned int ubifs_crypt_max_namelen(struct inode *inode) | ||
28 | { | ||
29 | if (S_ISLNK(inode->i_mode)) | ||
30 | return UBIFS_MAX_INO_DATA; | ||
31 | else | ||
32 | return UBIFS_MAX_NLEN; | ||
33 | } | ||
34 | |||
35 | int ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn, | 27 | int ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn, |
36 | unsigned int in_len, unsigned int *out_len, int block) | 28 | unsigned int in_len, unsigned int *out_len, int block) |
37 | { | 29 | { |
@@ -89,5 +81,5 @@ const struct fscrypt_operations ubifs_crypt_operations = { | |||
89 | .get_context = ubifs_crypt_get_context, | 81 | .get_context = ubifs_crypt_get_context, |
90 | .set_context = ubifs_crypt_set_context, | 82 | .set_context = ubifs_crypt_set_context, |
91 | .empty_dir = ubifs_crypt_empty_dir, | 83 | .empty_dir = ubifs_crypt_empty_dir, |
92 | .max_namelen = ubifs_crypt_max_namelen, | 84 | .max_namelen = UBIFS_MAX_NLEN, |
93 | }; | 85 | }; |
diff --git a/include/linux/fscrypt_supp.h b/include/linux/fscrypt_supp.h index c9c2cc26bc62..5080cb1bec4c 100644 --- a/include/linux/fscrypt_supp.h +++ b/include/linux/fscrypt_supp.h | |||
@@ -29,7 +29,7 @@ struct fscrypt_operations { | |||
29 | int (*set_context)(struct inode *, const void *, size_t, void *); | 29 | int (*set_context)(struct inode *, const void *, size_t, void *); |
30 | bool (*dummy_context)(struct inode *); | 30 | bool (*dummy_context)(struct inode *); |
31 | bool (*empty_dir)(struct inode *); | 31 | bool (*empty_dir)(struct inode *); |
32 | unsigned (*max_namelen)(struct inode *); | 32 | unsigned int max_namelen; |
33 | }; | 33 | }; |
34 | 34 | ||
35 | struct fscrypt_ctx { | 35 | struct fscrypt_ctx { |