Skip to content

Commit

Permalink
NFS: Fix use-after-free issues in nfs_pageio_add_request()
Browse files Browse the repository at this point in the history
commit dc9dc2f upstream.

We need to ensure that we create the mirror requests before calling
nfs_pageio_add_request_mirror() on the request we are adding.
Otherwise, we can end up with a use-after-free if the call to
nfs_pageio_add_request_mirror() triggers I/O.

Fixes: c917cfa ("NFS: Fix up NFS I/O subrequest creation")
Cc: stable@vger.kernel.org
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Trond Myklebust authored and gregkh committed Apr 17, 2020
1 parent 98a817e commit 6b64cbd
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions fs/nfs/pagelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,38 +1177,38 @@ int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc,
if (desc->pg_error < 0)
goto out_failed;

for (midx = 0; midx < desc->pg_mirror_count; midx++) {
if (midx) {
nfs_page_group_lock(req);

/* find the last request */
for (lastreq = req->wb_head;
lastreq->wb_this_page != req->wb_head;
lastreq = lastreq->wb_this_page)
;

dupreq = nfs_create_subreq(req, lastreq,
pgbase, offset, bytes);

nfs_page_group_unlock(req);
if (IS_ERR(dupreq)) {
desc->pg_error = PTR_ERR(dupreq);
goto out_failed;
}
} else
dupreq = req;
/* Create the mirror instances first, and fire them off */
for (midx = 1; midx < desc->pg_mirror_count; midx++) {
nfs_page_group_lock(req);

/* find the last request */
for (lastreq = req->wb_head;
lastreq->wb_this_page != req->wb_head;
lastreq = lastreq->wb_this_page)
;

dupreq = nfs_create_subreq(req, lastreq,
pgbase, offset, bytes);

nfs_page_group_unlock(req);
if (IS_ERR(dupreq)) {
desc->pg_error = PTR_ERR(dupreq);
goto out_failed;
}

if (nfs_pgio_has_mirroring(desc))
desc->pg_mirror_idx = midx;
desc->pg_mirror_idx = midx;
if (!nfs_pageio_add_request_mirror(desc, dupreq))
goto out_cleanup_subreq;
}

desc->pg_mirror_idx = 0;
if (!nfs_pageio_add_request_mirror(desc, req))
goto out_failed;

return 1;

out_cleanup_subreq:
if (req != dupreq)
nfs_pageio_cleanup_request(desc, dupreq);
nfs_pageio_cleanup_request(desc, dupreq);
out_failed:
nfs_pageio_error_cleanup(desc);
return 0;
Expand Down

0 comments on commit 6b64cbd

Please sign in to comment.