Skip to contentSkip to conversation

gfs2: fix potential NULL pointer dereference

PATCH In review Michal Nazarewicz 2 participants 2 messages Nov 12, 2013 GFS2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gfs2: fix potential NULL pointer dereference

From: Michal Nazarewicz <[email protected]>

Commit [e66cf1610: GFS2: Use lockref for glocks] replaced call:

    atomic_read(&gi->gl->gl_ref) == 0
with:
    __lockref_is_dead(&gl->gl_lockref)

therefore changing how gl is accessed, from gi->gl to plan gl. However, gl can be a NULL pointer, and so gi->gl needs to be used instead (which is guaranteed not to be NULL because fo the while loop checking that condition).

---
 fs/gfs2/glock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/gfs2/glock.c +2 -1
index e66a800..c8420f7 100644
@@ -1899,7 +1899,8 @@ static int gfs2_glock_iter_next(struct gfs2_glock_iter *gi)
 			gi->nhash = 0;
 		}
 	/* Skip entries for other sb and dead entries */
-	} while (gi->sdp != gi->gl->gl_sbd || __lockref_is_dead(&gl->gl_lockref));
+	} while (gi->sdp != gi->gl->gl_sbd ||
+		 __lockref_is_dead(&gi->gl->gl_lockref));
 
 	return 0;
 }
Signature · 1 line
1.8.4.1
#1 lore raw

Hi,

Yes, good catch. Thanks, I'll add it to the tree,

Steve.

Quoted 30 lines · Michal Nazarewicz

From: Michal Nazarewicz <[email protected]>

Commit [e66cf1610: GFS2: Use lockref for glocks] replaced call:

    atomic_read(&gi->gl->gl_ref) == 0
with:
    __lockref_is_dead(&gl->gl_lockref)

therefore changing how gl is accessed, from gi->gl to plan gl. However, gl can be a NULL pointer, and so gi->gl needs to be used instead (which is guaranteed not to be NULL because fo the while loop checking that condition).

---
 fs/gfs2/glock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/gfs2/glock.c +2 -1
index e66a800..c8420f7 100644
@@ -1899,7 +1899,8 @@ static int gfs2_glock_iter_next(struct gfs2_glock_iter *gi)
 			gi->nhash = 0;
 		}
 	/* Skip entries for other sb and dead entries */
-	} while (gi->sdp != gi->gl->gl_sbd || __lockref_is_dead(&gl->gl_lockref));
+	} while (gi->sdp != gi->gl->gl_sbd ||
+		 __lockref_is_dead(&gi->gl->gl_lockref));
 
 	return 0;
 }