Skip to contentSkip to conversation

ceph: Check PagePrivate(page) before dereference, page->private

PATCH Yan, Zheng 2 participants 3 messages May 25, 2012 – May 28, 2012 Ceph client

lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

I got lots of NULL pointer dereference Oops when compiling kernel on ceph. The bug is because the kernel page migration routine replaces some pages in the page cache with new pages, these new pages' private can be non-zero.

---
 fs/ceph/addr.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
fs/ceph/addr.c +4 -1
index 173b1d2..1f180b1 100644
@@ -984,7 +984,10 @@ retry_locked:
 	BUG_ON(!ci->i_snap_realm);
 	down_read(&mdsc->snap_rwsem);
 	BUG_ON(!ci->i_snap_realm->cached_context);
-	snapc = (void *)page->private;
+	if (PagePrivate(page))
+		snapc = (void *)page->private;
+	else
+		snapc = NULL;
 	if (snapc && snapc != ci->i_head_snapc) {
 		/*
 		 * this page is already dirty in another (older) snap
Signature · 1 line
1.7.6.5
#1 lore raw

Hi Yan,

Quoted 16 lines · Zheng

I got lots of NULL pointer dereference Oops when compiling kernel on ceph. The bug is because the kernel page migration routine replaces some pages in the page cache with new pages, these new pages' private can be non-zero.

---
 fs/ceph/addr.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
fs/ceph/addr.c +0 -0
index 173b1d2..1f180b1 100644
@@ -984,7 +984,10 @@ retry_locked:
 	BUG_ON(!ci->i_snap_realm);

fs/ceph/addr.c retry_locked: · line 993

Quoted 10 lines
fs/ceph/addr.c +4 -1
 	down_read(&mdsc->snap_rwsem);
 	BUG_ON(!ci->i_snap_realm->cached_context);
-	snapc = (void *)page->private;
+	if (PagePrivate(page))
+		snapc = (void *)page->private;
+	else
+		snapc = NULL;
 	if (snapc && snapc != ci->i_head_snapc) {
 		/*
 		 * this page is already dirty in another (older) snap

This looks right for this case. What I'm less sure about is whether it's sufficient. I take it the migration only happens on clean pages? (Unless ->migrate is implemented?)

Before we were assuming private == NULL on any clean page, independent of PG_private. For example, ceph_invalidatepage() and ceph_releasepage() have BUG_ONs that are probably wrong. writepage_nounlock() has a sanity check that should probably be strengthened/guarded with a PagePrivate() check, too.

sage

author
#2 lore raw
Quoted 25 lines · Sage Weil

Hi Yan,

Quoted 22 lines · Zheng

I got lots of NULL pointer dereference Oops when compiling kernel on ceph. The bug is because the kernel page migration routine replaces some pages in the page cache with new pages, these new pages' private can be non-zero.

---
 fs/ceph/addr.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
fs/ceph/addr.c +4 -1
index 173b1d2..1f180b1 100644
@@ -984,7 +984,10 @@ retry_locked:
 	BUG_ON(!ci->i_snap_realm);
 	down_read(&mdsc->snap_rwsem);
 	BUG_ON(!ci->i_snap_realm->cached_context);
-	snapc = (void *)page->private;
+	if (PagePrivate(page))
+		snapc = (void *)page->private;
+	else
+		snapc = NULL;
Quoted 8 lines

fs/ceph/addr.c retry_locked: · line 993

Quoted 4 lines
fs/ceph/addr.c +0 -0
 	if (snapc && snapc != ci->i_head_snapc) {
 		/*
 		 * this page is already dirty in another (older) snap

This looks right for this case. What I'm less sure about is whether it's sufficient. I take it the migration only happens on clean pages? (Unless ->migrate is implemented?)

Yes, migration only happens on pages that are clean and have no private stuff.

Quoted 7 lines

Before we were assuming private == NULL on any clean page, independent of PG_private. For example, ceph_invalidatepage() and ceph_releasepage() have BUG_ONs that are probably wrong. writepage_nounlock() has a sanity check that should probably be strengthened/guarded with a PagePrivate() check, too.

Will send the v2 patch soon.

Regards
Yan, Zheng