linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: do not unnecessarily null-terminate encrypted symlink data
@ 2016-09-22 20:31 Eric Biggers
  2016-09-22 20:31 ` [PATCH] f2fs: " Eric Biggers
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Eric Biggers @ 2016-09-22 20:31 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-ext4, linux-f2fs-devel, tytso, jaegeuk, Eric Biggers

Null-terminating the fscrypt_symlink_data on read is unnecessary because
it is not string data --- it contains binary ciphertext.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/ext4/symlink.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
index 0a26cbd..fdf1c61 100644
--- a/fs/ext4/symlink.c
+++ b/fs/ext4/symlink.c
@@ -30,7 +30,6 @@ static const char *ext4_encrypted_get_link(struct dentry *dentry,
 	char *caddr, *paddr = NULL;
 	struct fscrypt_str cstr, pstr;
 	struct fscrypt_symlink_data *sd;
-	loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
 	int res;
 	u32 max_size = inode->i_sb->s_blocksize;
 
@@ -49,7 +48,6 @@ static const char *ext4_encrypted_get_link(struct dentry *dentry,
 		if (IS_ERR(cpage))
 			return ERR_CAST(cpage);
 		caddr = page_address(cpage);
-		caddr[size] = 0;
 	}
 
 	/* Symlink is encrypted */
-- 
2.8.0.rc3.226.g39d4020


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] f2fs: do not unnecessarily null-terminate encrypted symlink data
  2016-09-22 20:31 [PATCH] ext4: do not unnecessarily null-terminate encrypted symlink data Eric Biggers
@ 2016-09-22 20:31 ` Eric Biggers
  2016-09-22 20:31 ` [PATCH] fscrypto: use standard macros to compute length of fname ciphertext Eric Biggers
  2016-09-30  5:45 ` [PATCH] ext4: do not unnecessarily null-terminate encrypted symlink data Theodore Ts'o
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2016-09-22 20:31 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-ext4, linux-f2fs-devel, tytso, jaegeuk, Eric Biggers

Null-terminating the fscrypt_symlink_data on read is unnecessary because
it is not string data --- it contains binary ciphertext.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/f2fs/namei.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index afd5633..5b4733e 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -1010,7 +1010,6 @@ static const char *f2fs_encrypted_get_link(struct dentry *dentry,
 	struct fscrypt_str cstr = FSTR_INIT(NULL, 0);
 	struct fscrypt_str pstr = FSTR_INIT(NULL, 0);
 	struct fscrypt_symlink_data *sd;
-	loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
 	u32 max_size = inode->i_sb->s_blocksize;
 	int res;
 
@@ -1025,7 +1024,6 @@ static const char *f2fs_encrypted_get_link(struct dentry *dentry,
 	if (IS_ERR(cpage))
 		return ERR_CAST(cpage);
 	caddr = page_address(cpage);
-	caddr[size] = 0;
 
 	/* Symlink is encrypted */
 	sd = (struct fscrypt_symlink_data *)caddr;
-- 
2.8.0.rc3.226.g39d4020


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] fscrypto: use standard macros to compute length of fname ciphertext
  2016-09-22 20:31 [PATCH] ext4: do not unnecessarily null-terminate encrypted symlink data Eric Biggers
  2016-09-22 20:31 ` [PATCH] f2fs: " Eric Biggers
@ 2016-09-22 20:31 ` Eric Biggers
  2016-09-30  5:47   ` Theodore Ts'o
  2016-09-30  5:45 ` [PATCH] ext4: do not unnecessarily null-terminate encrypted symlink data Theodore Ts'o
  2 siblings, 1 reply; 5+ messages in thread
From: Eric Biggers @ 2016-09-22 20:31 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-ext4, linux-f2fs-devel, tytso, jaegeuk, Eric Biggers

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/crypto/fname.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c
index 90697c7..9a28133 100644
--- a/fs/crypto/fname.c
+++ b/fs/crypto/fname.c
@@ -14,11 +14,6 @@
 #include <linux/ratelimit.h>
 #include <linux/fscrypto.h>
 
-static u32 size_round_up(size_t size, size_t blksize)
-{
-	return ((size + blksize - 1) / blksize) * blksize;
-}
-
 /**
  * fname_crypt_complete() - completion callback for filename crypto
  * @req: The asynchronous cipher request context
@@ -60,10 +55,9 @@ static int fname_encrypt(struct inode *inode,
 	if (iname->len <= 0 || iname->len > lim)
 		return -EIO;
 
-	ciphertext_len = (iname->len < FS_CRYPTO_BLOCK_SIZE) ?
-					FS_CRYPTO_BLOCK_SIZE : iname->len;
-	ciphertext_len = size_round_up(ciphertext_len, padding);
-	ciphertext_len = (ciphertext_len > lim) ? lim : ciphertext_len;
+	ciphertext_len = max(iname->len, (u32)FS_CRYPTO_BLOCK_SIZE);
+	ciphertext_len = round_up(ciphertext_len, padding);
+	ciphertext_len = min(ciphertext_len, lim);
 
 	if (ciphertext_len <= sizeof(buf)) {
 		workbuf = buf;
@@ -233,9 +227,8 @@ u32 fscrypt_fname_encrypted_size(struct inode *inode, u32 ilen)
 
 	if (ci)
 		padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK);
-	if (ilen < FS_CRYPTO_BLOCK_SIZE)
-		ilen = FS_CRYPTO_BLOCK_SIZE;
-	return size_round_up(ilen, padding);
+	ilen = max(ilen, (u32)FS_CRYPTO_BLOCK_SIZE);
+	return round_up(ilen, padding);
 }
 EXPORT_SYMBOL(fscrypt_fname_encrypted_size);
 
-- 
2.8.0.rc3.226.g39d4020


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext4: do not unnecessarily null-terminate encrypted symlink data
  2016-09-22 20:31 [PATCH] ext4: do not unnecessarily null-terminate encrypted symlink data Eric Biggers
  2016-09-22 20:31 ` [PATCH] f2fs: " Eric Biggers
  2016-09-22 20:31 ` [PATCH] fscrypto: use standard macros to compute length of fname ciphertext Eric Biggers
@ 2016-09-30  5:45 ` Theodore Ts'o
  2 siblings, 0 replies; 5+ messages in thread
From: Theodore Ts'o @ 2016-09-30  5:45 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-fsdevel, linux-ext4, linux-f2fs-devel, jaegeuk

On Thu, Sep 22, 2016 at 01:31:47PM -0700, Eric Biggers wrote:
> Null-terminating the fscrypt_symlink_data on read is unnecessary because
> it is not string data --- it contains binary ciphertext.
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fscrypto: use standard macros to compute length of fname ciphertext
  2016-09-22 20:31 ` [PATCH] fscrypto: use standard macros to compute length of fname ciphertext Eric Biggers
@ 2016-09-30  5:47   ` Theodore Ts'o
  0 siblings, 0 replies; 5+ messages in thread
From: Theodore Ts'o @ 2016-09-30  5:47 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-fsdevel, linux-ext4, linux-f2fs-devel, jaegeuk

On Thu, Sep 22, 2016 at 01:31:49PM -0700, Eric Biggers wrote:
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-30  5:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-22 20:31 [PATCH] ext4: do not unnecessarily null-terminate encrypted symlink data Eric Biggers
2016-09-22 20:31 ` [PATCH] f2fs: " Eric Biggers
2016-09-22 20:31 ` [PATCH] fscrypto: use standard macros to compute length of fname ciphertext Eric Biggers
2016-09-30  5:47   ` Theodore Ts'o
2016-09-30  5:45 ` [PATCH] ext4: do not unnecessarily null-terminate encrypted symlink data Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).