public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: remove redundant check for encrypted file on dio write path
@ 2017-05-23  0:53 Eric Biggers
  2017-05-23  6:03 ` David Gstir
  2017-05-23  8:24 ` Jan Kara
  0 siblings, 2 replies; 6+ messages in thread
From: Eric Biggers @ 2017-05-23  0:53 UTC (permalink / raw)
  To: linux-ext4; +Cc: Theodore Ts'o, linux-fscrypt, Eric Biggers

From: Eric Biggers <ebiggers@google.com>

Currently we don't allow direct I/O on encrypted regular files, so in
such cases we return 0 early in ext4_direct_IO().  There was also an
additional BUG_ON() check in ext4_direct_IO_write(), but it can never be
hit because of the earlier check for the exact same condition in
ext4_direct_IO().  There was also no matching check on the read path,
which made the write path specific check seem very ad-hoc.

Just remove the unnecessary BUG_ON().

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

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 1bd0bfa547f6..7c6e715b4d2e 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3629,9 +3629,6 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
 		get_block_func = ext4_dio_get_block_unwritten_async;
 		dio_flags = DIO_LOCKING;
 	}
-#ifdef CONFIG_EXT4_FS_ENCRYPTION
-	BUG_ON(ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode));
-#endif
 	ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter,
 				   get_block_func, ext4_end_io_dio, NULL,
 				   dio_flags);
-- 
2.13.0.303.g4ebf302169-goog

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

* Re: [PATCH] ext4: remove redundant check for encrypted file on dio write path
  2017-05-23  0:53 [PATCH] ext4: remove redundant check for encrypted file on dio write path Eric Biggers
@ 2017-05-23  6:03 ` David Gstir
  2017-05-23  8:24 ` Jan Kara
  1 sibling, 0 replies; 6+ messages in thread
From: David Gstir @ 2017-05-23  6:03 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-ext4, Theodore Ts'o, linux-fscrypt, Eric Biggers

Hi Eric,

> On 23 May 2017, at 02:53, Eric Biggers <ebiggers3@gmail.com> wrote:
> 
> From: Eric Biggers <ebiggers@google.com>
> 
> Currently we don't allow direct I/O on encrypted regular files, so in
> such cases we return 0 early in ext4_direct_IO().  There was also an
> additional BUG_ON() check in ext4_direct_IO_write(), but it can never be
> hit because of the earlier check for the exact same condition in
> ext4_direct_IO().  There was also no matching check on the read path,
> which made the write path specific check seem very ad-hoc.
> 
> Just remove the unnecessary BUG_ON().
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> fs/ext4/inode.c | 3 ---
> 1 file changed, 3 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 1bd0bfa547f6..7c6e715b4d2e 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3629,9 +3629,6 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
> 		get_block_func = ext4_dio_get_block_unwritten_async;
> 		dio_flags = DIO_LOCKING;
> 	}
> -#ifdef CONFIG_EXT4_FS_ENCRYPTION
> -	BUG_ON(ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode));
> -#endif
> 	ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter,
> 				   get_block_func, ext4_end_io_dio, NULL,
> 				   dio_flags);
> -- 
> 2.13.0.303.g4ebf302169-goog

LGTM.
Reviewed-by: David Gstir <david@sigma-star.at> 

David

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

* Re: [PATCH] ext4: remove redundant check for encrypted file on dio write path
  2017-05-23  0:53 [PATCH] ext4: remove redundant check for encrypted file on dio write path Eric Biggers
  2017-05-23  6:03 ` David Gstir
@ 2017-05-23  8:24 ` Jan Kara
  2017-05-23 16:13   ` Eric Biggers
  1 sibling, 1 reply; 6+ messages in thread
From: Jan Kara @ 2017-05-23  8:24 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-ext4, Theodore Ts'o, linux-fscrypt, Eric Biggers

On Mon 22-05-17 17:53:16, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Currently we don't allow direct I/O on encrypted regular files, so in
> such cases we return 0 early in ext4_direct_IO().  There was also an
> additional BUG_ON() check in ext4_direct_IO_write(), but it can never be
> hit because of the earlier check for the exact same condition in
> ext4_direct_IO().  There was also no matching check on the read path,
> which made the write path specific check seem very ad-hoc.
> 
> Just remove the unnecessary BUG_ON().
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>

Yeah, the check is rather before the BUG_ON so I guess that there's no big
point in the BUG_ON. When looking at this code I have one question though:

So when you mount the filesystem with 'dioread_nolock', do overwriting
direct write to the file, and just after we do inode_unlock() in
ext4_direct_IO_write() someone calls EXT4_IOC_SET_ENCRYPTION_POLICY ioctl
on the file, the BUG_ON could actually trigger. So I think you need 
to wait for outstanding direct IO for the file when setting encryption
policy. Likely in ext4_set_context() or maybe in the generic fscrypt code
(you need to wait after acquiring inode_lock), I'm not sure how other
filesystems using fscrypt handle this and whether it would make more sense
in the generic code or in ext4 specific one.

								Honza

> ---
>  fs/ext4/inode.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 1bd0bfa547f6..7c6e715b4d2e 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3629,9 +3629,6 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
>  		get_block_func = ext4_dio_get_block_unwritten_async;
>  		dio_flags = DIO_LOCKING;
>  	}
> -#ifdef CONFIG_EXT4_FS_ENCRYPTION
> -	BUG_ON(ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode));
> -#endif
>  	ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter,
>  				   get_block_func, ext4_end_io_dio, NULL,
>  				   dio_flags);
> -- 
> 2.13.0.303.g4ebf302169-goog
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] ext4: remove redundant check for encrypted file on dio write path
  2017-05-23  8:24 ` Jan Kara
@ 2017-05-23 16:13   ` Eric Biggers
  2017-05-24  8:10     ` Jan Kara
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Biggers @ 2017-05-23 16:13 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, Theodore Ts'o, linux-fscrypt, Eric Biggers

Hi Jan,

On Tue, May 23, 2017 at 10:24:10AM +0200, Jan Kara wrote:
> On Mon 22-05-17 17:53:16, Eric Biggers wrote:
> > From: Eric Biggers <ebiggers@google.com>
> > 
> > Currently we don't allow direct I/O on encrypted regular files, so in
> > such cases we return 0 early in ext4_direct_IO().  There was also an
> > additional BUG_ON() check in ext4_direct_IO_write(), but it can never be
> > hit because of the earlier check for the exact same condition in
> > ext4_direct_IO().  There was also no matching check on the read path,
> > which made the write path specific check seem very ad-hoc.
> > 
> > Just remove the unnecessary BUG_ON().
> > 
> > Signed-off-by: Eric Biggers <ebiggers@google.com>
> 
> Yeah, the check is rather before the BUG_ON so I guess that there's no big
> point in the BUG_ON. When looking at this code I have one question though:
> 
> So when you mount the filesystem with 'dioread_nolock', do overwriting
> direct write to the file, and just after we do inode_unlock() in
> ext4_direct_IO_write() someone calls EXT4_IOC_SET_ENCRYPTION_POLICY ioctl
> on the file, the BUG_ON could actually trigger. So I think you need 
> to wait for outstanding direct IO for the file when setting encryption
> policy. Likely in ext4_set_context() or maybe in the generic fscrypt code
> (you need to wait after acquiring inode_lock), I'm not sure how other
> filesystems using fscrypt handle this and whether it would make more sense
> in the generic code or in ext4 specific one.
> 

That's not possible because the ioctl can only set an encryption policy on a
directory, and specifically an empty one.  Other files can only acquire an
encryption policy through inheritance.  There have been thoughts about
implementing "in-place" encryption but it's not something we currently support.

Eric

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

* Re: [PATCH] ext4: remove redundant check for encrypted file on dio write path
  2017-05-23 16:13   ` Eric Biggers
@ 2017-05-24  8:10     ` Jan Kara
  2017-05-24 22:21       ` Theodore Ts'o
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Kara @ 2017-05-24  8:10 UTC (permalink / raw)
  To: Eric Biggers
  Cc: Jan Kara, linux-ext4, Theodore Ts'o, linux-fscrypt,
	Eric Biggers

On Tue 23-05-17 09:13:54, Eric Biggers wrote:
> Hi Jan,
> 
> On Tue, May 23, 2017 at 10:24:10AM +0200, Jan Kara wrote:
> > On Mon 22-05-17 17:53:16, Eric Biggers wrote:
> > > From: Eric Biggers <ebiggers@google.com>
> > > 
> > > Currently we don't allow direct I/O on encrypted regular files, so in
> > > such cases we return 0 early in ext4_direct_IO().  There was also an
> > > additional BUG_ON() check in ext4_direct_IO_write(), but it can never
> > > be hit because of the earlier check for the exact same condition in
> > > ext4_direct_IO().  There was also no matching check on the read path,
> > > which made the write path specific check seem very ad-hoc.
> > > 
> > > Just remove the unnecessary BUG_ON().
> > > 
> > > Signed-off-by: Eric Biggers <ebiggers@google.com>
> > 
> > Yeah, the check is rather before the BUG_ON so I guess that there's no
> > big point in the BUG_ON. When looking at this code I have one question
> > though:
> > 
> > So when you mount the filesystem with 'dioread_nolock', do overwriting
> > direct write to the file, and just after we do inode_unlock() in
> > ext4_direct_IO_write() someone calls EXT4_IOC_SET_ENCRYPTION_POLICY
> > ioctl on the file, the BUG_ON could actually trigger. So I think you
> > need to wait for outstanding direct IO for the file when setting
> > encryption policy. Likely in ext4_set_context() or maybe in the generic
> > fscrypt code (you need to wait after acquiring inode_lock), I'm not
> > sure how other filesystems using fscrypt handle this and whether it
> > would make more sense in the generic code or in ext4 specific one.
> > 
> 
> That's not possible because the ioctl can only set an encryption policy
> on a directory, and specifically an empty one.  Other files can only
> acquire an encryption policy through inheritance.  There have been
> thoughts about implementing "in-place" encryption but it's not something
> we currently support.

Ah, good. Thanks for explanation. Then you can add:

Reviewed-by: Jan Kara <jack@suse.cz>

to your patch.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] ext4: remove redundant check for encrypted file on dio write path
  2017-05-24  8:10     ` Jan Kara
@ 2017-05-24 22:21       ` Theodore Ts'o
  0 siblings, 0 replies; 6+ messages in thread
From: Theodore Ts'o @ 2017-05-24 22:21 UTC (permalink / raw)
  To: Jan Kara; +Cc: Eric Biggers, linux-ext4, linux-fscrypt, Eric Biggers

Thanks, applied.

					- Ted

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

end of thread, other threads:[~2017-05-24 22:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-23  0:53 [PATCH] ext4: remove redundant check for encrypted file on dio write path Eric Biggers
2017-05-23  6:03 ` David Gstir
2017-05-23  8:24 ` Jan Kara
2017-05-23 16:13   ` Eric Biggers
2017-05-24  8:10     ` Jan Kara
2017-05-24 22:21       ` 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