linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Don't allow an atomic write be truncated in blkdev_write_iter()
@ 2024-11-27  9:23 John Garry
  2024-11-27  9:31 ` Christoph Hellwig
  2024-11-27 22:05 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: John Garry @ 2024-11-27  9:23 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, hare, hch, martin.petersen, John Garry

A write which goes past the end of the bdev in blkdev_write_iter() will
be truncated. Truncating cannot tolerated for an atomic write, so error
that condition.

Fixes: caf336f81b3a ("block: Add fops atomic write support")
Signed-off-by: John Garry <john.g.garry@oracle.com>

diff --git a/block/fops.c b/block/fops.c
index 2d01c9007681..13a67940d040 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -677,6 +677,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	struct file *file = iocb->ki_filp;
 	struct inode *bd_inode = bdev_file_inode(file);
 	struct block_device *bdev = I_BDEV(bd_inode);
+	bool atomic = iocb->ki_flags & IOCB_ATOMIC;
 	loff_t size = bdev_nr_bytes(bdev);
 	size_t shorted = 0;
 	ssize_t ret;
@@ -696,7 +697,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	if ((iocb->ki_flags & (IOCB_NOWAIT | IOCB_DIRECT)) == IOCB_NOWAIT)
 		return -EOPNOTSUPP;
 
-	if (iocb->ki_flags & IOCB_ATOMIC) {
+	if (atomic) {
 		ret = generic_atomic_write_valid(iocb, from);
 		if (ret)
 			return ret;
@@ -704,6 +705,8 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
 
 	size -= iocb->ki_pos;
 	if (iov_iter_count(from) > size) {
+		if (atomic)
+			return -EINVAL;
 		shorted = iov_iter_count(from) - size;
 		iov_iter_truncate(from, size);
 	}
-- 
2.31.1


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

* Re: [PATCH] block: Don't allow an atomic write be truncated in blkdev_write_iter()
  2024-11-27  9:23 [PATCH] block: Don't allow an atomic write be truncated in blkdev_write_iter() John Garry
@ 2024-11-27  9:31 ` Christoph Hellwig
  2024-11-27 22:05 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2024-11-27  9:31 UTC (permalink / raw)
  To: John Garry; +Cc: axboe, linux-block, hare, hch, martin.petersen

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


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

* Re: [PATCH] block: Don't allow an atomic write be truncated in blkdev_write_iter()
  2024-11-27  9:23 [PATCH] block: Don't allow an atomic write be truncated in blkdev_write_iter() John Garry
  2024-11-27  9:31 ` Christoph Hellwig
@ 2024-11-27 22:05 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2024-11-27 22:05 UTC (permalink / raw)
  To: John Garry; +Cc: linux-block, hare, hch, martin.petersen


On Wed, 27 Nov 2024 09:23:18 +0000, John Garry wrote:
> A write which goes past the end of the bdev in blkdev_write_iter() will
> be truncated. Truncating cannot tolerated for an atomic write, so error
> that condition.
> 
> 

Applied, thanks!

[1/1] block: Don't allow an atomic write be truncated in blkdev_write_iter()
      commit: 2cbd51f1f8739fd2fdf4bae1386bcf75ce0176ba

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2024-11-27 22:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-27  9:23 [PATCH] block: Don't allow an atomic write be truncated in blkdev_write_iter() John Garry
2024-11-27  9:31 ` Christoph Hellwig
2024-11-27 22:05 ` Jens Axboe

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).