dlm: check negative length in dlm_search_rsb_tree
PATCH 1/1 dlm: check negative length in dlm_search_rsb_tree
commit 080e5563f878 only checks for len > DLM_RESNAME_MAXLEN, which does not catch negative values. While the input 'len' can be negative and a negative int passed to memcpy() is implicitly converted to a large size_t, causing a stack buffer overflow on the key[] array.
Fix this by also rejecting len <= 0.
--- fs/dlm/lock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/dlm/lock.c +3 -1
@@ -626,8 +626,10 @@ int dlm_search_rsb_tree(struct rhashtable *rhash, const void *name, int len, struct dlm_rsb **r_ret) {char key[DLM_RESNAME_MAXLEN ] = {}; -if (len >DLM_RESNAME_MAXLEN ) + +if (len <=0 || len >DLM_RESNAME_MAXLEN )return -EINVAL ; +memcpy (key, name, len); *r_ret =rhashtable_lookup_fast (rhash, &key, dlm_rhash_rsb_params);if (*r_ret)
Signature · 1 line
2.39.3
Alexander Aring
maintainerHi,
Quoted 7 lines · Joseph Qi
commit
080e5563f878only checks for len >DLM_RESNAME_MAXLEN, which does not catch negative values. While the input 'len' can be negative and a negative int passed tomemcpy()is implicitly converted to a largesize_t, causing a stack buffer overflow on the key[] array.Fix this by also rejecting len <= 0.
or change the parameter to unsigned?
- Alex
Quoted 4 lines · Alexander Aring
Hi,
Quoted 1 line · Joseph Qi
Quoted 9 lines
Quoted 6 lines
commit
080e5563f878only checks for len >DLM_RESNAME_MAXLEN, which does not catch negative values. While the input 'len' can be negative and a negative int passed tomemcpy()is implicitly converted to a largesize_t, causing a stack buffer overflow on the key[] array.Fix this by also rejecting len <= 0.
or change the parameter to unsigned?
Yes, it would be fine. I'll work on it and send v2 later.
Thanks,
Joseph