Skip to content

Commit

Permalink
NFS: Fix potential oops in nfs_inode_remove_request()
Browse files Browse the repository at this point in the history
Once a folio's private data has been cleared, it's possible for another
process to clear the folio->mapping (e.g. via invalidate_complete_folio2
or evict_mapping_folio), so it wouldn't be safe to call
nfs_page_to_inode() after that.

Fixes: 0c493b5 ("NFS: Convert buffered writes to use folios")
Signed-off-by: Scott Mayhew <smayhew@redhat.com>
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Tested-by: Benjamin Coddington <bcodding@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
  • Loading branch information
scottmayhew authored and amschuma-ntap committed Oct 11, 2023
1 parent f588d72 commit 6a6d464
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/nfs/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,8 @@ static void nfs_inode_add_request(struct nfs_page *req)
*/
static void nfs_inode_remove_request(struct nfs_page *req)
{
struct nfs_inode *nfsi = NFS_I(nfs_page_to_inode(req));

if (nfs_page_group_sync_on_bit(req, PG_REMOVE)) {
struct folio *folio = nfs_page_to_folio(req->wb_head);
struct address_space *mapping = folio_file_mapping(folio);
Expand All @@ -802,7 +804,7 @@ static void nfs_inode_remove_request(struct nfs_page *req)
}

if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags)) {
atomic_long_dec(&NFS_I(nfs_page_to_inode(req))->nrequests);
atomic_long_dec(&nfsi->nrequests);
nfs_release_request(req);
}
}
Expand Down

0 comments on commit 6a6d464

Please sign in to comment.