2003-08-17 16:39:59

by Mark Hemment

[permalink] [raw]
Subject: [PATCH] Wrong assumption in set_bh_page()

set_bh_page() assumes page_address() will always return NULL for a
highmem page. This assumption is wrong - the highmem page could be
kmap()ped.

Luckily, no code I've looked at assumes that b_data contains a _pure_
offset for a highmem page, but this is a bug waiting to happen.

Patch is against 2.4.21-rc1.

Mark


diff -urN linux-2.4.21-rc1/fs/buffer.c linux-2.4.21-rc1-bh/fs/buffer.c
--- linux-2.4.21-rc1/fs/buffer.c 2003-08-17 15:55:40.000000000 +0100
+++ linux-2.4.21-rc1-bh/fs/buffer.c 2003-08-17 18:15:13.000000000 +0100
@@ -1231,10 +1231,11 @@
if (offset >= PAGE_SIZE)
BUG();

- /*
- * page_address will return NULL anyways for highmem pages
- */
- bh->b_data = page_address(page) + offset;
+ if (PageHighMem(page)) {
+ bh->b_data = (char *)offset;
+ } else {
+ bh->b_data = page_address(page) + offset;
+ }
bh->b_page = page;
}
EXPORT_SYMBOL(set_bh_page);