From: Alan Mikhak <alan.mikhak@sifive.com>
To: linux-kernel@vger.kernel.org, martin.petersen@oracle.com,
alexios.zavras@intel.com, ming.lei@redhat.com,
gregkh@linuxfoundation.org, tglx@linutronix.de, jgg@ziepe.ca,
christophe.leroy@c-s.fr, palmer@sifive.com,
paul.walmsley@sifive.com
Cc: Alan Mikhak <alan.mikhak@sifive.com>
Subject: [PATCH] scatterlist: Validate page before calling PageSlab()
Date: Mon, 30 Sep 2019 16:22:35 -0700 [thread overview]
Message-ID: <1569885755-10947-1-git-send-email-alan.mikhak@sifive.com> (raw)
From: Alan Mikhak <alan.mikhak@sifive.com>
Modify sg_miter_stop() to validate the page pointer
before calling PageSlab(). This check prevents a crash
that will occur if PageSlab() gets called with a page
pointer that is not backed by page struct.
A virtual address obtained from ioremap() for a physical
address in PCI address space can be assigned to a
scatterlist segment using the public scatterlist API
as in the following example:
my_sg_set_page(struct scatterlist *sg,
const void __iomem *ioaddr,
size_t iosize)
{
sg_set_page(sg,
virt_to_page(ioaddr),
(unsigned int)iosize,
offset_in_page(ioaddr));
sg_init_marker(sg, 1);
}
If the virtual address obtained from ioremap() is not
backed by a page struct, virt_to_page() returns an
invalid page pointer. However, sg_copy_buffer() can
correctly recover the original virtual address. Such
addresses can successfully be assigned to scatterlist
segments to transfer data across the PCI bus with
sg_copy_buffer() if it were not for the crash in
PageSlab() when called by sg_miter_stop().
Signed-off-by: Alan Mikhak <alan.mikhak@sifive.com>
---
lib/scatterlist.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index c2cf2c311b7d..f5c61cad40ba 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -807,6 +807,7 @@ void sg_miter_stop(struct sg_mapping_iter *miter)
miter->__remaining -= miter->consumed;
if ((miter->__flags & SG_MITER_TO_SG) &&
+ pfn_valid(page_to_pfn(miter->page)) &&
!PageSlab(miter->page))
flush_kernel_dcache_page(miter->page);
--
2.7.4
next reply other threads:[~2019-09-30 23:22 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-30 23:22 Alan Mikhak [this message]
2019-10-01 12:16 ` Jason Gunthorpe
2019-10-01 17:09 ` Alan Mikhak
2019-10-01 17:12 ` Jason Gunthorpe
2019-10-01 17:26 ` Alan Mikhak
2019-10-01 17:43 ` Jason Gunthorpe
2019-10-01 17:46 ` Alan Mikhak
2019-10-07 6:12 ` Christoph Hellwig
2019-10-07 6:13 ` Christoph Hellwig
2019-10-07 16:44 ` Alan Mikhak
2019-10-07 21:13 ` Alan Mikhak
2019-10-15 9:55 ` Christoph Hellwig
2019-10-15 16:12 ` Logan Gunthorpe
2019-10-15 19:02 ` Alan Mikhak
2019-10-15 17:40 ` Alan Mikhak
2019-10-15 17:45 ` Logan Gunthorpe
2019-10-15 18:11 ` Alan Mikhak
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=1569885755-10947-1-git-send-email-alan.mikhak@sifive.com \
--to=alan.mikhak@sifive.com \
--cc=alexios.zavras@intel.com \
--cc=christophe.leroy@c-s.fr \
--cc=gregkh@linuxfoundation.org \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=ming.lei@redhat.com \
--cc=palmer@sifive.com \
--cc=paul.walmsley@sifive.com \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®