dlm: pending patches
Alexander Aring
maintainercover dlm: pending patches
Hi David,
Those are the pending patches for DLM. More checks to caught an invalid node weight calulcation for members array, fix typos and be more type aligned with debugfs api and the return type of waiters_read().
- Alex
Dan Carpenter (1):
dlm: clean up a type in waiters_read()
Hemanth Selam (1):
dlm: fix typos in comments
Qing Ming (1):
dlm: validate node weights before building member array
fs/dlm/ast.c | 2 +- fs/dlm/config.c | 9 ++++++++- fs/dlm/debug_fs.c | 3 ++- fs/dlm/lock.c | 2 +- fs/dlm/member.c | 17 +++++++++++------ 5 files changed, 23 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH RESEND 1/3 dlm: validate node weights before building member array
From: Qing Ming <[email protected]>
DLM node weights are parsed as signed integers and copied into the member list. make_member_array() uses their sum as the allocation count, but only positive weights contribute entries to the array. A negative weight can therefore reduce the allocation without reducing the number of writes.
The issue was found through static analysis of the configfs input and member array construction. With two recovery members weighted -31 and 32, the sum is 1, so recovery allocates one int and then writes the positive member's node ID 32 times. A reproducer using dlm_controld and dlm_tool triggered the same report on a KASAN kernel:
BUG: KASAN: slab-out-of-bounds in dlm_recover_members [dlm] Write of size 4 by task dlm_recoverd Call Trace: dlm_recover_members dlm_recoverd kthread ret_from_fork
Reject negative weights at the configfs input boundary. Also detect overflow when adding non-negative weights to the signed allocation count, and propagate array construction errors to the recovery path.
--- fs/dlm/config.c | 9 ++++++++- fs/dlm/member.c | 17 +++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-)
fs/dlm/config.c +8 -1
@@ -857,10 +857,17 @@ static ssize_t node_weight_show(struct config_item *item, char *buf)static ssize_t node_weight_store (struct config_item *item,const char *buf,size_t len) { -int rc =kstrtoint (buf,0 , &config_item_to_node (item)->weight); +struct dlm_node *node =config_item_to_node (item); +int weight; +int rc; + rc =kstrtoint (buf,0 , &weight);if (rc)return rc; +if (weight <0 ) +return -EINVAL ; + + node->weight = weight;return len; }
fs/dlm/member.c +11 -6
@@ -402,7 +402,7 @@ void dlm_clear_members_gone(struct dlm_ls *ls)clear_memb_list (&ls->ls_nodes_gone,NULL ); } -static void make_member_array (struct dlm_ls *ls) +static int make_member_array (struct dlm_ls *ls) {struct dlm_member *memb;int i, w, x =0 , total =0 , all_zero =0 , *array;
@@ -411,8 +411,8 @@ static void make_member_array(struct dlm_ls *ls) ls->ls_node_array =NULL ;list_for_each_entry (memb, &ls->ls_nodes, list) { -if (memb->weight) - total += memb->weight; +if (check_add_overflow (total, memb->weight, &total)) +return -EOVERFLOW ; }/* all nodes revert to weight of 1 if all have weight 0 */
@@ -422,10 +422,9 @@ static void make_member_array(struct dlm_ls *ls) all_zero =1 ; } - ls->ls_total_weight = total; array =kmalloc_objs (*array, total,GFP_NOFS );if (!array) -return ; +return -ENOMEM ;list_for_each_entry (memb, &ls->ls_nodes, list) {if (!all_zero && !memb->weight)
@@ -442,7 +441,10 @@ static void make_member_array(struct dlm_ls *ls) array[x++] = memb->nodeid; } + ls->ls_total_weight = total; ls->ls_node_array = array; + +return 0 ; }/* send a status request to all members just to establish comms connections */
@@ -617,7 +619,10 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out) } ls->ls_low_nodeid = low; -make_member_array (ls); + error =make_member_array (ls); +if (error) +return error; + *neg_out = neg; error =ping_members (ls, rv->seq);
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH RESEND 2/3 dlm: clean up a type in waiters_read()
In reply to Alexander AringFrom: Dan Carpenter <[email protected]>
This doesn't affect runtime but "rv" stores error codes and so declare it as ssize_t instead of size_t.
--- fs/dlm/debug_fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/dlm/debug_fs.c +2 -1
@@ -596,7 +596,8 @@ static ssize_t waiters_read(struct file *file, char __user *userbuf, {struct dlm_ls *ls = file->private_data;struct dlm_lkb *lkb; -size_t len =DLM_DEBUG_BUF_LEN , pos =0 , ret, rv; +size_t len =DLM_DEBUG_BUF_LEN , pos =0 , ret; +ssize_t rv;mutex_lock (&debug_buf_lock); ret =dlm_lock_recovery_try (ls);
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH RESEND 3/3 dlm: fix typos in comments
In reply to Alexander AringFrom: Hemanth Selam <[email protected]>
Fix typos in comments, reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes.
--- fs/dlm/ast.c | 2 +- fs/dlm/lock.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/dlm/ast.c +1 -1
@@ -81,7 +81,7 @@ bool dlm_may_skip_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,* Suppress some redundant basts here, do more on removal. * Don't even add a bast if the callback just before it * is a bast for the same mode or a more restrictive mode. -* (the addional > PR check is needed for PR/CW inversion) +* (the additional > PR check is needed for PR/CW inversion) */ if (lkb->lkb_last_cb_mode !=-1 && lkb->lkb_last_cb_flags &DLM_CB_BAST ) {
fs/dlm/lock.c +1 -1
@@ -92,7 +92,7 @@ static void do_purge(struct dlm_ls *ls, int nodeid, int pid);static void deactivate_rsb (struct kref *kref);/* -* Lock compatibilty matrix - thanks Steve +* Lock compatibility matrix - thanks Steve * UN = Unlocked state. Not really a state, used as a flag * PD = Padding. Used to make the matrix a nice power of two in size * Other states are the same as the VMS DLM.
Signature · 1 line
2.43.0