Skip to content

Commit

Permalink
block: Invalidate cache on discard v2
Browse files Browse the repository at this point in the history
It is reasonable drop page cache on discard, otherwise that pages may
be written by writeback second later, so thin provision devices will
not be happy. This seems to be a  security leak in case of secure discard case.

Also add check for queue_discard flag on early stage.

Signed-off-by: Dmitry Monakhov <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Dmitry Monakhov authored and axboe committed Oct 25, 2017
1 parent 75bc5f0 commit 351499a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions block/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,16 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
{
uint64_t range[2];
uint64_t start, len;
struct request_queue *q = bdev_get_queue(bdev);
struct address_space *mapping = bdev->bd_inode->i_mapping;


if (!(mode & FMODE_WRITE))
return -EBADF;

if (!blk_queue_discard(q))
return -EOPNOTSUPP;

if (copy_from_user(range, (void __user *)arg, sizeof(range)))
return -EFAULT;

Expand All @@ -216,12 +222,12 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
return -EINVAL;
if (len & 511)
return -EINVAL;
start >>= 9;
len >>= 9;

if (start + len > (i_size_read(bdev->bd_inode) >> 9))
if (start + len > i_size_read(bdev->bd_inode))
return -EINVAL;
return blkdev_issue_discard(bdev, start, len, GFP_KERNEL, flags);
truncate_inode_pages_range(mapping, start, start + len);
return blkdev_issue_discard(bdev, start >> 9, len >> 9,
GFP_KERNEL, flags);
}

static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode,
Expand Down

0 comments on commit 351499a

Please sign in to comment.