lib/igt_hook: Fix realloc size to avoid memory overwriting
PATCH 1/1 lib/igt_hook: Fix realloc size to avoid memory overwriting
Doubling test name size might be not enough for realloc if target name length is larger than test/subtest name size.
--- lib/igt_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/igt_hook.c +1 -1
@@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, structif (len +1 > *size_ptr) {size_t fullname_size; - *size_ptr *=2 ; + *size_ptr += len +1 ; *name_ptr =realloc (*name_ptr, *size_ptr); fullname_size =igt_hook_calc_test_fullname_size (igt_hook);
Signature · 1 line
2.54.0
Quoted 23 lines · Zbigniew Kempczyński
Doubling test name size might be not enough for realloc if target name length is larger than test/subtest name size.
Signed-off-by Zbigniew Kempczyński <[email protected]>Cc Gustavo Sousa <[email protected]>Cc Ryszard Knop <[email protected]>--- lib/igt_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/igt_hook.c +1
-1@@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, structif (len +1 > *size_ptr) {size_t fullname_size; - *size_ptr *=2 ; + *size_ptr += len +1 ; *name_ptr =realloc (*name_ptr, *size_ptr); fullname_size =igt_hook_calc_test_fullname_size (igt_hook);
Quoted 15 lines · Zbigniew Kempczyński
Doubling test name size might be not enough for realloc if target name length is larger than test/subtest name size.
Signed-off-by Zbigniew Kempczyński <[email protected]>Cc Gustavo Sousa <[email protected]>Cc Ryszard Knop <[email protected]>--- lib/igt_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/igt_hook.c +0
-0
lib/igt_hook.c static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, struct · line 303
Quoted 5 lines
lib/igt_hook.c +1
-1@@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, structif (len +1 > *size_ptr) {size_t fullname_size; - *size_ptr *=2 ; + *size_ptr += len +1 ;
Oops. My bad. Thanks for finding this!
Do we need to use "+=" instead of "=" above, though?
Also, perhaps we could use roundup_power_of_two(len + 1) to reduce the number of follow-up reallocs?
--
Gustavo Sousa
Quoted 5 lines
lib/igt_hook.c +0
-0*name_ptr =realloc (*name_ptr, *size_ptr); fullname_size =igt_hook_calc_test_fullname_size (igt_hook);Signature · 1 line
2.54.0
Quoted 25 lines · Gustavo Sousa
Quoted 15 lines · Zbigniew Kempczyński
Doubling test name size might be not enough for realloc if target name length is larger than test/subtest name size.
Signed-off-by Zbigniew Kempczyński <[email protected]>Cc Gustavo Sousa <[email protected]>Cc Ryszard Knop <[email protected]>--- lib/igt_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/igt_hook.c +0
-0lib/igt_hook.c static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, struct · line 303
Quoted 5 lines
lib/igt_hook.c +1
-1@@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, structif (len +1 > *size_ptr) {size_t fullname_size; - *size_ptr *=2 ; + *size_ptr += len +1 ;Oops. My bad. Thanks for finding this!
Quoted 4 lines
Do we need to use "+=" instead of "=" above, though?
Also, perhaps we could use
roundup_power_of_two(len + 1)to reduce the number of follow-up reallocs?
Yes, that was my intention, maybe I should to add a comment but that was quickfix and didn't think about it.
--
Zbigniew
Quoted 9 lines
--
Gustavo SousaQuoted 5 lines
lib/igt_hook.c +0
-0*name_ptr =realloc (*name_ptr, *size_ptr); fullname_size =igt_hook_calc_test_fullname_size (igt_hook);Signature · 1 line
2.54.0
Quoted 25 lines · Gustavo Sousa
Quoted 15 lines · Zbigniew Kempczyński
Doubling test name size might be not enough for realloc if target name length is larger than test/subtest name size.
Signed-off-by Zbigniew Kempczyński <[email protected]>Cc Gustavo Sousa <[email protected]>Cc Ryszard Knop <[email protected]>--- lib/igt_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/igt_hook.c +0
-0lib/igt_hook.c static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, struct · line 303
Quoted 5 lines
lib/igt_hook.c +1
-1@@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, structif (len +1 > *size_ptr) {size_t fullname_size; - *size_ptr *=2 ; + *size_ptr += len +1 ;Oops. My bad. Thanks for finding this!
Quoted 4 lines
Do we need to use "+=" instead of "=" above, though?
Also, perhaps we could use
roundup_power_of_two(len + 1)to reduce the number of follow-up reallocs?
Sorry, I haven't explained why I used "+=" instead of "=". That was first what comes to my mind to fix the issue and try to decrease number of reallocs more than with simple '='. For smaller sizes I'm not sure if size of power of two is better than any other value. Glibc adds some overhead to malloc so I think any strategy we pick which increases buffer underneath is acceptable to me.
--
Zbigniew
Quoted 9 lines
--
Gustavo SousaQuoted 5 lines
lib/igt_hook.c +0
-0*name_ptr =realloc (*name_ptr, *size_ptr); fullname_size =igt_hook_calc_test_fullname_size (igt_hook);Signature · 1 line
2.54.0
Quoted 31 lines · Zbigniew Kempczyński
Quoted 25 lines · Gustavo Sousa
Quoted 15 lines · Zbigniew Kempczyński
Doubling test name size might be not enough for realloc if target name length is larger than test/subtest name size.
Signed-off-by Zbigniew Kempczyński <[email protected]>Cc Gustavo Sousa <[email protected]>Cc Ryszard Knop <[email protected]>--- lib/igt_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/igt_hook.c +0
-0lib/igt_hook.c static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, struct · line 303
Quoted 5 lines
lib/igt_hook.c +1
-1@@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, structif (len +1 > *size_ptr) {size_t fullname_size; - *size_ptr *=2 ; + *size_ptr += len +1 ;Oops. My bad. Thanks for finding this!
Quoted 4 lines
Do we need to use "+=" instead of "=" above, though?
Also, perhaps we could use
roundup_power_of_two(len + 1)to reduce the number of follow-up reallocs?
Quoted 6 lines
Sorry, I haven't explained why I used "+=" instead of "=". That was first what comes to my mind to fix the issue and try to decrease number of reallocs more than with simple '='. For smaller sizes I'm not sure if size of power of two is better than any other value. Glibc adds some overhead to malloc so I think any strategy we pick which increases buffer underneath is acceptable to me.
I just though "+=" adding exactly the size needed as an "extra" looked odd and didn't initially get that this indeed had the objective of avoiding extra reallocs in the future. I wonder if future readers of the code will get the same perception or if that's just me.
--
Gustavo Sousa
Quoted 14 lines
--
ZbigniewQuoted 9 lines
--
Gustavo SousaQuoted 5 lines
lib/igt_hook.c +0
-0*name_ptr =realloc (*name_ptr, *size_ptr); fullname_size =igt_hook_calc_test_fullname_size (igt_hook);Signature · 1 line
2.54.0
Quoted 2 lines · Zbigniew Kempczyński
Doubling test name size might be not enough for realloc if target name length is larger than test/subtest name size.
Might one to point out (if) this is the cause for the segfaults we've been seeing in CI.
BR,
Jani.
Quoted 21 lines
Signed-off-by Zbigniew Kempczyński <[email protected]>Cc Gustavo Sousa <[email protected]>Cc Ryszard Knop <[email protected]>--- lib/igt_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/igt_hook.c +1
-1@@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, structif (len +1 > *size_ptr) {size_t fullname_size; - *size_ptr *=2 ; + *size_ptr += len +1 ; *name_ptr =realloc (*name_ptr, *size_ptr); fullname_size =igt_hook_calc_test_fullname_size (igt_hook);
Signature · 1 line
Jani Nikula, Intel
Quoted 6 lines · Jani Nikula
Quoted 2 lines · Zbigniew Kempczyński
Doubling test name size might be not enough for realloc if target name length is larger than test/subtest name size.
Might one to point out (if) this is the cause for the segfaults we've been seeing in CI.
Also, Fixes: ?
Quoted 25 lines
BR,
Jani.Quoted 21 lines
Signed-off-by Zbigniew Kempczyński <[email protected]>Cc Gustavo Sousa <[email protected]>Cc Ryszard Knop <[email protected]>--- lib/igt_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/igt_hook.c +1
-1@@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, structif (len +1 > *size_ptr) {size_t fullname_size; - *size_ptr *=2 ; + *size_ptr += len +1 ; *name_ptr =realloc (*name_ptr, *size_ptr); fullname_size =igt_hook_calc_test_fullname_size (igt_hook);
Signature · 1 line
Jani Nikula, Intel
Quoted 9 lines · Jani Nikula
Quoted 6 lines · Jani Nikula
Quoted 2 lines · Zbigniew Kempczyński
Doubling test name size might be not enough for realloc if target name length is larger than test/subtest name size.
Might one to point out (if) this is the cause for the segfaults we've been seeing in CI.
Also, Fixes: ?
I'm sorry, I wasn't aware of this issue id, just got link to failing job so I wanted to fix it quickly. I promise I'll behave decent in the future and will check this id before sending the patch.
--
Zbigniew
Quoted 29 lines
Quoted 26 lines
BR,
Jani.Quoted 21 lines
Signed-off-by Zbigniew Kempczyński <[email protected]>Cc Gustavo Sousa <[email protected]>Cc Ryszard Knop <[email protected]>--- lib/igt_hook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/igt_hook.c +1
-1@@ -300,7 +300,7 @@ static void igt_hook_update_test_name_pre_call(struct igt_hook *igt_hook, structif (len +1 > *size_ptr) {size_t fullname_size; - *size_ptr *=2 ; + *size_ptr += len +1 ; *name_ptr =realloc (*name_ptr, *size_ptr); fullname_size =igt_hook_calc_test_fullname_size (igt_hook);Signature · 1 line
Jani Nikula, Intel
Patchwork
CI✗ Fi.CI.BAT: failure for lib/igt_hook: Fix realloc size to avoid memory overwriting
In reply to Zbigniew Kempczyński== Series Details ==
== Series Details ==
Series: lib/igt_hook: Fix realloc size to avoid memory overwriting
URL : https://patchwork.freedesktop.org/series/169418/
State : failure
== Summary ==
Series 169418 revision 1 was fully merged or fully failed: no git log