Skip to contentSkip to conversation

kasan: avoid -Wmaybe-uninitialized warning

PATCH Superseded Arnd Bergmann 3 participants 5 messages Jul 21, 2017 – Jul 25, 2017

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kasan: avoid -Wmaybe-uninitialized warning

gcc-7 produces this warning:

mm/kasan/report.c: In function 'kasan_report':
mm/kasan/report.c:351:3: error: 'info.first_bad_addr' may be used uninitialized in this function [-Werror=maybe-uninitialized]
print_shadow_for_address(info->first_bad_addr);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/kasan/report.c:360:27: note: 'info.first_bad_addr' was declared here

The code seems fine as we only print info.first_bad_addr when there is a shadow, and we always initialize it in that case, but this is relatively hard for gcc to figure out after the latest rework. Adding an intialization in the other code path gets rid of the warning.

Fixes b235b9808664 ("kasan: unify report headers")

---
Originally submitted on March 23, but unfortunately is still needed, as verified on 4.13-rc1, with aarch64-linux-gcc-7.1.1

v2: add a comment as Andrew suggested

---
 mm/kasan/report.c | 3 +++
 1 file changed, 3 insertions(+)
mm/kasan/report.c +3 -0
index 04bb1d3eb9ec..28fb222ab149 100644
@@ -111,6 +111,9 @@ static const char *get_wild_bug_type(struct kasan_access_info *info)
 {
 	const char *bug_type = "unknown-crash";
 
+	/* shut up spurious -Wmaybe-uninitialized warning */
+	info->first_bad_addr = (void *)(-1ul);
+
 	if ((unsigned long)info->access_addr < PAGE_SIZE)
 		bug_type = "null-ptr-deref";
 	else if ((unsigned long)info->access_addr < TASK_SIZE)
Signature · 7 lines
2.9.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 31 lines · Arnd Bergmann

gcc-7 produces this warning:

mm/kasan/report.c: In function 'kasan_report':
mm/kasan/report.c:351:3: error: 'info.first_bad_addr' may be used uninitialized in this function [-Werror=maybe-uninitialized]

   print_shadow_for_address(info->first_bad_addr);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mm/kasan/report.c:360:27: note: 'info.first_bad_addr' was declared here

The code seems fine as we only print info.first_bad_addr when there is a shadow, and we always initialize it in that case, but this is relatively hard for gcc to figure out after the latest rework. Adding an intialization in the other code path gets rid of the warning.

Fixes b235b9808664 ("kasan: unify report headers")

---
Originally submitted on March 23, but unfortunately is still needed, as verified on 4.13-rc1, with aarch64-linux-gcc-7.1.1

v2: add a comment as Andrew suggested

---
 mm/kasan/report.c | 3 +++
 1 file changed, 3 insertions(+)
mm/kasan/report.c +0 -0
index 04bb1d3eb9ec..28fb222ab149 100644

mm/kasan/report.c static const char *get_wild_bug_type(struct kasan_access_info *info) · line 116

Quoted 6 lines
mm/kasan/report.c +3 -0
@@ -111,6 +111,9 @@ static const char *get_wild_bug_type(struct kasan_access_info *info)
 {
        const char *bug_type = "unknown-crash";
 
+       /* shut up spurious -Wmaybe-uninitialized warning */
+       info->first_bad_addr = (void *)(-1ul);
+

Why don't we initialize info.first_bad_addr in kasan_report(), where info is allocated?

Quoted 6 lines
mm/kasan/report.c +0 -1
        if ((unsigned long)info->access_addr < PAGE_SIZE)
                bug_type = "null-ptr-deref";
        else if ((unsigned long)info->access_addr < TASK_SIZE)
--

2.9.0

Signature · 16 lines
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 10 lines · Alexander Potapenko
Quoted 8 lines · Arnd Bergmann
mm/kasan/report.c +0 -0
index 04bb1d3eb9ec..28fb222ab149 100644
@@ -111,6 +111,9 @@ static const char *get_wild_bug_type(struct kasan_access_info *info)
 {
        const char *bug_type = "unknown-crash";
 
Quoted 5 lines

mm/kasan/report.c static const char *get_wild_bug_type(struct kasan_access_info *info) · line 116

Quoted 3 lines
mm/kasan/report.c +3 -0
+       /* shut up spurious -Wmaybe-uninitialized warning */
+       info->first_bad_addr = (void *)(-1ul);
+

Why don't we initialize info.first_bad_addr in kasan_report(), where info is allocated?

I'm just trying to shut up a particular warning here where gcc can't figure out by itself that it is initialized. Setting an invalid address at allocation time would
prevent gcc from warning even for any trivial bug where we use the incorrect value in the normal code path, in case someone later wants to modify the code further and makes a mistake.

Arnd

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 17 lines · Arnd Bergmann
Quoted 10 lines · Alexander Potapenko
Quoted 8 lines · Arnd Bergmann
mm/kasan/report.c +0 -0
index 04bb1d3eb9ec..28fb222ab149 100644
@@ -111,6 +111,9 @@ static const char *get_wild_bug_type(struct kasan_access_info *info)
 {
        const char *bug_type = "unknown-crash";
 
Quoted 5 lines

mm/kasan/report.c static const char *get_wild_bug_type(struct kasan_access_info *info) · line 116

Quoted 3 lines
mm/kasan/report.c +3 -0
+       /* shut up spurious -Wmaybe-uninitialized warning */
+       info->first_bad_addr = (void *)(-1ul);
+

Why don't we initialize info.first_bad_addr in kasan_report(), where info is allocated?

Quoted 7 lines

I'm just trying to shut up a particular warning here where gcc can't figure out by itself that it is initialized. Setting an invalid address at allocation time would
prevent gcc from warning even for any trivial bug where we use the incorrect value in the normal code path, in case someone later wants to modify the code further and makes a mistake.

'info->first_bad_addr' could be initialized to the correct value. That would be 'addr' itself for 'wild' type of bugs.
Initialization in get_wild_bug_type() looks a bit odd and off-place.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 26 lines · Andrey Ryabinin
Quoted 17 lines · Arnd Bergmann
Quoted 10 lines · Alexander Potapenko
Quoted 8 lines · Arnd Bergmann
mm/kasan/report.c +0 -0
index 04bb1d3eb9ec..28fb222ab149 100644
@@ -111,6 +111,9 @@ static const char *get_wild_bug_type(struct kasan_access_info *info)
 {
        const char *bug_type = "unknown-crash";
 
Quoted 5 lines

mm/kasan/report.c static const char *get_wild_bug_type(struct kasan_access_info *info) · line 116

Quoted 3 lines
mm/kasan/report.c +3 -0
+       /* shut up spurious -Wmaybe-uninitialized warning */
+       info->first_bad_addr = (void *)(-1ul);
+

Why don't we initialize info.first_bad_addr in kasan_report(), where info is allocated?

Quoted 7 lines

I'm just trying to shut up a particular warning here where gcc can't figure out by itself that it is initialized. Setting an invalid address at allocation time would
prevent gcc from warning even for any trivial bug where we use the incorrect value in the normal code path, in case someone later wants to modify the code further and makes a mistake.

Quoted 3 lines

'info->first_bad_addr' could be initialized to the correct value. That would be 'addr' itself for 'wild' type of bugs.
Initialization in get_wild_bug_type() looks a bit odd and off-place.

Yes, that makes sense. I'll send a new version then.

Arnd

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>