Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756922Ab2K0Xb3 (ORCPT ); Tue, 27 Nov 2012 18:31:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:21908 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755834Ab2K0Xb1 (ORCPT ); Tue, 27 Nov 2012 18:31:27 -0500 From: Rafael Aquini To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sasha Levin , Mel Gorman , Rik van Riel , aquini@redhat.com Subject: [PATCH] mm: fix balloon_page_movable() page->flags check Date: Tue, 27 Nov 2012 21:31:10 -0200 Message-Id: <1ccb1c95a52185bcc6009761cb2829197e2737ea.1354058194.git.aquini@redhat.com> In-Reply-To: <20121127145708.c7173d0d.akpm@linux-foundation.org> References: <20121127145708.c7173d0d.akpm@linux-foundation.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2583 Lines: 65 This patch fixes the following crash by fixing and enhancing the way page->flags are tested to identify a ballooned page. ---8<--- BUG: unable to handle kernel NULL pointer dereference at 0000000000000194 IP: [] isolate_migratepages_range+0x344/0x7b0 --->8--- The NULL pointer deref was taking place because balloon_page_movable() page->flags tests were incomplete and we ended up inadvertently poking at private pages. Reported-by: Sasha Levin Signed-off-by: Rafael Aquini --- include/linux/balloon_compaction.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h index 68893bc..634a19b 100644 --- a/include/linux/balloon_compaction.h +++ b/include/linux/balloon_compaction.h @@ -107,6 +107,23 @@ static inline void balloon_mapping_free(struct address_space *balloon_mapping) } /* + * __balloon_page_flags - helper to perform balloon @page ->flags tests. + * + * As balloon pages are got from Buddy, and we do not play with page->flags + * at driver level (exception made when we get the page lock for compaction), + * therefore we can safely identify a ballooned page by checking if the + * NR_PAGEFLAGS rightmost bits from the page->flags are all cleared. + * This approach also helps on skipping ballooned pages that are locked for + * compaction or release, thus mitigating their racy check at + * balloon_page_movable() + */ +#define BALLOON_PAGE_FLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1) +static inline bool __balloon_page_flags(struct page *page) +{ + return page->flags & BALLOON_PAGE_FLAGS_MASK ? false : true; +} + +/* * __is_movable_balloon_page - helper to perform @page mapping->flags tests */ static inline bool __is_movable_balloon_page(struct page *page) @@ -135,8 +152,8 @@ static inline bool balloon_page_movable(struct page *page) * Before dereferencing and testing mapping->flags, lets make sure * this is not a page that uses ->mapping in a different way */ - if (!PageSlab(page) && !PageSwapCache(page) && !PageAnon(page) && - !page_mapped(page)) + if (__balloon_page_flags(page) && !page_mapped(page) && + page_count(page) == 1) return __is_movable_balloon_page(page); return false; -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/