aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2016-09-15 17:25:55 -0400
committerTheodore Ts'o <tytso@mit.edu>2016-09-15 17:25:55 -0400
commitef1eb3aa50930f026135085cd160b1212cdfe817 (patch)
tree12ed99fd9e7dc658b0e1bb0bc78e2ad0bb887dca /fs/ext4
parent53fd7550ec40571e26f730a0d3fc0a5dd93ecda2 (diff)
fscrypto: make filename crypto functions return 0 on success
Several filename crypto functions: fname_decrypt(), fscrypt_fname_disk_to_usr(), and fscrypt_fname_usr_to_disk(), returned the output length on success or -errno on failure. However, the output length was redundant with the value written to 'oname->len'. It is also potentially error-prone to make callers have to check for '< 0' instead of '!= 0'. Therefore, make these functions return 0 instead of a length, and make the callers who cared about the return value being a length use 'oname->len' instead. For consistency also make other callers check for a nonzero result rather than a negative result. This change also fixes the inconsistency of fname_encrypt() actually already returning 0 on success, not a length like the other filename crypto functions and as documented in its function comment. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Andreas Dilger <adilger@dilger.ca> Acked-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/dir.c5
-rw-r--r--fs/ext4/namei.c8
-rw-r--r--fs/ext4/symlink.c5
3 files changed, 9 insertions, 9 deletions
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 67415e0e6af0..4d4b91029109 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -260,11 +260,12 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
260 /* Directory is encrypted */ 260 /* Directory is encrypted */
261 err = fscrypt_fname_disk_to_usr(inode, 261 err = fscrypt_fname_disk_to_usr(inode,
262 0, 0, &de_name, &fstr); 262 0, 0, &de_name, &fstr);
263 de_name = fstr;
263 fstr.len = save_len; 264 fstr.len = save_len;
264 if (err < 0) 265 if (err)
265 goto errout; 266 goto errout;
266 if (!dir_emit(ctx, 267 if (!dir_emit(ctx,
267 fstr.name, err, 268 de_name.name, de_name.len,
268 le32_to_cpu(de->inode), 269 le32_to_cpu(de->inode),
269 get_dtype(sb, de->file_type))) 270 get_dtype(sb, de->file_type)))
270 goto done; 271 goto done;
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 34c0142caf6a..2243ae2ad2ee 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -639,7 +639,7 @@ static struct stats dx_show_leaf(struct inode *dir,
639 res = fscrypt_fname_alloc_buffer( 639 res = fscrypt_fname_alloc_buffer(
640 dir, len, 640 dir, len,
641 &fname_crypto_str); 641 &fname_crypto_str);
642 if (res < 0) 642 if (res)
643 printk(KERN_WARNING "Error " 643 printk(KERN_WARNING "Error "
644 "allocating crypto " 644 "allocating crypto "
645 "buffer--skipping " 645 "buffer--skipping "
@@ -647,7 +647,7 @@ static struct stats dx_show_leaf(struct inode *dir,
647 res = fscrypt_fname_disk_to_usr(dir, 647 res = fscrypt_fname_disk_to_usr(dir,
648 0, 0, &de_name, 648 0, 0, &de_name,
649 &fname_crypto_str); 649 &fname_crypto_str);
650 if (res < 0) { 650 if (res) {
651 printk(KERN_WARNING "Error " 651 printk(KERN_WARNING "Error "
652 "converting filename " 652 "converting filename "
653 "from disk to usr" 653 "from disk to usr"
@@ -1011,7 +1011,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
1011 err = fscrypt_fname_disk_to_usr(dir, hinfo->hash, 1011 err = fscrypt_fname_disk_to_usr(dir, hinfo->hash,
1012 hinfo->minor_hash, &de_name, 1012 hinfo->minor_hash, &de_name,
1013 &fname_crypto_str); 1013 &fname_crypto_str);
1014 if (err < 0) { 1014 if (err) {
1015 count = err; 1015 count = err;
1016 goto errout; 1016 goto errout;
1017 } 1017 }
@@ -3144,7 +3144,7 @@ static int ext4_symlink(struct inode *dir,
3144 istr.name = (const unsigned char *) symname; 3144 istr.name = (const unsigned char *) symname;
3145 istr.len = len; 3145 istr.len = len;
3146 err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr); 3146 err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr);
3147 if (err < 0) 3147 if (err)
3148 goto err_drop_inode; 3148 goto err_drop_inode;
3149 sd->len = cpu_to_le16(ostr.len); 3149 sd->len = cpu_to_le16(ostr.len);
3150 disk_link.name = (char *) sd; 3150 disk_link.name = (char *) sd;
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
index 04a7850a0d45..0a26cbd529c8 100644
--- a/fs/ext4/symlink.c
+++ b/fs/ext4/symlink.c
@@ -68,12 +68,11 @@ static const char *ext4_encrypted_get_link(struct dentry *dentry,
68 paddr = pstr.name; 68 paddr = pstr.name;
69 69
70 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr); 70 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
71 if (res < 0) 71 if (res)
72 goto errout; 72 goto errout;
73 73
74 /* Null-terminate the name */ 74 /* Null-terminate the name */
75 if (res <= pstr.len) 75 paddr[pstr.len] = '\0';
76 paddr[res] = '\0';
77 if (cpage) 76 if (cpage)
78 put_page(cpage); 77 put_page(cpage);
79 set_delayed_call(done, kfree_link, paddr); 78 set_delayed_call(done, kfree_link, paddr);