Fix a couple of potential problem (static analysis)
cover Fix a couple of potential problem (static analysis)
Yauheni Kaliuta (2):
libkmod-module: check "new_from_name" return value in get_builtin
libkmod-builtin: consider final NIL in name length check
libkmod/libkmod-builtin.c | 2 +- libkmod/libkmod-module.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 libkmod-module: check "new_from_name" return value in get_builtin
kmod_module_new_from_name() may fail and return error value. It is handled properly across the code, but in this particular place the check is missing.
--- libkmod/libkmod-module.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
libkmod/libkmod-module.c +4 -1
@@ -2912,7 +2912,10 @@ int kmod_module_get_builtin(struct kmod_ctx *ctx, struct kmod_list **list) goto fail; } -kmod_module_new_from_name (ctx, modname, &mod); + err =kmod_module_new_from_name (ctx, modname, &mod); +if (err <0 ) + goto fail; +kmod_module_set_builtin (mod, true); *list =kmod_list_append (*list, mod);
Signature · 1 line
2.31.1
PATCH 2/2 libkmod-builtin: consider final NIL in name length check
There is potential buffer overrun in kmod_builtin_iter_get_modname() for the name of length PATH_MAX. The required buffer size is PATH_MAX, so modname[len] = '\0' with len == PATH_MAX will write right beyond the buffer.
Check the length against PATH_MAX - 1.
--- libkmod/libkmod-builtin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libkmod/libkmod-builtin.c +1 -1
@@ -246,7 +246,7 @@ bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter, len = dot - line; -if (len >=PATH_MAX ) { +if (len >=PATH_MAX -1 ) { sv_errno =ENAMETOOLONG ; goto fail; }
Signature · 1 line
2.31.1
Re: [PATCH 2/2] libkmod-builtin: consider final NIL in name length check
Quoted 4 lines · Yauheni Kaliuta
There is potential buffer overrun in
kmod_builtin_iter_get_modname()for the name of lengthPATH_MAX. The required buffer size isPATH_MAX, somodname[len] = '\0'with len ==PATH_MAXwill write right beyond the buffer.
this doesn't look correct. "with len == PATH_MAX" we will actually return an error.
What indeed is happening is truncation: since we are not reserving 1 char for NUL termination, we will truncate the name. If we update the commit message to state the right reasoning, then we can land this patch.
I don't see any buffer overflow here, but I may be missing something.
thanks
LUcas De Marchi
Quoted 24 lines
Check the length against
PATH_MAX- 1.Signed-off-by Yauheni Kaliuta <[email protected]>---
libkmod/libkmod-builtin.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)libkmod/libkmod-builtin.c +1
-1@@ -246,7 +246,7 @@ bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter, len = dot - line; -if (len >=PATH_MAX ) { +if (len >=PATH_MAX -1 ) { sv_errno =ENAMETOOLONG ; goto fail; }Signature · 1 line
2.31.1
Re: [PATCH 2/2] libkmod-builtin: consider final NIL in name length check
Quoted 6 lines · Lucas De Marchi
Quoted 4 lines · Yauheni Kaliuta
There is potential buffer overrun in
kmod_builtin_iter_get_modname()for the name of lengthPATH_MAX. The required buffer size isPATH_MAX, somodname[len] = '\0'with len ==PATH_MAXwill write right beyond the buffer.
Quoted 8 lines
this doesn't look correct. "with len ==
PATH_MAX" we will actually return an error.What indeed is happening is truncation: since we are not reserving 1 char for NUL termination, we will truncate the name. If we update the commit message to state the right reasoning, then we can land this patch.
I don't see any buffer overflow here, but I may be missing something.
another thing... what is your git-sendemail setup? This is putting patch 2 as a reply to patch 1 and that breaks b4. See:
https://lore.kernel.org/linux-modules/[email protected]/T/#u
Lucas De Marchi
Quoted 28 lines
thanks
LUcas De MarchiQuoted 24 lines
Check the length against
PATH_MAX- 1.Signed-off-by Yauheni Kaliuta <[email protected]>---
libkmod/libkmod-builtin.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)libkmod/libkmod-builtin.c +1
-1@@ -246,7 +246,7 @@ bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter, len = dot - line; -if (len >=PATH_MAX ) { +if (len >=PATH_MAX -1 ) { sv_errno =ENAMETOOLONG ; goto fail; }Signature · 1 line
2.31.1
Re: [PATCH 2/2] libkmod-builtin: consider final NIL in name length check
Quoted 15 lines · Lucas De Marchi
Quoted 13 lines · Lucas De Marchi
Quoted 4 lines · Yauheni Kaliuta
There is potential buffer overrun in
kmod_builtin_iter_get_modname()for the name of lengthPATH_MAX. The required buffer size isPATH_MAX, somodname[len] = '\0'with len ==PATH_MAXwill write right beyond the buffer.this doesn't look correct. "with len ==
PATH_MAX" we will actually return an error.What indeed is happening is truncation: since we are not reserving 1 char for NUL termination, we will truncate the name. If we update the commit message to state the right reasoning, then we can land this patch.
Quoted 5 lines
Quoted 1 line
I don't see any buffer overflow here, but I may be missing something.
another thing... what is your git-sendemail setup? This is putting patch 2 as a reply to patch 1 and that breaks b4. See:
https://lore.kernel.org/linux-modules/[email protected]/T/#u
Thanks, yes. I have thread = true, but send it after the cover letter with
git send-email --to [email protected] --cc [email protected] [email protected] 0001-libkmod-module-check-new_from_name-return-value-in-g.patch 0002-libkmod-builtin-consider-final-NIL-in-name-length-ch.patch
So, the right way is to send all together, or disable 'thread'.
Quoted 32 lines
Lucas De Marchi
Quoted 28 lines
thanks
LUcas De MarchiQuoted 24 lines
Check the length against
PATH_MAX- 1.Signed-off-by Yauheni Kaliuta <[email protected]>---
libkmod/libkmod-builtin.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)libkmod/libkmod-builtin.c +1
-2@@ -246,7 +246,7 @@ bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter, len = dot - line; -if (len >=PATH_MAX ) { +if (len >=PATH_MAX -1 ) { sv_errno =ENAMETOOLONG ; goto fail; } --2.31.1
Signature · 1 line
WBR, Yauheni
Re: [PATCH 2/2] libkmod-builtin: consider final NIL in name length check
In reply to Lucas De MarchiHi, Lucas!
My filters missed your replies, sorry :(
Quoted 7 lines · Lucas De Marchi
Quoted 4 lines · Yauheni Kaliuta
There is potential buffer overrun in
kmod_builtin_iter_get_modname()for the name of lengthPATH_MAX. The required buffer size isPATH_MAX, somodname[len] = '\0'with len ==PATH_MAXwill write right beyond the buffer.
Quoted 8 lines
this doesn't look correct. "with len ==
PATH_MAX" we will actually return an error.What indeed is happening is truncation: since we are not reserving 1 char for NUL termination, we will truncate the name. If we update the commit message to state the right reasoning, then we can land this patch.
I don't see any buffer overflow here, but I may be missing something.
Yes, you are right. I see the actual overflow is fixed by 1cab02ecf6ee ("libkmod: fix an overflow with wrong modules.builtin.modinfo")
I should have checked some reports more carefully. Please, ignore the patch.
Quoted 19 lines
thanks
LUcas De MarchiQuoted 16 lines
Check the length against
PATH_MAX- 1.Signed-off-by Yauheni Kaliuta <[email protected]>---
libkmod/libkmod-builtin.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)libkmod/libkmod-builtin.c +0
-0@@ -246,7 +246,7 @@ bool kmod_builtin_iter_get_modname(struct kmod_builtin_iter *iter, len = dot - line;
Quoted 9 lines
Quoted 8 lines
libkmod/libkmod-builtin.c +1
-2-if (len >=PATH_MAX ) { +if (len >=PATH_MAX -1 ) { sv_errno =ENAMETOOLONG ; goto fail; } --2.31.1
--
WBR, Yauheni
Lucas De Marchi
AppliedRe: [PATCH 1/2] libkmod-module: check "new_from_name" return value in get_builtin
In reply to Yauheni KaliutaQuoted 5 lines · Yauheni Kaliuta
kmod_module_new_from_name()may fail and return error value. It is handled properly across the code, but in this particular place the check is missing.Signed-off-by Yauheni Kaliuta <[email protected]>
applied, thanks
Lucas De Marchi
Quoted 23 lines
---
libkmod/libkmod-module.c| 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)libkmod/libkmod-module.c +4
-1@@ -2912,7 +2912,10 @@ int kmod_module_get_builtin(struct kmod_ctx *ctx, struct kmod_list **list) goto fail; } -kmod_module_new_from_name (ctx, modname, &mod); + err =kmod_module_new_from_name (ctx, modname, &mod); +if (err <0 ) + goto fail; +kmod_module_set_builtin (mod, true); *list =kmod_list_append (*list, mod);Signature · 1 line
2.31.1