Skip to contentSkip to conversation

kcsan: debugfs: Use krealloc_array() to replace krealloc()

PATCH Superseded Andy Shevchenko 2 participants 5 messages Nov 21, 2024 KCSAN

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kcsan: debugfs: Use krealloc_array() to replace krealloc()

Use krealloc_array() to replace krealloc() with multiplication. krealloc_array() has multiply overflow check, which will be safer.

---
 kernel/kcsan/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/kcsan/debugfs.c +3 -3
index 53b21ae30e00..be7051d0e7f4 100644
@@ -166,10 +166,10 @@ static ssize_t insert_report_filterlist(const char *func)
 	} else if (report_filterlist.used == report_filterlist.size) {
 		/* resize filterlist */
 		size_t new_size = report_filterlist.size * 2;
-		unsigned long *new_addrs =
-			krealloc(report_filterlist.addrs,
-				 new_size * sizeof(unsigned long), GFP_ATOMIC);
+		unsigned long *new_addrs;
 
+		new_addrs = krealloc_array(report_filterlist.addrs,
+					   new_size, sizeof(*new_addrs), GFP_ATOMIC);
 		if (new_addrs == NULL) {
 			/* leave filterlist itself untouched */
 			ret = -ENOMEM;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Andy Shevchenko

Use krealloc_array() to replace krealloc() with multiplication. krealloc_array() has multiply overflow check, which will be safer.

Do you have a tree to take this through? Otherwise I'll take it.

Quoted 25 lines
---
 kernel/kcsan/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/kcsan/debugfs.c +3 -4
index 53b21ae30e00..be7051d0e7f4 100644
@@ -166,10 +166,10 @@ static ssize_t insert_report_filterlist(const char *func)
        } else if (report_filterlist.used == report_filterlist.size) {
                /* resize filterlist */
                size_t new_size = report_filterlist.size * 2;
-               unsigned long *new_addrs =
-                       krealloc(report_filterlist.addrs,
-                                new_size * sizeof(unsigned long), GFP_ATOMIC);
+               unsigned long *new_addrs;
 
+               new_addrs = krealloc_array(report_filterlist.addrs,
+                                          new_size, sizeof(*new_addrs), GFP_ATOMIC);
                if (new_addrs == NULL) {
                        /* leave filterlist itself untouched */
                        ret = -ENOMEM;
--

2.43.0.rc1.1336.g36b5255a03ac

#2 lore raw
Quoted 9 lines · Marco Elver
Quoted 5 lines · Andy Shevchenko

Use krealloc_array() to replace krealloc() with multiplication. krealloc_array() has multiply overflow check, which will be safer.

Thank you!

Quoted 1 line

Do you have a tree to take this through? Otherwise I'll take it.

No, but please, wait a bit, I have a sequential dependent patch. I'll send a v2 soon.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw
In reply to Marco Elver
Quoted 10 lines · Marco Elver
Quoted 5 lines · Andy Shevchenko

Use krealloc_array() to replace krealloc() with multiplication. krealloc_array() has multiply overflow check, which will be safer.

Unreview.

Quoted 1 line

Do you have a tree to take this through? Otherwise I'll take it.

Whoops. We got rid of that krealloc() in 59458fa4ddb4 ("kcsan: Turn report_filterlist_lock into a raw_spinlock"). And the replacement kmalloc() is already a kmalloc_array(). I suppose this patch is therefore obsolete.

#4 lore raw
Quoted 11 lines · Marco Elver
Quoted 9 lines · Marco Elver
Quoted 5 lines · Andy Shevchenko

Use krealloc_array() to replace krealloc() with multiplication. krealloc_array() has multiply overflow check, which will be safer.

Quoted 8 lines

Unreview.

Quoted 1 line

Do you have a tree to take this through? Otherwise I'll take it.

Whoops. We got rid of that krealloc() in 59458fa4ddb4 ("kcsan: Turn report_filterlist_lock into a raw_spinlock"). And the replacement kmalloc() is already a kmalloc_array(). I suppose this patch is therefore obsolete.

Ah, I made this on top of v6.12 + something most likely unrelated.

Signature · 2 lines
With Best Regards,
Andy Shevchenko