Skip to contentSkip to conversation

Ocfs2: Handle invalid lock_res in lockres_seq_start() for dlmdebug.c

PATCH New Tristan Ye 2 participants 5 messages Sep 9, 2010 – Sep 10, 2010 OCFS2

lore
Share & tools
lore

Tristan Ye

author
#0 lore raw

PATCH 1/1 Ocfs2: Handle invalid lock_res in lockres_seq_start() for dlmdebug.c

In lockres_seq_start() of dlmdebug.c, when you looking at following piece of codes:

list_for_each_entry(res, track_list, tracking) {
	if (&res->tracking == &dlm->tracking_list)
		res = NULL;
	else
		dlm_lockres_get(res);
	break;
}

...

if (res) {
	spin_lock(&res->spinlock);
	dump_lockres(res, dl->dl_buf, dl->dl_len - 1);
	spin_unlock(&res->spinlock);
} else
	dl = NULL;

One thought can come to you that, in the case of 'an-empty-list', cursor 'res' here is not an INVALID pointer for real dlm_lock_resource object, it is nothing than a fake address figured out by arbitary 'container_of()' way, the patch tries to check track_list, and avoid accessing an invalid pointer if the list is empty, it fixes following oops:

http://oss.oracle.com/bugzilla/show_bug.cgi?id=1287

---
 fs/ocfs2/dlm/dlmdebug.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
fs/ocfs2/dlm/dlmdebug.c +7 -0
index 5efdd37..06d668a 100644
@@ -639,6 +639,12 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
 	else
 		track_list = &dlm->tracking_list;
 
+	if (list_empty(track_list)) {
+		dl = NULL;
+		spin_unlock(&dlm->track_lock);
+		goto bail;
+	}
+
 	list_for_each_entry(res, track_list, tracking) {
 		if (&res->tracking == &dlm->tracking_list)
 			res = NULL;
@@ -660,6 +666,7 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
 	} else
 		dl = NULL;
 
+bail:
 	/* passed to seq_show */
 	return dl;
 }
Signature · 1 line
1.5.5
#1 lore raw

PATCH 1/1 Ocfs2: Handle invalid lock_res in lockres_seq_start() for dlmdebug.c

Quoted 26 lines · Tristan Ye

In lockres_seq_start() of dlmdebug.c, when you looking at following piece of codes:

list_for_each_entry(res, track_list, tracking) {
	if (&res->tracking ==&dlm->tracking_list)
		res = NULL;
	else
		dlm_lockres_get(res);
	break;
}

...

if (res) {
	spin_lock(&res->spinlock);
	dump_lockres(res, dl->dl_buf, dl->dl_len - 1);
	spin_unlock(&res->spinlock);
} else
	dl = NULL;

One thought can come to you that, in the case of 'an-empty-list', cursor 'res' here is not an INVALID pointer for real dlm_lock_resource object, it is nothing than a fake address figured out by arbitary 'container_of()' way, the patch tries to check track_list, and avoid accessing an invalid pointer if the list is empty, it fixes following oops:

Quoted 5 lines

http://oss.oracle.com/bugzilla/show_bug.cgi?id=1287

---

Such a detailed description is only required if the bug fix is complicated. This is a simple fix. Just say that this handles the case in which the dlm->tracking_list is empty and mention the bz.

Quoted 8 lines
  fs/ocfs2/dlm/dlmdebug.c |    7 +++++++
  1 files changed, 7 insertions(+), 0 deletions(-)
fs/ocfs2/dlm/dlmdebug.c +0 -0
index 5efdd37..06d668a 100644

fs/ocfs2/dlm/dlmdebug.c static void *lockres_seq_start(struct seq_file *m, loff_t *pos) · line 648

Quoted 10 lines
fs/ocfs2/dlm/dlmdebug.c +6 -0
@@ -639,6 +639,12 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
  	else
  		track_list =&dlm->tracking_list;
 
+	if (list_empty(track_list)) {
+		dl = NULL;
+		spin_unlock(&dlm->track_lock);
+		goto bail;
+	}
+
 

You should add this check as part of the else block above so that we check for empty list only at the start.

Quoted 12 lines
fs/ocfs2/dlm/dlmdebug.c +0 -0
  	list_for_each_entry(res, track_list, tracking) {
  		if (&res->tracking ==&dlm->tracking_list)
  			res = NULL;
fs/ocfs2/dlm/dlmdebug.c +1 -0
@@ -660,6 +666,7 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
  	} else
  		dl = NULL;
 
+bail:
  	/* passed to seq_show */
  	return dl;
  }
author
#2 lore raw

PATCH 1/1 Ocfs2: Handle invalid lock_res in lockres_seq_start() for dlmdebug.c

Quoted 33 lines · Sunil Mushran
Quoted 32 lines · Tristan Ye

In lockres_seq_start() of dlmdebug.c, when you looking at following piece of codes:

list_for_each_entry(res, track_list, tracking) {
    if (&res->tracking ==&dlm->tracking_list)
        res = NULL;
    else
        dlm_lockres_get(res);
    break;
}

...

if (res) {
    spin_lock(&res->spinlock);
    dump_lockres(res, dl->dl_buf, dl->dl_len - 1);
    spin_unlock(&res->spinlock);
} else
    dl = NULL;

One thought can come to you that, in the case of 'an-empty-list', cursor 'res'
here is not an INVALID pointer for real dlm_lock_resource object, it is nothing
than a fake address figured out by arbitary 'container_of()' way, the patch tries
to check track_list, and avoid accessing an invalid pointer if the list is empty,
it fixes following oops:

http://oss.oracle.com/bugzilla/show_bug.cgi?id=1287

Quoted 9 lines
Quoted 3 lines

---

Such a detailed description is only required if the bug fix is complicated. This is a simple fix. Just say that this handles the case in which the dlm->tracking_list is empty and mention the bz.

Yeah, kind of...

Quoted 12 lines
Quoted 12 lines
  fs/ocfs2/dlm/dlmdebug.c |    7 +++++++
  1 files changed, 7 insertions(+), 0 deletions(-)
fs/ocfs2/dlm/dlmdebug.c +0 -0
index 5efdd37..06d668a 100644
@@ -639,6 +639,12 @@ static void *lockres_seq_start(struct seq_file 
 *m, loff_t *pos)
      else
          track_list =&dlm->tracking_list;
 
Quoted 10 lines

fs/ocfs2/dlm/dlmdebug.c static void *lockres_seq_start(struct seq_file *m, loff_t *pos)

Quoted 7 lines
fs/ocfs2/dlm/dlmdebug.c +6 -0
+    if (list_empty(track_list)) {
+        dl = NULL;
+        spin_unlock(&dlm->track_lock);
+        goto bail;
+    }
+
 

You should add this check as part of the else block above so that we check for empty list only at the start.

So we just don't need to check list 'oldres->tracking'?

Quoted 15 lines
Quoted 14 lines
fs/ocfs2/dlm/dlmdebug.c +0 -0
      list_for_each_entry(res, track_list, tracking) {
          if (&res->tracking ==&dlm->tracking_list)
              res = NULL;
fs/ocfs2/dlm/dlmdebug.c +1 -0
@@ -660,6 +666,7 @@ static void *lockres_seq_start(struct seq_file 
 *m, loff_t *pos)
      } else
          dl = NULL;
 
+bail:
      /* passed to seq_show */
      return dl;
  }
#3 lore raw

PATCH 1/1 Ocfs2: Handle invalid lock_res in lockres_seq_start() for dlmdebug.c

Quoted 20 lines · tristan
Quoted 11 lines
Quoted 11 lines
  1 files changed, 7 insertions(+), 0 deletions(-)
fs/ocfs2/dlm/dlmdebug.c +0 -0
index 5efdd37..06d668a 100644
@@ -639,6 +639,12 @@ static void *lockres_seq_start(struct seq_file 
 *m, loff_t *pos)
      else
          track_list =&dlm->tracking_list;
 
Quoted 9 lines

fs/ocfs2/dlm/dlmdebug.c static void *lockres_seq_start(struct seq_file *m, loff_t *pos) · line 647

Quoted 6 lines
fs/ocfs2/dlm/dlmdebug.c +6 -0
+    if (list_empty(track_list)) {
+        dl = NULL;
+        spin_unlock(&dlm->track_lock);
+        goto bail;
+    }
+

You should add this check as part of the else block above so that we check for empty list only at the start.

Quoted 3 lines
  fs/ocfs2/dlm/dlmdebug.c |    7 +++++++

So we just don't need to check list 'oldres->tracking'?

If you see how it works, it prints one lock resource at a time. As in, each time _start is called, it fetches the next lock resource in the tracking
list. So the empty list should be checked only at the very beginning.

To be fair, your code should also work. If the list has even one lockres, it cannot, by definition, be empty. But adding it in the if block makes the check explicit and clean. IMHO.

author
#4 lore raw

PATCH 1/1 Ocfs2: Handle invalid lock_res in lockres_seq_start() for dlmdebug.c

Quoted 30 lines · Sunil Mushran
Quoted 20 lines · tristan
Quoted 11 lines
Quoted 11 lines
  1 files changed, 7 insertions(+), 0 deletions(-)
fs/ocfs2/dlm/dlmdebug.c +0 -0
index 5efdd37..06d668a 100644
@@ -639,6 +639,12 @@ static void *lockres_seq_start(struct seq_file 
 *m, loff_t *pos)
      else
          track_list =&dlm->tracking_list;
 
Quoted 9 lines

fs/ocfs2/dlm/dlmdebug.c static void *lockres_seq_start(struct seq_file *m, loff_t *pos) · line 647

Quoted 6 lines
fs/ocfs2/dlm/dlmdebug.c +6 -0
+    if (list_empty(track_list)) {
+        dl = NULL;
+        spin_unlock(&dlm->track_lock);
+        goto bail;
+    }
+

You should add this check as part of the else block above so that we check for empty list only at the start.

Quoted 3 lines
  fs/ocfs2/dlm/dlmdebug.c |    7 +++++++

So we just don't need to check list 'oldres->tracking'?

If you see how it works, it prints one lock resource at a time. As in, each time _start is called, it fetches the next lock resource in the tracking
list. So the empty list should be checked only at the very beginning.

Quoted 4 lines

To be fair, your code should also work. If the list has even one lockres, it cannot, by definition, be empty. But adding it in the if block makes the
check explicit and clean. IMHO.

That makes pretty sense, we just need to check the list at the time of getting its head:)

My check was making the logic clumsy, thanks for correction.