Skip to content

Commit

Permalink
fix a page leak in vhost_scsi_iov_to_sgl() error recovery
Browse files Browse the repository at this point in the history
we are advancing sg as we go, so the pages we need to drop in
case of error are *before* the current sg.

Cc: [email protected]
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Oct 12, 2017
1 parent 09cf698 commit 11d49e9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/vhost/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ vhost_scsi_iov_to_sgl(struct vhost_scsi_cmd *cmd, bool write,
struct scatterlist *sg, int sg_count)
{
size_t off = iter->iov_offset;
struct scatterlist *p = sg;
int i, ret;

for (i = 0; i < iter->nr_segs; i++) {
Expand All @@ -696,8 +697,8 @@ vhost_scsi_iov_to_sgl(struct vhost_scsi_cmd *cmd, bool write,

ret = vhost_scsi_map_to_sgl(cmd, base, len, sg, write);
if (ret < 0) {
for (i = 0; i < sg_count; i++) {
struct page *page = sg_page(&sg[i]);
while (p < sg) {
struct page *page = sg_page(p++);
if (page)
put_page(page);
}
Expand Down

0 comments on commit 11d49e9

Please sign in to comment.