All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	linux-mtd@lists.infradead.org,
	Chandan Rajendra <chandan@linux.ibm.com>,
	linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 04/13] fscrypt: clean up some BUG_ON()s in block encryption/decryption
Date: Wed,  1 May 2019 15:45:06 -0700	[thread overview]
Message-ID: <20190501224515.43059-5-ebiggers@kernel.org> (raw)
In-Reply-To: <20190501224515.43059-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

Replace some BUG_ON()s with WARN_ON_ONCE() and returning an error code,
and move the check for len divisible by FS_CRYPTO_BLOCK_SIZE into
fscrypt_crypt_block() so that it's done for both encryption and
decryption, not just encryption.

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

diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index e6802d7aca3c7..9cda0147fca95 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -161,7 +161,10 @@ int fscrypt_crypt_block(const struct inode *inode, fscrypt_direction_t rw,
 	struct crypto_skcipher *tfm = ci->ci_ctfm;
 	int res = 0;
 
-	BUG_ON(len == 0);
+	if (WARN_ON_ONCE(len <= 0))
+		return -EINVAL;
+	if (WARN_ON_ONCE(len % FS_CRYPTO_BLOCK_SIZE != 0))
+		return -EINVAL;
 
 	fscrypt_generate_iv(&iv, lblk_num, ci);
 
@@ -224,8 +227,6 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
 	struct page *ciphertext_page = page;
 	int err;
 
-	BUG_ON(len % FS_CRYPTO_BLOCK_SIZE != 0);
-
 	if (inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES) {
 		/* with inplace-encryption we just encrypt the page */
 		err = fscrypt_crypt_block(inode, FS_ENCRYPT, lblk_num, page,
@@ -237,7 +238,8 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
 		return ciphertext_page;
 	}
 
-	BUG_ON(!PageLocked(page));
+	if (WARN_ON_ONCE(!PageLocked(page)))
+		return ERR_PTR(-EINVAL);
 
 	/* The encryption operation will require a bounce page. */
 	ciphertext_page = fscrypt_alloc_bounce_page(gfp_flags);
@@ -274,8 +276,9 @@ EXPORT_SYMBOL(fscrypt_encrypt_page);
 int fscrypt_decrypt_page(const struct inode *inode, struct page *page,
 			unsigned int len, unsigned int offs, u64 lblk_num)
 {
-	if (!(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES))
-		BUG_ON(!PageLocked(page));
+	if (WARN_ON_ONCE(!PageLocked(page) &&
+			 !(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES)))
+		return -EINVAL;
 
 	return fscrypt_crypt_block(inode, FS_DECRYPT, lblk_num, page, page,
 				   len, offs, GFP_NOFS);
-- 
2.21.0.593.g511ec345e18-goog



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org
Cc: linux-ext4@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org,
	Chandan Rajendra <chandan@linux.ibm.com>
Subject: [PATCH 04/13] fscrypt: clean up some BUG_ON()s in block encryption/decryption
Date: Wed,  1 May 2019 15:45:06 -0700	[thread overview]
Message-ID: <20190501224515.43059-5-ebiggers@kernel.org> (raw)
In-Reply-To: <20190501224515.43059-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

Replace some BUG_ON()s with WARN_ON_ONCE() and returning an error code,
and move the check for len divisible by FS_CRYPTO_BLOCK_SIZE into
fscrypt_crypt_block() so that it's done for both encryption and
decryption, not just encryption.

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

diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index e6802d7aca3c7..9cda0147fca95 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -161,7 +161,10 @@ int fscrypt_crypt_block(const struct inode *inode, fscrypt_direction_t rw,
 	struct crypto_skcipher *tfm = ci->ci_ctfm;
 	int res = 0;
 
-	BUG_ON(len == 0);
+	if (WARN_ON_ONCE(len <= 0))
+		return -EINVAL;
+	if (WARN_ON_ONCE(len % FS_CRYPTO_BLOCK_SIZE != 0))
+		return -EINVAL;
 
 	fscrypt_generate_iv(&iv, lblk_num, ci);
 
@@ -224,8 +227,6 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
 	struct page *ciphertext_page = page;
 	int err;
 
-	BUG_ON(len % FS_CRYPTO_BLOCK_SIZE != 0);
-
 	if (inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES) {
 		/* with inplace-encryption we just encrypt the page */
 		err = fscrypt_crypt_block(inode, FS_ENCRYPT, lblk_num, page,
@@ -237,7 +238,8 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
 		return ciphertext_page;
 	}
 
-	BUG_ON(!PageLocked(page));
+	if (WARN_ON_ONCE(!PageLocked(page)))
+		return ERR_PTR(-EINVAL);
 
 	/* The encryption operation will require a bounce page. */
 	ciphertext_page = fscrypt_alloc_bounce_page(gfp_flags);
@@ -274,8 +276,9 @@ EXPORT_SYMBOL(fscrypt_encrypt_page);
 int fscrypt_decrypt_page(const struct inode *inode, struct page *page,
 			unsigned int len, unsigned int offs, u64 lblk_num)
 {
-	if (!(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES))
-		BUG_ON(!PageLocked(page));
+	if (WARN_ON_ONCE(!PageLocked(page) &&
+			 !(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES)))
+		return -EINVAL;
 
 	return fscrypt_crypt_block(inode, FS_DECRYPT, lblk_num, page, page,
 				   len, offs, GFP_NOFS);
-- 
2.21.0.593.g511ec345e18-goog


WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	linux-mtd@lists.infradead.org,
	Chandan Rajendra <chandan@linux.ibm.com>,
	linux-f2fs-devel@lists.sourceforge.net
Subject: [PATCH 04/13] fscrypt: clean up some BUG_ON()s in block encryption/decryption
Date: Wed,  1 May 2019 15:45:06 -0700	[thread overview]
Message-ID: <20190501224515.43059-5-ebiggers@kernel.org> (raw)
In-Reply-To: <20190501224515.43059-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

Replace some BUG_ON()s with WARN_ON_ONCE() and returning an error code,
and move the check for len divisible by FS_CRYPTO_BLOCK_SIZE into
fscrypt_crypt_block() so that it's done for both encryption and
decryption, not just encryption.

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

diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index e6802d7aca3c7..9cda0147fca95 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -161,7 +161,10 @@ int fscrypt_crypt_block(const struct inode *inode, fscrypt_direction_t rw,
 	struct crypto_skcipher *tfm = ci->ci_ctfm;
 	int res = 0;
 
-	BUG_ON(len == 0);
+	if (WARN_ON_ONCE(len <= 0))
+		return -EINVAL;
+	if (WARN_ON_ONCE(len % FS_CRYPTO_BLOCK_SIZE != 0))
+		return -EINVAL;
 
 	fscrypt_generate_iv(&iv, lblk_num, ci);
 
@@ -224,8 +227,6 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
 	struct page *ciphertext_page = page;
 	int err;
 
-	BUG_ON(len % FS_CRYPTO_BLOCK_SIZE != 0);
-
 	if (inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES) {
 		/* with inplace-encryption we just encrypt the page */
 		err = fscrypt_crypt_block(inode, FS_ENCRYPT, lblk_num, page,
@@ -237,7 +238,8 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
 		return ciphertext_page;
 	}
 
-	BUG_ON(!PageLocked(page));
+	if (WARN_ON_ONCE(!PageLocked(page)))
+		return ERR_PTR(-EINVAL);
 
 	/* The encryption operation will require a bounce page. */
 	ciphertext_page = fscrypt_alloc_bounce_page(gfp_flags);
@@ -274,8 +276,9 @@ EXPORT_SYMBOL(fscrypt_encrypt_page);
 int fscrypt_decrypt_page(const struct inode *inode, struct page *page,
 			unsigned int len, unsigned int offs, u64 lblk_num)
 {
-	if (!(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES))
-		BUG_ON(!PageLocked(page));
+	if (WARN_ON_ONCE(!PageLocked(page) &&
+			 !(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES)))
+		return -EINVAL;
 
 	return fscrypt_crypt_block(inode, FS_DECRYPT, lblk_num, page, page,
 				   len, offs, GFP_NOFS);
-- 
2.21.0.593.g511ec345e18-goog

WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	linux-mtd@lists.infradead.org,
	Chandan Rajendra <chandan@linux.ibm.com>,
	linux-f2fs-devel@lists.sourceforge.net
Subject: [PATCH 04/13] fscrypt: clean up some BUG_ON()s in block encryption/decryption
Date: Wed,  1 May 2019 15:45:06 -0700	[thread overview]
Message-ID: <20190501224515.43059-5-ebiggers@kernel.org> (raw)
In-Reply-To: <20190501224515.43059-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

Replace some BUG_ON()s with WARN_ON_ONCE() and returning an error code,
and move the check for len divisible by FS_CRYPTO_BLOCK_SIZE into
fscrypt_crypt_block() so that it's done for both encryption and
decryption, not just encryption.

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

diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index e6802d7aca3c7..9cda0147fca95 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -161,7 +161,10 @@ int fscrypt_crypt_block(const struct inode *inode, fscrypt_direction_t rw,
 	struct crypto_skcipher *tfm = ci->ci_ctfm;
 	int res = 0;
 
-	BUG_ON(len == 0);
+	if (WARN_ON_ONCE(len <= 0))
+		return -EINVAL;
+	if (WARN_ON_ONCE(len % FS_CRYPTO_BLOCK_SIZE != 0))
+		return -EINVAL;
 
 	fscrypt_generate_iv(&iv, lblk_num, ci);
 
@@ -224,8 +227,6 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
 	struct page *ciphertext_page = page;
 	int err;
 
-	BUG_ON(len % FS_CRYPTO_BLOCK_SIZE != 0);
-
 	if (inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES) {
 		/* with inplace-encryption we just encrypt the page */
 		err = fscrypt_crypt_block(inode, FS_ENCRYPT, lblk_num, page,
@@ -237,7 +238,8 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
 		return ciphertext_page;
 	}
 
-	BUG_ON(!PageLocked(page));
+	if (WARN_ON_ONCE(!PageLocked(page)))
+		return ERR_PTR(-EINVAL);
 
 	/* The encryption operation will require a bounce page. */
 	ciphertext_page = fscrypt_alloc_bounce_page(gfp_flags);
@@ -274,8 +276,9 @@ EXPORT_SYMBOL(fscrypt_encrypt_page);
 int fscrypt_decrypt_page(const struct inode *inode, struct page *page,
 			unsigned int len, unsigned int offs, u64 lblk_num)
 {
-	if (!(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES))
-		BUG_ON(!PageLocked(page));
+	if (WARN_ON_ONCE(!PageLocked(page) &&
+			 !(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES)))
+		return -EINVAL;
 
 	return fscrypt_crypt_block(inode, FS_DECRYPT, lblk_num, page, page,
 				   len, offs, GFP_NOFS);
-- 
2.21.0.593.g511ec345e18-goog


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  parent reply	other threads:[~2019-05-01 22:45 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-01 22:45 [PATCH 00/13] fscrypt, ext4: prepare for blocksize != PAGE_SIZE Eric Biggers
2019-05-01 22:45 ` Eric Biggers
2019-05-01 22:45 ` Eric Biggers
2019-05-01 22:45 ` [f2fs-dev] [PATCH 01/13] fscrypt: simplify bounce page handling Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-02 15:10   ` Chandan Rajendra
2019-05-02 15:10     ` Chandan Rajendra
2019-05-02 15:10     ` Chandan Rajendra
2019-05-01 22:45 ` [PATCH 02/13] fscrypt: remove the "write" part of struct fscrypt_ctx Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-02 15:11   ` Chandan Rajendra
2019-05-02 15:11     ` Chandan Rajendra
2019-05-02 15:11     ` Chandan Rajendra
2019-05-01 22:45 ` [f2fs-dev] [PATCH 03/13] fscrypt: rename fscrypt_do_page_crypto() to fscrypt_crypt_block() Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-02 15:43   ` Chandan Rajendra
2019-05-02 15:43     ` Chandan Rajendra
2019-05-02 15:43     ` Chandan Rajendra
2019-05-01 22:45 ` Eric Biggers [this message]
2019-05-01 22:45   ` [PATCH 04/13] fscrypt: clean up some BUG_ON()s in block encryption/decryption Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-06  8:24   ` [f2fs-dev] " Chandan Rajendra
2019-05-06  8:24     ` Chandan Rajendra
2019-05-06  8:24     ` Chandan Rajendra
2019-05-06  8:24     ` Chandan Rajendra
2019-05-01 22:45 ` [f2fs-dev] [PATCH 05/13] fscrypt: introduce fscrypt_encrypt_block_inplace() Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-06  8:37   ` Chandan Rajendra
2019-05-06  8:37     ` Chandan Rajendra
2019-05-06  8:37     ` Chandan Rajendra
2019-05-01 22:45 ` [PATCH 06/13] fscrypt: support encrypting multiple filesystem blocks per page Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-06  8:38   ` Chandan Rajendra
2019-05-06  8:38     ` Chandan Rajendra
2019-05-01 22:45 ` [f2fs-dev] [PATCH 07/13] fscrypt: handle blocksize < PAGE_SIZE in fscrypt_zeroout_range() Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-06  8:42   ` Chandan Rajendra
2019-05-06  8:42     ` Chandan Rajendra
2019-05-06  8:42     ` Chandan Rajendra
2019-05-01 22:45 ` [PATCH 08/13] fscrypt: introduce fscrypt_decrypt_block_inplace() Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-06  9:01   ` Chandan Rajendra
2019-05-06  9:01     ` Chandan Rajendra
2019-05-01 22:45 ` [PATCH 09/13] fscrypt: support decrypting multiple filesystem blocks per page Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-06  9:09   ` Chandan Rajendra
2019-05-06  9:09     ` Chandan Rajendra
2019-05-06  9:09     ` Chandan Rajendra
2019-05-01 22:45 ` [f2fs-dev] [PATCH 10/13] ext4: clear BH_Uptodate flag on decryption error Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45 ` [PATCH 11/13] ext4: decrypt only the needed blocks in ext4_block_write_begin() Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45 ` [PATCH 12/13] ext4: decrypt only the needed block in __ext4_block_zero_page_range() Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45 ` [PATCH 13/13] ext4: encrypt only up to last block in ext4_bio_write_page() Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-01 22:45   ` Eric Biggers
2019-05-06  9:12   ` Chandan Rajendra
2019-05-06  9:12     ` Chandan Rajendra
2019-05-06  9:12     ` Chandan Rajendra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190501224515.43059-5-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=chandan@linux.ibm.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.