aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger Pau Monne2017-07-18 09:01:00 -0500
committerGreg Kroah-Hartman2017-08-24 19:02:36 -0500
commitc0b397fd6b2b8ed7b39a717340b85b4b1add5332 (patch)
tree2eb0bf443638511736a665d7ff14424e41ba37e3
parent240628085effc47e86f51fc3fb37bc0e628f9a85 (diff)
downloadkernel-omap-c0b397fd6b2b8ed7b39a717340b85b4b1add5332.tar.gz
kernel-omap-c0b397fd6b2b8ed7b39a717340b85b4b1add5332.tar.xz
kernel-omap-c0b397fd6b2b8ed7b39a717340b85b4b1add5332.zip
xen: fix bio vec merging
commit 462cdace790ac2ed6aad1b19c9c0af0143b6aab0 upstream. The current test for bio vec merging is not fully accurate and can be tricked into merging bios when certain grant combinations are used. The result of these malicious bio merges is a bio that extends past the memory page used by any of the originating bios. Take into account the following scenario, where a guest creates two grant references that point to the same mfn, ie: grant 1 -> mfn A, grant 2 -> mfn A. These references are then used in a PV block request, and mapped by the backend domain, thus obtaining two different pfns that point to the same mfn, pfn B -> mfn A, pfn C -> mfn A. If those grants happen to be used in two consecutive sectors of a disk IO operation becoming two different bios in the backend domain, the checks in xen_biovec_phys_mergeable will succeed, because bfn1 == bfn2 (they both point to the same mfn). However due to the bio merging, the backend domain will end up with a bio that expands past mfn A into mfn A + 1. Fix this by making sure the check in xen_biovec_phys_mergeable takes into account the offset and the length of the bio, this basically replicates whats done in __BIOVEC_PHYS_MERGEABLE using mfns (bus addresses). While there also remove the usage of __BIOVEC_PHYS_MERGEABLE, since that's already checked by the callers of xen_biovec_phys_mergeable. Reported-by: "Jan H. Schönherr" <jschoenh@amazon.de> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/xen/biomerge.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/drivers/xen/biomerge.c b/drivers/xen/biomerge.c
index 4da69dbf7dca..1bdd02a6d6ac 100644
--- a/drivers/xen/biomerge.c
+++ b/drivers/xen/biomerge.c
@@ -10,8 +10,7 @@ bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,
10 unsigned long bfn1 = pfn_to_bfn(page_to_pfn(vec1->bv_page)); 10 unsigned long bfn1 = pfn_to_bfn(page_to_pfn(vec1->bv_page));
11 unsigned long bfn2 = pfn_to_bfn(page_to_pfn(vec2->bv_page)); 11 unsigned long bfn2 = pfn_to_bfn(page_to_pfn(vec2->bv_page));
12 12
13 return __BIOVEC_PHYS_MERGEABLE(vec1, vec2) && 13 return bfn1 + PFN_DOWN(vec1->bv_offset + vec1->bv_len) == bfn2;
14 ((bfn1 == bfn2) || ((bfn1+1) == bfn2));
15#else 14#else
16 /* 15 /*
17 * XXX: Add support for merging bio_vec when using different page 16 * XXX: Add support for merging bio_vec when using different page