Staging: zram: Fix access of NULL pointer
Subsystems (2)
PATCH v5 1/3 Staging: zram: Fix access of NULL pointer
In reply to a message not in the archiveThis patch fixes the bug in reset_store caused by accessing NULL pointer. Hence, It introduces a check for bdev. It also removes unnecessary check of bdev for fsync_bdev().
---
This revision fixes the following issues of the previous revision- Seperate patch into Bug Fix and Smatch Fix
drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/zram/zram_drv.c +4 -2
@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); +if (!bdev) +return -EBUSY ; +/* Do not reset an active device! */ if (bdev->bd_holders)return -EBUSY ;
@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev,return -EINVAL ;/* Make sure all pending I/O is finished */ -if (bdev) -fsync_bdev (bdev); +fsync_bdev (bdev);zram_reset_device (zram, true);return len;
Signature · 1 line
1.7.9.5
PATCH v5 3/3 Staging: zram: Fix decrement of variable by calling bdput()
In reply to a message not in the archiveAs suggested by Jerome Marchand "The code in reset_store get the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefor incremented but never decremented."
Hence, this patch introduces a call to bdput() to decrement the variable after usage.
--- drivers/staging/zram/zram_drv.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/zram/zram_drv.c +1 -0
@@ -664,6 +664,7 @@ static ssize_t reset_store(struct device *dev,/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev);zram_reset_device (zram, true);return len;
Signature · 1 line
1.7.9.5
PATCH v5 2/3 Staging: zram: Fix variable dereferenced before check
In reply to a message not in the archiveThis patch fixes the following Smatch warning in zram_drv.c- drivers/staging/zram/zram_drv.c:899destroy_device() warn: variable dereferenced before check 'zram->disk' (see line 896)
---
This revision fixes the following issues of the previous revision- Seperating patches into Bug fix and Smatch fix
drivers/staging/zram/zram_drv.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/zram/zram_drv.c +3 -6
@@ -898,13 +898,10 @@ static void destroy_device(struct zram *zram)sysfs_remove_group (&disk_to_dev (zram->disk)->kobj, &zram_disk_attr_group); -if (zram->disk) { -del_gendisk (zram->disk); -put_disk (zram->disk); - } +del_gendisk (zram->disk); +put_disk (zram->disk); -if (zram->queue) -blk_cleanup_queue (zram->queue); +blk_cleanup_queue (zram->queue); }static int __init zram_init (void )
Signature · 1 line
1.7.9.5
PATCH v6 1/3 Staging: zram: Fix access of NULL pointer
In reply to a message not in the archiveThis patch fixes the bug in reset_store caused by accessing NULL pointer. Hence, It introduces a check for bdev. It also removes unnecessary check of bdev for fsync_bdev().
---
This revision fixes the following issues of the previous revision- Seperating patches into Bug fix and Smatch fix
drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/zram/zram_drv.c +4 -2
@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); +if (!bdev) +return -EBUSY ; +/* Do not reset an active device! */ if (bdev->bd_holders)return -EBUSY ;
@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev,return -EINVAL ;/* Make sure all pending I/O is finished */ -if (bdev) -fsync_bdev (bdev); +fsync_bdev (bdev);zram_reset_device (zram, true);return len;
Signature · 1 line
1.7.9.5
PATCH v6 2/3 Staging: zram: Fix variable dereferenced before check
In reply to a message not in the archiveThis patch fixes the following Smatch warning in zram_drv.c- drivers/staging/zram/zram_drv.c:899destroy_device() warn: variable dereferenced before check 'zram->disk' (see line 896)
---
This revision fixes the following issues of the previous revision- Seperating patches into Bug fix and Smatch fix
drivers/staging/zram/zram_drv.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/zram/zram_drv.c +3 -6
@@ -898,13 +898,10 @@ static void destroy_device(struct zram *zram)sysfs_remove_group (&disk_to_dev (zram->disk)->kobj, &zram_disk_attr_group); -if (zram->disk) { -del_gendisk (zram->disk); -put_disk (zram->disk); - } +del_gendisk (zram->disk); +put_disk (zram->disk); -if (zram->queue) -blk_cleanup_queue (zram->queue); +blk_cleanup_queue (zram->queue); }static int __init zram_init (void )
Signature · 1 line
1.7.9.5
PATCH v6 3/3 Staging: zram: Fix decrement of variable by calling bdput()
In reply to a message not in the archiveAs suggested by Jerome Marchand "The code in reset_store get the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefor incremented but never decremented."
Hence, this patch introduces a call to bdput() to decrement the variable after usage.
--- drivers/staging/zram/zram_drv.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/zram/zram_drv.c +1 -0
@@ -664,6 +664,7 @@ static ssize_t reset_store(struct device *dev,/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev);zram_reset_device (zram, true);return len;
Signature · 1 line
1.7.9.5
Quoted 18 lines · Rashika Kheria
This patch fixes the bug in
reset_storecaused by accessing NULL pointer. Hence, It introduces a check for bdev. It also removes unnecessary check of bdev forfsync_bdev().Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issues of the previous revision- Seperating patches into Bug fix and Smatch fix
drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/staging/zram/zram_drv.c +0
-0
drivers/staging/zram/zram_drv.c static ssize_t reset_store(struct device *dev, · line 653
Quoted 6 lines
drivers/staging/zram/zram_drv.c +3
-0@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); +if (!bdev) +return -EBUSY ; +
I am not sure how does it happen. Would you please make it clear to me?
Thanks
Quoted 21 lines
drivers/staging/zram/zram_drv.c +1
-3/* Do not reset an active device! */ if (bdev->bd_holders)return -EBUSY ;@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev,return -EINVAL ;/* Make sure all pending I/O is finished */ -if (bdev) -fsync_bdev (bdev); +fsync_bdev (bdev);zram_reset_device (zram, true);return len; --1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 38 lines · Rashika Kheria
Quoted 26 lines · Weijie Yang
Quoted 23 lines · Rashika Kheria
This patch fixes the bug in
reset_storecaused by accessing NULL pointer.
Hence, It introduces a check for bdev. It also removes unnecessary check of bdev forfsync_bdev().Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issues of the previous revision- Seperating patches into Bug fix and Smatch fix
drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/staging/zram/zram_drv.c +0
-0@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 );Quoted 6 lines
drivers/staging/zram/zram_drv.c static ssize_t reset_store(struct device *dev, · line 653
Quoted 3 lines
drivers/staging/zram/zram_drv.c +3
-0+if (!bdev) +return -EBUSY ; +I am not sure how does it happen. Would you please make it clear to me?
Quoted 7 lines
Hi Weijie,
The bdev gets its value from
bdget_disk()which could fail when memory is less available and hence bdev can be NULL.If this check is not introduced then we might reference NULL pointer in the later part of the code.
I see. Thanks!
Quoted 8 lines
I hope I am clear.
Thanks,
--
Rashika Kheria
B.Tech CSE
IIIT Hyderabad
Hello Rashika,
Quoted 3 lines · Rashika Kheria
This patch fixes the bug in
reset_storecaused by accessing NULL pointer. Hence, It introduces a check for bdev. It also removes unnecessary check of bdev forfsync_bdev().
It's better than old but I still want it more better.
First of all, I hope patch description is more clear in case of bugfix patch because other maintainers from stable/distro or other people could understand well so they could judge once again whether they need to backport or not. If maintainer judge that it's not severe, even they couldn't backport.
Patch description includes followin as, at least.
1. When this bug happens?
2. What's the result of user POV?
3. How to fix it.
You were good for 2 and 3 but 1
I can help.
If memory pressure is severe, inode could be reclaimed. In this case, bdget_disk can return NULL because allocation of inode in bdget could fail.
I hope you could do better massage.
In addition, this bug have been for a long time so it deserves backporting to stable tree. In such case, you could Cc stable tree with stable mark. Please refer Documentation/stable_kernel_rules.txt and others patches in LKML.
After this year kernel summit, it seems to change something rule for marking stable but I thinks it's not solid so old rule still would be valid.
Thanks!
Quoted 42 lines
Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issues of the previous revision- Seperating patches into Bug fix and Smatch fix
drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/staging/zram/zram_drv.c +4
-2@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); +if (!bdev) +return -EBUSY ; +/* Do not reset an active device! */ if (bdev->bd_holders)return -EBUSY ;@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev,return -EINVAL ;/* Make sure all pending I/O is finished */ -if (bdev) -fsync_bdev (bdev); +fsync_bdev (bdev);zram_reset_device (zram, true);return len;Signature · 7 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Kind regards, Minchan Kim
Re: [PATCH v6 2/3] Staging: zram: Fix variable dereferenced before check
In reply to Rashika KheriaQuoted 5 lines · Rashika Kheria
This patch fixes the following Smatch warning in zram_drv.c-
drivers/staging/zram/zram_drv.c:899destroy_device()warn: variable dereferenced before check 'zram->disk' (see line 896)Signed-off-by Rashika Kheria <[email protected]>
Signature · 2 lines
Kind regards, Minchan Kim
Re: [PATCH v6 3/3] Staging: zram: Fix decrement of variable by calling bdput()
In reply to Rashika KheriaQuoted 7 lines · Rashika Kheria
As suggested by Jerome Marchand "The code in
reset_storeget the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefor incremented but never decremented."Hence, this patch introduces a call to
bdput()to decrement the variable after usage.Signed-off-by Rashika Kheria <[email protected]>
I think this patch is for stable, too.
So, please read my previous reply.
And please relocate this with [2/3] and do bdput in all of error cases in reset_store.
Quoted 24 lines
--- drivers/staging/zram/zram_drv.c | 1 + 1 file changed, 1 insertion(+)drivers/staging/zram/zram_drv.c +1
-0@@ -664,6 +664,7 @@ static ssize_t reset_store(struct device *dev,/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev);zram_reset_device (zram, true);return len;Signature · 7 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Kind regards, Minchan Kim
PATCH v7 1/3 Staging: zram: Fix access of NULL pointer
In reply to a message not in the archiveThis patch fixes the bug in reset_store caused by accessing NULL pointer.
The bdev gets its value from bdget_disk() which could fail when memory pressure is severe and hence can return NULL because allocation of inode in bdget could fail.
Hence, this patch introduces a check for bdev to prevent reference to a NULL pointer in the later part of the code. It also removes unnecessary check of bdev for fsync_bdev().
---
This patch fixes the following issues of the previous revision- Better Description
drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/zram/zram_drv.c +4 -2
@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); +if (!bdev) +return -EBUSY ; +/* Do not reset an active device! */ if (bdev->bd_holders)return -EBUSY ;
@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev,return -EINVAL ;/* Make sure all pending I/O is finished */ -if (bdev) -fsync_bdev (bdev); +fsync_bdev (bdev);zram_reset_device (zram, true);return len;
Signature · 1 line
1.7.9.5
PATCH v7 2/3 Staging: zram: Fix decrement of variable by calling bdput()
In reply to a message not in the archiveAs suggested by Jerome Marchand "The code in reset_store get the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefor incremented but never decremented."
Hence, this patch introduces a call to bdput() to decrement the variable after usage.
---
This revision fixes the following issues of the previous revision- Handle more error cases
drivers/staging/zram/zram_drv.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/staging/zram/zram_drv.c +3 -0
@@ -664,6 +664,9 @@ static ssize_t reset_store(struct device *dev,/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev); +bdput (bdev->bd_holders); +bdput (do_reset);zram_reset_device (zram, true);return len;
Signature · 1 line
1.7.9.5
PATCH v7 3/3 Staging: zram: Fix variable dereferenced before check
In reply to a message not in the archiveThis patch fixes the following Smatch warning in zram_drv.c- drivers/staging/zram/zram_drv.c:899destroy_device() warn: variable dereferenced before check 'zram->disk' (see line 896)
--- drivers/staging/zram/zram_drv.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/zram/zram_drv.c +3 -6
@@ -901,13 +901,10 @@ static void destroy_device(struct zram *zram)sysfs_remove_group (&disk_to_dev (zram->disk)->kobj, &zram_disk_attr_group); -if (zram->disk) { -del_gendisk (zram->disk); -put_disk (zram->disk); - } +del_gendisk (zram->disk); +put_disk (zram->disk); -if (zram->queue) -blk_cleanup_queue (zram->queue); +blk_cleanup_queue (zram->queue); }static int __init zram_init (void )
Signature · 1 line
1.7.9.5
Quoted 6 lines · Rashika Kheria
This patch fixes the bug in
reset_storecaused by accessing NULL pointer.The bdev gets its value from
bdget_disk()which could fail when memory pressure is severe and hence can return NULL because allocation of inode in bdget could fail.
Quoted 6 lines
Hence, this patch introduces a check for bdev to prevent reference to a NULL pointer in the later part of the code. It also removes unnecessary check of bdev for
fsync_bdev().Signed-off-by Rashika Kheria <[email protected]>
Signature · 2 lines
Kind regards, Minchan Kim
Re: [PATCH v7 2/3] Staging: zram: Fix decrement of variable by calling bdput()
In reply to Rashika KheriaQuoted 21 lines · Rashika Kheria
As suggested by Jerome Marchand "The code in
reset_storeget the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefor incremented but never decremented."Hence, this patch introduces a call to
bdput()to decrement the variable after usage.Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issues of the previous revision- Handle more error cases
drivers/staging/zram/zram_drv.c | 3 +++ 1 file changed, 3 insertions(+)drivers/staging/zram/zram_drv.c +0
-0
drivers/staging/zram/zram_drv.c static ssize_t reset_store(struct device *dev, · line 669
Quoted 6 lines
drivers/staging/zram/zram_drv.c +3
-0@@ -664,6 +664,9 @@ static ssize_t reset_store(struct device *dev,/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev); +bdput (bdev->bd_holders); +bdput (do_reset);
I meant it.
drivers/staging/zram/zram_drv.c +15 -7
@@ -621,22 +621,30 @@ static ssize_t reset_store(struct device *dev, bdev =bdget_disk (zram->disk,0 );/* Do not reset an active device! */ -if (bdev->bd_holders) -return -EBUSY ; +if (bdev->bd_holders) { + ret = -EBUSY ; + goto out; + } ret =kstrtou16 (buf,10 , &do_reset);if (ret) -return ret; + goto out; -if (!do_reset) -return -EINVAL ; +if (!do_reset) { + ret = -EINVAL ; + goto out; + }/* Make sure all pending I/O is finished */ -if (bdev) -fsync_bdev (bdev); +fsync_bdev (bdev); +bdput (bdev);zram_reset_device (zram);return len; + +out: +bdput (bdev); +return ret; }static void __zram_make_request (struct zram *zram,struct bio *bio,int rw)
Signature · 2 lines
Kind regards, Minchan Kim
Re: [PATCH v7 3/3] Staging: zram: Fix variable dereferenced before check
In reply to Rashika KheriaQuoted 5 lines · Rashika Kheria
This patch fixes the following Smatch warning in zram_drv.c-
drivers/staging/zram/zram_drv.c:899destroy_device()warn: variable dereferenced before check 'zram->disk' (see line 896)
It shouldn't be a stable stuff because it's just warning of Smatch but there is no bug in real practice.
Quoted 35 lines
Acked-by Minchan Kim <[email protected]>Signed-off-by Rashika Kheria <[email protected]>--- drivers/staging/zram/zram_drv.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/staging/zram/zram_drv.c +3
-6@@ -901,13 +901,10 @@ static void destroy_device(struct zram *zram)sysfs_remove_group (&disk_to_dev (zram->disk)->kobj, &zram_disk_attr_group); -if (zram->disk) { -del_gendisk (zram->disk); -put_disk (zram->disk); - } +del_gendisk (zram->disk); +put_disk (zram->disk); -if (zram->queue) -blk_cleanup_queue (zram->queue); +blk_cleanup_queue (zram->queue); }static int __init zram_init (void )Signature · 7 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Kind regards, Minchan Kim
Quoted 25 lines · Rashika Kheria
This patch fixes the bug in
reset_storecaused by accessing NULL pointer.The bdev gets its value from
bdget_disk()which could fail when memory pressure is severe and hence can return NULL because allocation of inode in bdget could fail.Hence, this patch introduces a check for bdev to prevent reference to a NULL pointer in the later part of the code. It also removes unnecessary check of bdev for
fsync_bdev().Signed-off-by Rashika Kheria <[email protected]>---
This patch fixes the following issues of the previous revision- Better Description
drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/staging/zram/zram_drv.c +0
-0
drivers/staging/zram/zram_drv.c static ssize_t reset_store(struct device *dev, · line 653
Quoted 6 lines
drivers/staging/zram/zram_drv.c +3
-0@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); +if (!bdev) +return -EBUSY ; +
Oops, Sorry.
I don't think EBUSY is right. How about ENOMEM?
Signature · 2 lines
Kind regards, Minchan Kim
Quoted 6 lines · Rashika Kheria
This patch fixes the bug in
reset_storecaused by accessing NULL pointer.The bdev gets its value from
bdget_disk()which could fail when memory pressure is severe and hence can return NULL because allocation of inode in bdget could fail.
Quoted 6 lines
Hence, this patch introduces a check for bdev to prevent reference to a NULL pointer in the later part of the code. It also removes unnecessary check of bdev for
fsync_bdev().Signed-off-by Rashika Kheria <[email protected]>
Quoted 33 lines
---
This patch fixes the following issues of the previous revision- Better Description
drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/staging/zram/zram_drv.c +4
-2@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); +if (!bdev) +return -EBUSY ; +/* Do not reset an active device! */ if (bdev->bd_holders)return -EBUSY ;@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev,return -EINVAL ;/* Make sure all pending I/O is finished */ -if (bdev) -fsync_bdev (bdev); +fsync_bdev (bdev);zram_reset_device (zram, true);return len;
Re: [PATCH v7 3/3] Staging: zram: Fix variable dereferenced before check
In reply to Rashika KheriaQuoted 7 lines · Rashika Kheria
This patch fixes the following Smatch warning in zram_drv.c-
drivers/staging/zram/zram_drv.c:899destroy_device()warn: variable dereferenced before check 'zram->disk' (see line 896)Acked-by Minchan Kim <[email protected]>Signed-off-by Rashika Kheria <[email protected]>
Quoted 26 lines
--- drivers/staging/zram/zram_drv.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)drivers/staging/zram/zram_drv.c +3
-6@@ -901,13 +901,10 @@ static void destroy_device(struct zram *zram)sysfs_remove_group (&disk_to_dev (zram->disk)->kobj, &zram_disk_attr_group); -if (zram->disk) { -del_gendisk (zram->disk); -put_disk (zram->disk); - } +del_gendisk (zram->disk); +put_disk (zram->disk); -if (zram->queue) -blk_cleanup_queue (zram->queue); +blk_cleanup_queue (zram->queue); }static int __init zram_init (void )
PATCH v8 1/3 Staging: zram: Fix access of NULL pointer
In reply to a message not in the archiveThis patch fixes the bug in reset_store caused by accessing NULL pointer.
The bdev gets its value from bdget_disk() which could fail when memory pressure is severe and hence can return NULL because allocation of inode in bdget could fail.
Hence, this patch introduces a check for bdev to prevent reference to a NULL pointer in the later part of the code. It also removes unnecessary check of bdev for fsync_bdev().
---
The previous revision fixes the following issues of the previous revision- Change return error code
drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/zram/zram_drv.c +4 -2
@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); +if (!bdev) +return -ENOMEM ; +/* Do not reset an active device! */ if (bdev->bd_holders)return -EBUSY ;
@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev,return -EINVAL ;/* Make sure all pending I/O is finished */ -if (bdev) -fsync_bdev (bdev); +fsync_bdev (bdev);zram_reset_device (zram, true);return len;
Signature · 1 line
1.7.9.5
PATCH v8 2/3 Staging: zram: Fix decrement of variable by calling bdput()
In reply to a message not in the archiveAs suggested by Jerome Marchand "The code in reset_store get the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."
This patch also puts bdput() for all error cases.
---
This revision fixes the following issues of the previous revision- Proper error handling
drivers/staging/zram/zram_drv.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
drivers/staging/zram/zram_drv.c +18 -7
@@ -648,25 +648,36 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); -if (!bdev) -return -ENOMEM ; +if (!bdev) { + ret = -ENOMEM ; + goto out; + }/* Do not reset an active device! */ -if (bdev->bd_holders) -return -EBUSY ; +if (bdev->bd_holders) { + ret = -EBUSY ; + goto out; + } ret =kstrtou16 (buf,10 , &do_reset);if (ret) -return ret; + goto out; -if (!do_reset) -return -EINVAL ; +if (!do_reset) { + ret = -EINVAL ; + goto out; + }/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev);zram_reset_device (zram, true);return len; + +out: +bdput (bdev); +return ret; }static void __zram_make_request (struct zram *zram,struct bio *bio,int rw)
Signature · 1 line
1.7.9.5
PATCH v8 3/3 Staging: zram: Fix variable dereferenced before check
In reply to a message not in the archiveThis patch fixes the following Smatch warning in zram_drv.c- drivers/staging/zram/zram_drv.c:899destroy_device() warn: variable dereferenced before check 'zram->disk' (see line 896)
---
This revision fixes the following issues of the previous revision- Removes Cc to [email protected] as it is just a Smatch warning fix
drivers/staging/zram/zram_drv.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/zram/zram_drv.c +3 -6
@@ -909,13 +909,10 @@ static void destroy_device(struct zram *zram)sysfs_remove_group (&disk_to_dev (zram->disk)->kobj, &zram_disk_attr_group); -if (zram->disk) { -del_gendisk (zram->disk); -put_disk (zram->disk); - } +del_gendisk (zram->disk); +put_disk (zram->disk); -if (zram->queue) -blk_cleanup_queue (zram->queue); +blk_cleanup_queue (zram->queue); }static int __init zram_init (void )
Signature · 1 line
1.7.9.5
Re: [PATCH v8 3/3] Staging: zram: Fix variable dereferenced before check
Quoted 11 lines · Rashika Kheria
This patch fixes the following Smatch warning in zram_drv.c-
drivers/staging/zram/zram_drv.c:899destroy_device()warn: variable dereferenced before check 'zram->disk' (see line 896)Acked-by Minchan Kim <[email protected]>Acked-by Jerome Marchand <[email protected]>Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issues of the previous revision- Removes Cc to [email protected] as it is just a Smatch warning fix
Applied, thanks.
greg k-h
Re: [PATCH v8 2/3] Staging: zram: Fix decrement of variable by calling bdput()
In reply to Rashika KheriaHello, Rashika
Quoted 21 lines · Rashika Kheria
As suggested by Jerome Marchand "The code in
reset_storeget the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."This patch also puts
bdput()for all error cases.Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issues of the previous revision- Proper error handling
drivers/staging/zram/zram_drv.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)drivers/staging/zram/zram_drv.c +0
-0
drivers/staging/zram/zram_drv.c static ssize_t reset_store(struct device *dev, · line 654
Quoted 9 lines
drivers/staging/zram/zram_drv.c +4
-2@@ -648,25 +648,36 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); -if (!bdev) -return -ENOMEM ; +if (!bdev) { + ret = -ENOMEM ; + goto out; + }
If bdev is NULL, just return -ENOMEM; DO NOT goto out; or you will get a NULL point reference in bdput(bdev);
Quoted 41 lines
drivers/staging/zram/zram_drv.c +14
-6/* Do not reset an active device! */ -if (bdev->bd_holders) -return -EBUSY ; +if (bdev->bd_holders) { + ret = -EBUSY ; + goto out; + } ret =kstrtou16 (buf,10 , &do_reset);if (ret) -return ret; + goto out; -if (!do_reset) -return -EINVAL ; +if (!do_reset) { + ret = -EINVAL ; + goto out; + }/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev);zram_reset_device (zram, true);return len; + +out: +bdput (bdev); +return ret; }static void __zram_make_request (struct zram *zram,struct bio *bio,int rw) --1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
PATCH v9 1/2 Staging: zram: Fix access of NULL pointer
In reply to a message not in the archiveThis patch fixes the bug in reset_store caused by accessing NULL pointer.
The bdev gets its value from bdget_disk() which could fail when memory pressure is severe and hence can return NULL because allocation of inode in bdget could fail.
Hence, this patch introduces a check for bdev to prevent reference to a NULL pointer in the later part of the code. It also removes unnecessary check of bdev for fsync_bdev().
--- drivers/staging/zram/zram_drv.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/zram/zram_drv.c +4 -2
@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, zram =dev_to_zram (dev); bdev =bdget_disk (zram->disk,0 ); +if (!bdev) +return -ENOMEM ; +/* Do not reset an active device! */ if (bdev->bd_holders)return -EBUSY ;
@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev,return -EINVAL ;/* Make sure all pending I/O is finished */ -if (bdev) -fsync_bdev (bdev); +fsync_bdev (bdev);zram_reset_device (zram, true);return len;
Signature · 1 line
1.7.9.5
PATCH v9 2/2 Staging: zram: Fix decrement of variable by calling bdput()
In reply to a message not in the archiveAs suggested by Jerome Marchand "The code in reset_store get the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."
This patch also puts bdput() for all error cases.
---
This revision fixes the following issues of the previous revision- Proper error handling
drivers/staging/zram/zram_drv.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/staging/zram/zram_drv.c +14 -5
@@ -652,21 +652,30 @@ static ssize_t reset_store(struct device *dev,return -ENOMEM ;/* Do not reset an active device! */ -if (bdev->bd_holders) -return -EBUSY ; +if (bdev->bd_holders) { + ret = -EBUSY ; + goto out; + } ret =kstrtou16 (buf,10 , &do_reset);if (ret) -return ret; + goto out; -if (!do_reset) -return -EINVAL ; +if (!do_reset) { + ret = -EINVAL ; + goto out; + }/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev);zram_reset_device (zram, true);return len; + +out: +bdput (bdev); +return ret; }static void __zram_make_request (struct zram *zram,struct bio *bio,int rw)
Signature · 1 line
1.7.9.5
Re: [PATCH v9 2/2] Staging: zram: Fix decrement of variable by calling bdput()
I hope subject should be "Fix memory leak by refcount mismatch"
Quoted 8 lines · Rashika Kheria
As suggested by Jerome Marchand "The code in
reset_storeget the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."This patch also puts
bdput()for all error cases.Signed-off-by Rashika Kheria <[email protected]>
Other than that,
Rashika, Thanks!
Signature · 2 lines
Kind regards, Minchan Kim
Re: [PATCH v9 2/2] Staging: zram: Fix decrement of variable by calling bdput()
In reply to Rashika KheriaQuoted 1 line · Rashika Kheria
As suggested by Jerome Marchand "The code in
reset_storeget the block device
The credit should actually go to Minchan. He found the bug. I merely explained it.
Quoted 7 lines
(
bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."This patch also puts
bdput()for all error cases.Signed-off-by Rashika Kheria <[email protected]>
This version finally looks good. Thanks for your effort.
Quoted 49 lines
---
This revision fixes the following issues of the previous revision- Proper error handling
drivers/staging/zram/zram_drv.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)drivers/staging/zram/zram_drv.c +14
-5@@ -652,21 +652,30 @@ static ssize_t reset_store(struct device *dev,return -ENOMEM ;/* Do not reset an active device! */ -if (bdev->bd_holders) -return -EBUSY ; +if (bdev->bd_holders) { + ret = -EBUSY ; + goto out; + } ret =kstrtou16 (buf,10 , &do_reset);if (ret) -return ret; + goto out; -if (!do_reset) -return -EINVAL ; +if (!do_reset) { + ret = -EINVAL ; + goto out; + }/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev);zram_reset_device (zram, true);return len; + +out: +bdput (bdev); +return ret; }static void __zram_make_request (struct zram *zram,struct bio *bio,int rw)
PATCH v10 1/1 Staging: zram: Fix memory leak by refcount mismatch
In reply to a message not in the archiveAs suggested by Minchan Kim and Jerome Marchand "The code in reset_store get the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."
This patch also puts bdput() for all error cases.
---
This revision fixes the following issue of the previous revision- Incorrect Subject Line
drivers/staging/zram/zram_drv.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/staging/zram/zram_drv.c +14 -5
@@ -652,21 +652,30 @@ static ssize_t reset_store(struct device *dev,return -ENOMEM ;/* Do not reset an active device! */ -if (bdev->bd_holders) -return -EBUSY ; +if (bdev->bd_holders) { + ret = -EBUSY ; + goto out; + } ret =kstrtou16 (buf,10 , &do_reset);if (ret) -return ret; + goto out; -if (!do_reset) -return -EINVAL ; +if (!do_reset) { + ret = -EINVAL ; + goto out; + }/* Make sure all pending I/O is finished */ fsync_bdev (bdev); +bdput (bdev);zram_reset_device (zram, true);return len; + +out: +bdput (bdev); +return ret; }static void __zram_make_request (struct zram *zram,struct bio *bio,int rw)
Signature · 1 line
1.7.9.5
Re: [PATCH v9 2/2] Staging: zram: Fix decrement of variable by calling bdput()
In reply to Jerome MarchandQuoted 9 lines · Jerome Marchand
Quoted 1 line · Rashika Kheria
As suggested by Jerome Marchand "The code in
reset_storeget the block deviceThe credit should actually go to Minchan. He found the bug. I merely explained it.
Quoted 3 lines
(
bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."
Quoted 10 lines
Quoted 4 lines
This patch also puts
bdput()for all error cases.Signed-off-by Rashika Kheria <[email protected]>This version finally looks good. Thanks for your effort.
Acked-by Jerome Marchand <[email protected]>
Hi,
Thanks Minchan and Jerome for all you support and patience. Your guidance helped me learn more about zram and kernel coding style in general. :)
Thanks,
Signature · 3 lines
Rashika Kheria B.Tech CSE IIIT Hyderabad
Greg Kroah-Hartman
maintainerRe: [PATCH v10] Staging: zram: Fix memory leak by refcount mismatch
In reply to Rashika KheriaQuoted 7 lines · Rashika Kheria
As suggested by Minchan Kim and Jerome Marchand "The code in
reset_storeget the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."This patch also puts
bdput()for all error cases.
Quoted 8 lines
Acked-by Minchan Kim <[email protected]>Acked-by Jerome Marchand <[email protected]>Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issue of the previous revision- Incorrect Subject Line
I'm a bit confused now, I see three different zram patches from you, with different subjects, are they all now just in one patch, this one?
Can you just send me the outstanding zram patches that you have gotten acks from that you want applied, as I'm lost here.
thanks,
greg "easily confused" k-h
Re: [OPW kernel] Re: [PATCH v10] Staging: zram: Fix memory leak by refcount mismatch
Quoted 20 lines · Greg Kroah-Hartman
Quoted 7 lines · Rashika Kheria
As suggested by Minchan Kim and Jerome Marchand "The code in
reset_storeget the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."This patch also puts
bdput()for all error cases.Quoted 8 lines
Acked-by Minchan Kim <[email protected]>Acked-by Jerome Marchand <[email protected]>Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issue of the previous revision- Incorrect Subject Line
I'm a bit confused now, I see three different zram patches from you, with different subjects, are they all now just in one patch, this one?
Quoted 7 lines
Can you just send me the outstanding zram patches that you have gotten acks from that you want applied, as I'm lost here.
thanks,
greg "easily confused" k-h
Hi Greg,
You have already applied the rest two patches for this driver. This is the only patch which is left.
But I think you might have problem applying this because there have been changes in previous patches later i.e you applied v8 of this series, while, maintainers later suggested to change more and hence v9 was also introduced.
Therefore, v9's patch 1 and v10 patch is correct to be applied in the tree.
Thanks,
Signature · 3 lines
Rashika Kheria B.Tech CSE IIIT Hyderabad
Greg Kroah-Hartman
maintainerRe: [OPW kernel] Re: [PATCH v10] Staging: zram: Fix memory leak by refcount mismatch
Quoted 35 lines · Rashika Kheria
Quoted 20 lines · Greg Kroah-Hartman
Quoted 7 lines · Rashika Kheria
As suggested by Minchan Kim and Jerome Marchand "The code in
reset_storeget the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."This patch also puts
bdput()for all error cases.Quoted 8 lines
Acked-by Minchan Kim <[email protected]>Acked-by Jerome Marchand <[email protected]>Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issue of the previous revision- Incorrect Subject Line
I'm a bit confused now, I see three different zram patches from you, with different subjects, are they all now just in one patch, this one?
Quoted 7 lines
Can you just send me the outstanding zram patches that you have gotten acks from that you want applied, as I'm lost here.
thanks,
greg "easily confused" k-h
Hi Greg,
You have already applied the rest two patches for this driver. This is the only patch which is left.
Quoted 6 lines
But I think you might have problem applying this because there have been changes in previous patches later i.e you applied v8 of this series, while, maintainers later suggested to change more and hence v9 was also introduced.
Therefore, v9's patch 1 and v10 patch is correct to be applied in the tree.
Hm, can you please resend them, as I no longer have them in my queue.
thanks,
greg k-h
Re: [OPW kernel] Re: [PATCH v10] Staging: zram: Fix memory leak by refcount mismatch
Quoted 41 lines · Greg Kroah-Hartman
Quoted 40 lines · Rashika Kheria
Quoted 20 lines · Greg Kroah-Hartman
Quoted 7 lines · Rashika Kheria
As suggested by Minchan Kim and Jerome Marchand "The code in
reset_storeget the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented."This patch also puts
bdput()for all error cases.Quoted 8 lines
Acked-by Minchan Kim <[email protected]>Acked-by Jerome Marchand <[email protected]>Signed-off-by Rashika Kheria <[email protected]>---
This revision fixes the following issue of the previous revision- Incorrect Subject Line
I'm a bit confused now, I see three different zram patches from you, with different subjects, are they all now just in one patch, this one?
Quoted 7 lines
Can you just send me the outstanding zram patches that you have gotten acks from that you want applied, as I'm lost here.
thanks,
greg "easily confused" k-h
Hi Greg,
You have already applied the rest two patches for this driver. This is the only patch which is left.
But I think you might have problem applying this because there have been changes in previous patches later i.e you applied v8 of this series, while, maintainers later suggested to change more and hence v9 was also introduced.
Quoted 8 lines
Quoted 1 line
Therefore, v9's patch 1 and v10 patch is correct to be applied in the tree.
Hm, can you please resend them, as I no longer have them in my queue.
thanks,
greg k-h
Resent.
Thanks,
Signature · 3 lines
Rashika Kheria B.Tech CSE IIIT Hyderabad