OCFS2: don't leave free'd mle attached to hb events
PATCH 1/1 OCFS2: don't leave free'd mle attached to hb events
don't leave free'd mle attached to hb events.
in dlm_add_migration_mle() the mle is attched to "heartbeat events" anyway no matter there is an existing mle with same name(returns -EEXIST). dlm_migrate_lockres() calls dlm_add_migration_mle(). in case the later function returning -EEXIST, dlm_migrate_lockres() frees the (new) mle without detaching it from "hb events". so that later "hb events" related operations could improperly operate against wrong mle objects or against an invalid memory address.
the patch fixes above problem. it marks the mle as "added" just after dlm_add_migration_mle() is called.
fs/ocfs2/dlm/dlmmaster.c +2 -1
@@ -2498,11 +2498,12 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm,spin_unlock (&dlm->master_lock);spin_unlock (&dlm->spinlock); + mle_added =1 ; +if (ret == -EEXIST ) {mlog (0 ,"another process is already migrating it\n" ); goto fail; } - mle_added =1 ;/* * set the MIGRATING flag and flush asts
Sunil Mushran
NAKPATCH 1/1 OCFS2: don't leave free'd mle attached to hb events
NAK
Quoted 8 lines · wengang wang
don't leave free'd mle attached to hb events.
in
dlm_add_migration_mle()the mle is attched to "heartbeat events" anyway no matter there is an existing mle with same name(returns-EEXIST).dlm_migrate_lockres()callsdlm_add_migration_mle(). in case the later function returning-EEXIST,dlm_migrate_lockres()frees the (new) mle without detaching it from "hb events". so that later "hb events" related operations could improperly operate against wrong mle objects or against an invalid memory address.
The mle is attached to hb events in dlm_init_mle() which is not called if it returns -EEXIST. When it returns -EEXIST, oldmle is set to the existing mle and its refcounting is handled correctly. mle is not touched and thus only needs to be freed.
Quoted 24 lines
the patch fixes above problem. it marks the mle as "added" just after
dlm_add_migration_mle()is called.Signed-off-by Wengang Wang <[email protected]>fs/ocfs2/dlm/dlmmaster.c +2
-1@@ -2498,11 +2498,12 @@ static int dlm_migrate_lockres(struct dlm_ctxt *dlm,spin_unlock (&dlm->master_lock);spin_unlock (&dlm->spinlock); + mle_added =1 ; +if (ret == -EEXIST ) {mlog (0 ,"another process is already migrating it\n" ); goto fail; } - mle_added =1 ;/* * set the MIGRATING flag and flush asts
PATCH 1/1 OCFS2: don't leave free'd mle attached to hb events
Hi Sunil,
Quoted 15 lines · Sunil Mushran
NAK
Quoted 11 lines · wengang wang
don't leave free'd mle attached to hb events.
indlm_add_migration_mle()the mle is attched to "heartbeat
events" anyway no
matter there is an existing mle with same name(returns-EEXIST).dlm_migrate_lockres()callsdlm_add_migration_mle(). in case the later function
returning-EEXIST,dlm_migrate_lockres()frees the (new) mle without detaching
it from "hb events". so that later "hb events" related operations could improperly
operate against wrong mle objects or against an invalid memory address.
Quoted 5 lines
The mle is attached to hb events in
dlm_init_mle()which is not called if it returns-EEXIST. When it returns-EEXIST, oldmle is set to the existing mle and its refcounting is handled correctly. mle is not touched and thus only needs to be freed.
Maybe I am wrong. but are you sure dlm_init_mle() is not called when it returns -EEXIST?
in code, it doesn't return immediately after setting ret with -EEXIST, but continue to calldlm_init_mle();
and thenmle->new_master = new_master;
Maybe I am wrong somewhere?
simplified code pasted here:
3098 static int dlm_add_migration_mle(struct dlm_ctxt *dlm,
3099 struct dlm_lock_resource *res, 3100 struct dlm_master_list_entry *mle, 3101 struct dlm_master_list_entry **oldmle, 3102 const char *name, unsigned int
namelen,
3103 u8 new_master, u8 master)
3104 {
3116 found = dlm_find_mle(dlm, oldmle, (char *)name, namelen);
3117 if (found) {
3118 struct dlm_master_list_entry *tmp = *oldmle;
3120 if (tmp->type == DLM_MLE_MIGRATION) {
3121 if (master == dlm->node_num) {
3126 ret = -EEXIST;
3127 } else {
3136 BUG();
3137 }
3138 } else {
....3151 }
3153 }
3154
3156 dlm_init_mle(mle, DLM_MLE_MIGRATION, dlm, res, name, namelen);
3157 mle->new_master = new_master; ......
3163 __dlm_insert_mle(dlm, mle);
3164
3165 return ret;
3166 }
regards,
wengang.
PATCH 1/1 OCFS2: don't leave free'd mle attached to hb events
oops... I read it incorrectly. But that does not sound right. Let me think about it.
Quoted 72 lines · Wengang Wang
Hi Sunil,
Quoted 15 lines · Sunil Mushran
NAK
Quoted 11 lines · wengang wang
don't leave free'd mle attached to hb events.
indlm_add_migration_mle()the mle is attched to "heartbeat
events" anyway no
matter there is an existing mle with same name(returns-EEXIST).dlm_migrate_lockres()callsdlm_add_migration_mle(). in case the later function
returning-EEXIST,dlm_migrate_lockres()frees the (new) mle without detaching
it from "hb events". so that later "hb events" related operations could improperly
operate against wrong mle objects or against an invalid memory address.Quoted 6 lines
The mle is attached to hb events in
dlm_init_mle()which is not called if it returns-EEXIST. When it returns-EEXIST, oldmle is set to the existing mle and its refcounting is handled correctly. mle is not touched
and thus only needs to be freed.Maybe I am wrong. but are you sure
dlm_init_mle()is not called when it returns-EEXIST?
in code, it doesn't return immediately after setting ret with-EEXIST, but continue to calldlm_init_mle();
and thenmle->new_master=new_master;Maybe I am wrong somewhere?
simplified code pasted here:3098 static int dlm_add_migration_mle(struct
dlm_ctxt*dlm,3099 struct dlm_lock_resource *res, 3100 struct dlm_master_list_entry *mle, 3101 struct dlm_master_list_entry**oldmle,
3102 const char *name, unsigned int
namelen,
3103 u8new_master, u8 master)
3104 {
3116 found =dlm_find_mle(dlm, oldmle, (char *)name, namelen);
3117 if (found) {
3118 structdlm_master_list_entry*tmp = *oldmle;
3120 if (tmp->type==DLM_MLE_MIGRATION) {
3121 if (master ==dlm->node_num) {
3126 ret =-EEXIST;
3127 } else {
3136BUG();
3137 }3138 } else { ....3151 }
3153 }
3154
3156 dlm_init_mle(mle,DLM_MLE_MIGRATION, dlm, res, name,
namelen);3157 mle->new_master = new_master; ......3163
__dlm_insert_mle(dlm, mle);
3164
3165 return ret;
3166 }regards,
wengang.
PATCH 1/1 OCFS2: don't leave free'd mle attached to hb events
Just a reminder:)
Quoted 22 lines · Sunil Mushran
oops... I read it incorrectly. But that does not sound right. Let me think about it.
Quoted 18 lines · Wengang Wang
Hi Sunil,
Quoted 15 lines · Sunil Mushran
NAK
Quoted 11 lines · wengang wang
don't leave free'd mle attached to hb events.
indlm_add_migration_mle()the mle is attched to "heartbeat
events" anyway no
matter there is an existing mle with same name(returns-EEXIST).dlm_migrate_lockres()callsdlm_add_migration_mle(). in case the later function
returning-EEXIST,dlm_migrate_lockres()frees the (new) mle without detaching
it from "hb events". so that later "hb events" related operations could improperly
operate against wrong mle objects or against an invalid memory address.