Ocfs2: Handle invalid lock_res in lockres_seq_start() for dlmdebug.c
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
@@ -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
PATCH 1/1 Ocfs2: Handle invalid lock_res in lockres_seq_start() for dlmdebug.c
Quoted 26 lines · Tristan Ye
In
lockres_seq_start()ofdlmdebug.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_resourceobject, it is nothing than a fake address figured out by arbitary 'container_of()' way, the patch tries to checktrack_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
Signed-off-by Tristan Ye<[email protected]>---
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
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
-0list_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; }
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()ofdlmdebug.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 realdlm_lock_resourceobject, it is nothing
than a fake address figured out by arbitary 'container_of()' way, the patch tries
to checktrack_list, and avoid accessing an invalid pointer if the list is empty,
it fixes following oops:
Quoted 9 lines
Quoted 3 lines
Signed-off-by Tristan Ye<[email protected]>---
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_listis 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@@ -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
-0list_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;}
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@@ -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.
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@@ -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
_startis 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.