mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 02:32:09 -04:00
loopdev: ignore negative offset when calculate loop device size
Negative offset may cause loop device size larger than backing file size. $ fallocate -l 1M a $ losetup --offset 0xffffffffffff0000 /dev/loop0 a $ blockdev --getsize64 /dev/loop0 1114112 $ ls -l a -rw-r--r-- 1 root root 1048576 Jan 23 12:46 a $ cat /dev/loop0 cat: /dev/loop0: Input/output error It makes no sense to do that. Only apply offset when it's positive. Fix a typo in the comment by the way. Signed-off-by: Guo Chao <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Guo Chao <[email protected]> Cc: M. Hindess <[email protected]> Cc: Nikanth Karthikesan <[email protected]> Cc: Jens Axboe <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
This commit is contained in:
parent
b1a6650406
commit
b7a1da695f
1 changed files with 5 additions and 4 deletions
|
|
@ -162,12 +162,13 @@ static struct loop_func_table *xfer_funcs[MAX_LO_CRYPT] = {
|
|||
|
||||
static loff_t get_size(loff_t offset, loff_t sizelimit, struct file *file)
|
||||
{
|
||||
loff_t size, loopsize;
|
||||
loff_t loopsize;
|
||||
|
||||
/* Compute loopsize in bytes */
|
||||
size = i_size_read(file->f_mapping->host);
|
||||
loopsize = size - offset;
|
||||
/* offset is beyond i_size, wierd but possible */
|
||||
loopsize = i_size_read(file->f_mapping->host);
|
||||
if (offset > 0)
|
||||
loopsize -= offset;
|
||||
/* offset is beyond i_size, weird but possible */
|
||||
if (loopsize < 0)
|
||||
return 0;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue