Commit 65631fea authored by Trond Myklebust's avatar Trond Myklebust Committed by Greg Kroah-Hartman

NFS: Fix 2 use after free issues in the I/O code

commit 196639eb upstream.

The writeback code wants to send a commit after processing the pages,
which is why we want to delay releasing the struct path until after
that's done.

Also, the layout code expects that we do not free the inode before
we've put the layout segments in pnfs_writehdr_free() and
pnfs_readhdr_free()

Fixes: 919e3bd9 ("NFS: Ensure we commit after writeback is complete")
Fixes: 4714fb51 ("nfs: remove pgio_header refcount, related cleanup")
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 03466e03
...@@ -251,7 +251,6 @@ int nfs_iocounter_wait(struct nfs_lock_context *l_ctx); ...@@ -251,7 +251,6 @@ int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
extern const struct nfs_pageio_ops nfs_pgio_rw_ops; extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *); struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
void nfs_pgio_header_free(struct nfs_pgio_header *); void nfs_pgio_header_free(struct nfs_pgio_header *);
void nfs_pgio_data_destroy(struct nfs_pgio_header *);
int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops, struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops,
......
...@@ -530,16 +530,6 @@ struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *ops) ...@@ -530,16 +530,6 @@ struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *ops)
} }
EXPORT_SYMBOL_GPL(nfs_pgio_header_alloc); EXPORT_SYMBOL_GPL(nfs_pgio_header_alloc);
/*
* nfs_pgio_header_free - Free a read or write header
* @hdr: The header to free
*/
void nfs_pgio_header_free(struct nfs_pgio_header *hdr)
{
hdr->rw_ops->rw_free_header(hdr);
}
EXPORT_SYMBOL_GPL(nfs_pgio_header_free);
/** /**
* nfs_pgio_data_destroy - make @hdr suitable for reuse * nfs_pgio_data_destroy - make @hdr suitable for reuse
* *
...@@ -548,14 +538,24 @@ EXPORT_SYMBOL_GPL(nfs_pgio_header_free); ...@@ -548,14 +538,24 @@ EXPORT_SYMBOL_GPL(nfs_pgio_header_free);
* *
* @hdr: A header that has had nfs_generic_pgio called * @hdr: A header that has had nfs_generic_pgio called
*/ */
void nfs_pgio_data_destroy(struct nfs_pgio_header *hdr) static void nfs_pgio_data_destroy(struct nfs_pgio_header *hdr)
{ {
if (hdr->args.context) if (hdr->args.context)
put_nfs_open_context(hdr->args.context); put_nfs_open_context(hdr->args.context);
if (hdr->page_array.pagevec != hdr->page_array.page_array) if (hdr->page_array.pagevec != hdr->page_array.page_array)
kfree(hdr->page_array.pagevec); kfree(hdr->page_array.pagevec);
} }
EXPORT_SYMBOL_GPL(nfs_pgio_data_destroy);
/*
* nfs_pgio_header_free - Free a read or write header
* @hdr: The header to free
*/
void nfs_pgio_header_free(struct nfs_pgio_header *hdr)
{
nfs_pgio_data_destroy(hdr);
hdr->rw_ops->rw_free_header(hdr);
}
EXPORT_SYMBOL_GPL(nfs_pgio_header_free);
/** /**
* nfs_pgio_rpcsetup - Set up arguments for a pageio call * nfs_pgio_rpcsetup - Set up arguments for a pageio call
...@@ -669,7 +669,6 @@ EXPORT_SYMBOL_GPL(nfs_initiate_pgio); ...@@ -669,7 +669,6 @@ EXPORT_SYMBOL_GPL(nfs_initiate_pgio);
static void nfs_pgio_error(struct nfs_pgio_header *hdr) static void nfs_pgio_error(struct nfs_pgio_header *hdr)
{ {
set_bit(NFS_IOHDR_REDO, &hdr->flags); set_bit(NFS_IOHDR_REDO, &hdr->flags);
nfs_pgio_data_destroy(hdr);
hdr->completion_ops->completion(hdr); hdr->completion_ops->completion(hdr);
} }
...@@ -680,7 +679,6 @@ static void nfs_pgio_error(struct nfs_pgio_header *hdr) ...@@ -680,7 +679,6 @@ static void nfs_pgio_error(struct nfs_pgio_header *hdr)
static void nfs_pgio_release(void *calldata) static void nfs_pgio_release(void *calldata)
{ {
struct nfs_pgio_header *hdr = calldata; struct nfs_pgio_header *hdr = calldata;
nfs_pgio_data_destroy(hdr);
hdr->completion_ops->completion(hdr); hdr->completion_ops->completion(hdr);
} }
......
...@@ -2274,7 +2274,6 @@ pnfs_write_through_mds(struct nfs_pageio_descriptor *desc, ...@@ -2274,7 +2274,6 @@ pnfs_write_through_mds(struct nfs_pageio_descriptor *desc,
nfs_pageio_reset_write_mds(desc); nfs_pageio_reset_write_mds(desc);
mirror->pg_recoalesce = 1; mirror->pg_recoalesce = 1;
} }
nfs_pgio_data_destroy(hdr);
hdr->release(hdr); hdr->release(hdr);
} }
...@@ -2398,7 +2397,6 @@ pnfs_read_through_mds(struct nfs_pageio_descriptor *desc, ...@@ -2398,7 +2397,6 @@ pnfs_read_through_mds(struct nfs_pageio_descriptor *desc,
nfs_pageio_reset_read_mds(desc); nfs_pageio_reset_read_mds(desc);
mirror->pg_recoalesce = 1; mirror->pg_recoalesce = 1;
} }
nfs_pgio_data_destroy(hdr);
hdr->release(hdr); hdr->release(hdr);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment