Message ID | 20220701142310.2188015-30-glider@google.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Add KernelMemorySanitizer infrastructure | expand |
On Fri, Jul 01, 2022 at 04:22PM +0200, 'Alexander Potapenko' via kasan-dev wrote: [...] > --- a/block/bio.c > +++ b/block/bio.c > @@ -867,6 +867,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv, > return false; > > *same_page = ((vec_end_addr & PAGE_MASK) == page_addr); > + if (!*same_page && IS_ENABLED(CONFIG_KMSAN)) > + return false; > if (*same_page) > return true; if (*same_page) return true; else if (IS_ENABLED(CONFIG_KMSAN)) return false; > return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);
On Wed, Jul 13, 2022 at 12:23 PM Marco Elver <elver@google.com> wrote: > > On Fri, Jul 01, 2022 at 04:22PM +0200, 'Alexander Potapenko' via kasan-dev wrote: > [...] > > --- a/block/bio.c > > +++ b/block/bio.c > > @@ -867,6 +867,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv, > > return false; > > > > *same_page = ((vec_end_addr & PAGE_MASK) == page_addr); > > + if (!*same_page && IS_ENABLED(CONFIG_KMSAN)) > > + return false; > > if (*same_page) > > return true; > > if (*same_page) > return true; > else if (IS_ENABLED(CONFIG_KMSAN)) > return false; > Done. > > return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);
diff --git a/block/bio.c b/block/bio.c index 51c99f2c5c908..ce6b3c82159a6 100644 --- a/block/bio.c +++ b/block/bio.c @@ -867,6 +867,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv, return false; *same_page = ((vec_end_addr & PAGE_MASK) == page_addr); + if (!*same_page && IS_ENABLED(CONFIG_KMSAN)) + return false; if (*same_page) return true; return (bv->bv_page + bv_end / PAGE_SIZE) == (page + off / PAGE_SIZE);
KMSAN doesn't allow treating adjacent memory pages as such, if they were allocated by different alloc_pages() calls. The block layer however does so: adjacent pages end up being used together. To prevent this, make page_is_mergeable() return false under KMSAN. Suggested-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Alexander Potapenko <glider@google.com> --- v4: -- swap block: and kmsan: in the subject Link: https://linux-review.googlesource.com/id/Ie29cc2464c70032347c32ab2a22e1e7a0b37b905 --- block/bio.c | 2 ++ 1 file changed, 2 insertions(+)