From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel@redhat.com, Christoph Hellwig <hch@lst.de>
Cc: "Bob Peterson" <rpeterso@redhat.com>, "Jan Kara" <jack@suse.cz>,
"Dave Chinner" <david@fromorbit.com>,
"Ross Lagerwall" <ross.lagerwall@citrix.com>,
"Mark Syms" <Mark.Syms@citrix.com>,
"Edwin Török" <edvin.torok@citrix.com>,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
"Andreas Gruenbacher" <agruenba@redhat.com>
Subject: [PATCH v5 1/3] iomap: Fix use-after-free error in page_done callback
Date: Fri, 26 Apr 2019 15:11:25 +0200 [thread overview]
Message-ID: <20190426131127.19164-1-agruenba@redhat.com> (raw)
In iomap_write_end, we are not holding a page reference anymore when
calling the page_done callback, but the callback needs that reference to
access the page.
To fix that, move the put_page call in __generic_write_end into the
callers of __generic_write_end. Then, in iomap_write_end, put the page
after calling the page_done callback.
Reported-by: Jan Kara <jack@suse.cz>
Fixes: 63899c6f8851 ("iomap: add a page_done callback")
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/buffer.c | 5 +++--
fs/iomap.c | 12 ++++++++++--
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index ce357602f471..6e2c95160ce3 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2104,7 +2104,6 @@ int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied,
}
unlock_page(page);
- put_page(page);
if (old_size < pos)
pagecache_isize_extended(inode, old_size, pos);
@@ -2160,7 +2159,9 @@ int generic_write_end(struct file *file, struct address_space *mapping,
struct page *page, void *fsdata)
{
copied = block_write_end(file, mapping, pos, len, copied, page, fsdata);
- return __generic_write_end(mapping->host, pos, copied, page);
+ copied = __generic_write_end(mapping->host, pos, copied, page);
+ put_page(page);
+ return copied;
}
EXPORT_SYMBOL(generic_write_end);
diff --git a/fs/iomap.c b/fs/iomap.c
index 97cb9d486a7d..3e4652dac9d9 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -765,6 +765,14 @@ iomap_write_end_inline(struct inode *inode, struct page *page,
return copied;
}
+static int
+buffer_write_end(struct address_space *mapping, loff_t pos, loff_t len,
+ unsigned copied, struct page *page)
+{
+ copied = block_write_end(NULL, mapping, pos, len, copied, page, NULL);
+ return __generic_write_end(mapping->host, pos, copied, page);
+}
+
static int
iomap_write_end(struct inode *inode, loff_t pos, unsigned len,
unsigned copied, struct page *page, struct iomap *iomap)
@@ -774,14 +782,14 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len,
if (iomap->type == IOMAP_INLINE) {
ret = iomap_write_end_inline(inode, page, iomap, pos, copied);
} else if (iomap->flags & IOMAP_F_BUFFER_HEAD) {
- ret = generic_write_end(NULL, inode->i_mapping, pos, len,
- copied, page, NULL);
+ ret = buffer_write_end(inode->i_mapping, pos, len, copied, page);
} else {
ret = __iomap_write_end(inode, pos, len, copied, page, iomap);
}
if (iomap->page_done)
iomap->page_done(inode, pos, copied, page, iomap);
+ put_page(page);
if (ret < len)
iomap_write_failed(inode, pos, len);
--
2.20.1
next reply other threads:[~2019-04-26 13:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-26 13:11 Andreas Gruenbacher [this message]
2019-04-26 13:11 ` [PATCH v5 2/3] iomap: Add a page_prepare callback Andreas Gruenbacher
2019-04-26 14:22 ` Christoph Hellwig
2019-04-26 13:11 ` [PATCH v5 3/3] gfs2: Fix iomap write page reclaim deadlock Andreas Gruenbacher
2019-04-27 6:17 ` [PATCH v5 1/3] iomap: Fix use-after-free error in page_done callback Christoph Hellwig
2019-04-28 19:20 ` Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190426131127.19164-1-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=Mark.Syms@citrix.com \
--cc=cluster-devel@redhat.com \
--cc=david@fromorbit.com \
--cc=edvin.torok@citrix.com \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ross.lagerwall@citrix.com \
--cc=rpeterso@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).