From: Li Bin huawei.libin@huawei.com
hulk inclusion category: bugfix bugzilla: 34236 CVE: NA
--------------------------------
Fix a memory leak that occurs when alloc_pages() succeeds several times before failing. This condition is noticed when rem_sz > 0.
Signed-off-by: Li Bin huawei.libin@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- drivers/scsi/sg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 9c4b71e..072d636 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1940,8 +1940,12 @@ static long sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned lon k, rem_sz));
schp->bufflen = blk_size; - if (rem_sz > 0) /* must have failed */ + if (rem_sz > 0) { /* must have failed */ + for (i = 0; i < k; i++) + __free_pages(schp->pages[i], order); + return -ENOMEM; + } return 0; out: for (i = 0; i < k; i++)