mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2024-12-28 16:53:49 +00:00
block: Don't allow an atomic write be truncated in blkdev_write_iter()
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: caf336f81b
("block: Add fops atomic write support")
Signed-off-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20241127092318.632790-1-john.g.garry@oracle.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
1b0cab327e
commit
2cbd51f1f8
@ -677,6 +677,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
|||||||
struct file *file = iocb->ki_filp;
|
struct file *file = iocb->ki_filp;
|
||||||
struct inode *bd_inode = bdev_file_inode(file);
|
struct inode *bd_inode = bdev_file_inode(file);
|
||||||
struct block_device *bdev = I_BDEV(bd_inode);
|
struct block_device *bdev = I_BDEV(bd_inode);
|
||||||
|
bool atomic = iocb->ki_flags & IOCB_ATOMIC;
|
||||||
loff_t size = bdev_nr_bytes(bdev);
|
loff_t size = bdev_nr_bytes(bdev);
|
||||||
size_t shorted = 0;
|
size_t shorted = 0;
|
||||||
ssize_t ret;
|
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)
|
if ((iocb->ki_flags & (IOCB_NOWAIT | IOCB_DIRECT)) == IOCB_NOWAIT)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
if (iocb->ki_flags & IOCB_ATOMIC) {
|
if (atomic) {
|
||||||
ret = generic_atomic_write_valid(iocb, from);
|
ret = generic_atomic_write_valid(iocb, from);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
@ -704,6 +705,8 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
|||||||
|
|
||||||
size -= iocb->ki_pos;
|
size -= iocb->ki_pos;
|
||||||
if (iov_iter_count(from) > size) {
|
if (iov_iter_count(from) > size) {
|
||||||
|
if (atomic)
|
||||||
|
return -EINVAL;
|
||||||
shorted = iov_iter_count(from) - size;
|
shorted = iov_iter_count(from) - size;
|
||||||
iov_iter_truncate(from, size);
|
iov_iter_truncate(from, size);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user