diff options
author | Eric Biggers <ebiggers@google.com> | 2018-01-12 05:30:08 +0100 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2018-01-12 05:30:08 +0100 |
commit | b9db0b4a68d373897119d1e0a3beebe1c1a23936 (patch) | |
tree | 3cb57195d294dae3eb19378428cabc75e78621e3 /fs/crypto/hooks.c | |
parent | fscrypt: define fscrypt_fname_alloc_buffer() to be for presented names (diff) | |
download | linux-b9db0b4a68d373897119d1e0a3beebe1c1a23936.tar.xz linux-b9db0b4a68d373897119d1e0a3beebe1c1a23936.zip |
fscrypt: fix up fscrypt_fname_encrypted_size() for internal use
Filesystems don't need fscrypt_fname_encrypted_size() anymore, so
unexport it and move it to fscrypt_private.h.
We also never calculate the encrypted size of a filename without having
the fscrypt_info present since it is needed to know the amount of
NUL-padding which is determined by the encryption policy, and also we
will always truncate the NUL-padding to the maximum filename length.
Therefore, also make fscrypt_fname_encrypted_size() assume that the
fscrypt_info is present, and make it truncate the returned length to the
specified max_len.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/crypto/hooks.c')
-rw-r--r-- | fs/crypto/hooks.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/fs/crypto/hooks.c b/fs/crypto/hooks.c index 5bf38d94c5d2..28f9f059571d 100644 --- a/fs/crypto/hooks.c +++ b/fs/crypto/hooks.c @@ -143,12 +143,12 @@ int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len, * counting it (even though it is meaningless for ciphertext) is simpler * for now since filesystems will assume it is there and subtract it. */ - if (sizeof(struct fscrypt_symlink_data) + len > max_len) + if (!fscrypt_fname_encrypted_size(dir, len, + max_len - sizeof(struct fscrypt_symlink_data), + &disk_link->len)) return -ENAMETOOLONG; - disk_link->len = min_t(unsigned int, - sizeof(struct fscrypt_symlink_data) + - fscrypt_fname_encrypted_size(dir, len), - max_len); + disk_link->len += sizeof(struct fscrypt_symlink_data); + disk_link->name = NULL; return 0; } |