Skip to contentSkip to conversation

kcsan: test: don't put the expect array on the stack

PATCH In review Max Filippov 2 participants 3 messages Dec 31, 2022 – Jan 2, 2023 KCSAN

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kcsan: test: don't put the expect array on the stack

Size of the 'expect' array in the __report_matches is 1536 bytes, which is exactly the default frame size warning limit of the xtensa architecture.
As a result allmodconfig xtensa kernel builds with the gcc that does not support the compiler plugins (which otherwise would push the said warning limit to 2K) fail with the following message:

kernel/kcsan/kcsan_test.c:257:1: error: the frame size of 1680 bytes
is larger than 1536 bytes

Fix it by dynamically alocating the 'expect' array.

---
Changes v1->v2:
- add WARN_ON in case of kmalloc failure

 kernel/kcsan/kcsan_test.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/kcsan/kcsan_test.c +6 -1
index dcec1b743c69..a60c561724be 100644
@@ -159,7 +159,7 @@ static bool __report_matches(const struct expect_report *r)
 	const bool is_assert = (r->access[0].type | r->access[1].type) & KCSAN_ACCESS_ASSERT;
 	bool ret = false;
 	unsigned long flags;
-	typeof(observed.lines) expect;
+	typeof(*observed.lines) *expect;
 	const char *end;
 	char *cur;
 	int i;
@@ -168,6 +168,10 @@ static bool __report_matches(const struct expect_report *r)
 	if (!report_available())
 		return false;
 
+	expect = kmalloc(sizeof(observed.lines), GFP_KERNEL);
+	if (WARN_ON(!expect))
+		return false;
+
 	/* Generate expected report contents. */
 
 	/* Title */
@@ -253,6 +257,7 @@ static bool __report_matches(const struct expect_report *r)
 		strstr(observed.lines[2], expect[1])));
 out:
 	spin_unlock_irqrestore(&observed.lock, flags);
+	kfree(expect);
 	return ret;
 }
 
Signature · 1 line
2.30.2
maintainer Reviewed-by Tested-by on v2 1/1
#1 lore raw
Quoted 8 lines · Max Filippov

Size of the 'expect' array in the __report_matches is 1536 bytes, which is exactly the default frame size warning limit of the xtensa architecture.
As a result allmodconfig xtensa kernel builds with the gcc that does not support the compiler plugins (which otherwise would push the said warning limit to 2K) fail with the following message:

Quoted 6 lines

kernel/kcsan/kcsan_test.c:257:1: error: the frame size of 1680 bytes
is larger than 1536 bytes

Fix it by dynamically alocating the 'expect' array.

Can you take this through the xtensa tree?

Quoted 46 lines

---
Changes v1->v2:
- add WARN_ON in case of kmalloc failure

 kernel/kcsan/kcsan_test.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/kcsan/kcsan_test.c +6 -2
index dcec1b743c69..a60c561724be 100644
@@ -159,7 +159,7 @@ static bool __report_matches(const struct expect_report *r)
        const bool is_assert = (r->access[0].type | r->access[1].type) & KCSAN_ACCESS_ASSERT;
        bool ret = false;
        unsigned long flags;
-       typeof(observed.lines) expect;
+       typeof(*observed.lines) *expect;
        const char *end;
        char *cur;
        int i;
@@ -168,6 +168,10 @@ static bool __report_matches(const struct expect_report *r)
        if (!report_available())
                return false;
 
+       expect = kmalloc(sizeof(observed.lines), GFP_KERNEL);
+       if (WARN_ON(!expect))
+               return false;
+
        /* Generate expected report contents. */
 
        /* Title */
@@ -253,6 +257,7 @@ static bool __report_matches(const struct expect_report *r)
                strstr(observed.lines[2], expect[1])));
 out:
        spin_unlock_irqrestore(&observed.lock, flags);
+       kfree(expect);
        return ret;
 }
 
--

2.30.2

--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20221231004514.317809-1-jcmvbkbc%40gmail.com.

#2 lore raw
Quoted 13 lines · Marco Elver
Quoted 11 lines · Max Filippov

Size of the 'expect' array in the __report_matches is 1536 bytes, which is exactly the default frame size warning limit of the xtensa architecture.
As a result allmodconfig xtensa kernel builds with the gcc that does not support the compiler plugins (which otherwise would push the said warning limit to 2K) fail with the following message:

kernel/kcsan/kcsan_test.c:257:1: error: the frame size of 1680 bytes
is larger than 1536 bytes

Quoted 8 lines
Quoted 3 lines

Fix it by dynamically alocating the 'expect' array.

Can you take this through the xtensa tree?

Sure. Thanks for your review and testing.

-- Max