Skip to content

Commit 1b11593

Browse files
Al Virogregkh
authored andcommitted
fix a page leak in vhost_scsi_iov_to_sgl() error recovery
commit 11d49e9d089ccec81be87c2386dfdd010d7f7f6e upstream. we are advancing sg as we go, so the pages we need to drop in case of error are *before* the current sg. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 509ab50 commit 1b11593

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

drivers/vhost/scsi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ vhost_scsi_iov_to_sgl(struct vhost_scsi_cmd *cmd, bool write,
703703
struct scatterlist *sg, int sg_count)
704704
{
705705
size_t off = iter->iov_offset;
706+
struct scatterlist *p = sg;
706707
int i, ret;
707708

708709
for (i = 0; i < iter->nr_segs; i++) {
@@ -711,8 +712,8 @@ vhost_scsi_iov_to_sgl(struct vhost_scsi_cmd *cmd, bool write,
711712

712713
ret = vhost_scsi_map_to_sgl(cmd, base, len, sg, write);
713714
if (ret < 0) {
714-
for (i = 0; i < sg_count; i++) {
715-
struct page *page = sg_page(&sg[i]);
715+
while (p < sg) {
716+
struct page *page = sg_page(p++);
716717
if (page)
717718
put_page(page);
718719
}

0 commit comments

Comments
 (0)