Skip to contentSkip to conversation

linux: validate type and value of the dtor argument of SetPageForeign()

PATCH New Jan Beulich 1 participant 1 message Mar 13, 2008 MM core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux: validate type and value of the dtor argument of SetPageForeign()

Linux 2.6.25 changes the protoype of pte_free() etc., resulting in those functions no longer be suitable as a PageForeign destructor. I had to find out by way of analysing a crash, but for the future it'd be much better if the build would already indicate a problem with this.

At once, also check the destructor supplied is not NULL.

As usual, written and tested on 2.6.25-rc5 and made apply to the 2.6.18 tree without further testing.

include/linux/page-flags.h +9 -8
Index: head-2008-03-06/include/linux/page-flags.h
===================================================================
@@ -305,16 +305,17 @@ static inline void __ClearPageTail(struc
 #define ClearPageUncached(page)	clear_bit(PG_uncached, &(page)->flags)
 
 #define PageForeign(page)	test_bit(PG_foreign, &(page)->flags)
-#define SetPageForeign(page, dtor) do {		\
-	set_bit(PG_foreign, &(page)->flags);	\
-	(page)->index = (long)(dtor);		\
+#define SetPageForeign(_page, dtor) do {		\
+	set_bit(PG_foreign, &(_page)->flags);		\
+	BUG_ON((dtor) == (void (*)(struct page *))0);	\
+	(_page)->index = (long)(dtor);			\
 } while (0)
-#define ClearPageForeign(page) do {		\
-	clear_bit(PG_foreign, &(page)->flags);	\
-	(page)->index = 0;			\
+#define ClearPageForeign(page) do {			\
+	clear_bit(PG_foreign, &(page)->flags);		\
+	(page)->index = 0;				\
 } while (0)
-#define PageForeignDestructor(page)		\
-	( (void (*) (struct page *)) (page)->index )(page)
+#define PageForeignDestructor(_page)			\
+	((void (*)(struct page *))(_page)->index)(_page)
 
 struct page;	/* forward declaration */