summaryrefslogtreecommitdiff
path: root/fs/crypto/hooks.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2018-01-11 23:30:08 -0500
committerJaegeuk Kim <jaegeuk@kernel.org>2018-04-08 02:27:19 -0700
commit168a90782888affff92b4a4fe950c9e5afca7179 (patch)
treebdfd86b1cd4a432c33a0d8c8cbda70aa17fdbea9 /fs/crypto/hooks.c
parent042ae9f4cfbfb555e6de68579870ac3c43594215 (diff)
fscrypt: calculate NUL-padding length in one place only
Currently, when encrypting a filename (either a real filename or a symlink target) we calculate the amount of NUL-padding twice: once before encryption and once during encryption in fname_encrypt(). It is needed before encryption to allocate the needed buffer size as well as calculate the size the symlink target will take up on-disk before creating the symlink inode. Calculating the size during encryption as well is redundant. Remove this redundancy by always calculating the exact size beforehand, and making fname_encrypt() just add as much NUL padding as is needed to fill the output buffer. 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.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/fs/crypto/hooks.c b/fs/crypto/hooks.c
index 534cfb212cdb..8b829400f467 100644
--- a/fs/crypto/hooks.c
+++ b/fs/crypto/hooks.c
@@ -161,7 +161,6 @@ int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
struct qstr iname = { .name = target, .len = len };
struct fscrypt_symlink_data *sd;
unsigned int ciphertext_len;
- struct fscrypt_str oname;
err = fscrypt_require_key(inode);
if (err)
@@ -178,16 +177,12 @@ int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
ciphertext_len = disk_link->len - sizeof(*sd);
sd->len = cpu_to_le16(ciphertext_len);
- oname.name = sd->encrypted_path;
- oname.len = ciphertext_len;
- err = fname_encrypt(inode, &iname, &oname);
+ err = fname_encrypt(inode, &iname, sd->encrypted_path, ciphertext_len);
if (err) {
if (!disk_link->name)
kfree(sd);
return err;
}
- BUG_ON(oname.len != ciphertext_len);
-
/*
* Null-terminating the ciphertext doesn't make sense, but we still
* count the null terminator in the length, so we might as well