Skip to contentSkip to conversation

dlm: check negative length in dlm_search_rsb_tree

PATCH In review Joseph Qi 2 participants 3 messages May 15 – May 17 Distributed lock manager (DLM)

lore
Share & tools
lore

Joseph Qi

author
#0 lore raw

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
index c381e1028446..124f68c8e653 100644
@@ -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
maintainer
#1 lore raw

Hi,

Quoted 7 lines · Joseph Qi

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.

or change the parameter to unsigned?

- Alex

author
#2 lore raw
Quoted 4 lines · Alexander Aring

Hi,

Quoted 1 line · Joseph Qi
Quoted 9 lines
Quoted 6 lines

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.

or change the parameter to unsigned?

Yes, it would be fine. I'll work on it and send v2 later.

Thanks,
Joseph