Skip to contentSkip to conversation

module: Fix NULL vs IS_ERR checking for module_get_next_page

PATCH In review Miaoqian Lin 3 participants 6 messages Nov 10, 2022 Module support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 module: Fix NULL vs IS_ERR checking for module_get_next_page

The module_get_next_page() function return error pointers on error instead of NULL.
Use IS_ERR() to check the return value to fix this.

Fixes b1ae6dc41eaa ("module: add in-kernel support for decompressing")
---
 kernel/module/decompress.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/module/decompress.c +4 -4
index c033572d83f0..720e719253cd 100644
@@ -114,8 +114,8 @@ static ssize_t module_gzip_decompress(struct load_info *info,
 	do {
 		struct page *page = module_get_next_page(info);
 
-		if (!page) {
-			retval = -ENOMEM;
+		if (IS_ERR(page)) {
+			retval = PTR_ERR(page);
 			goto out_inflate_end;
 		}
 
@@ -173,8 +173,8 @@ static ssize_t module_xz_decompress(struct load_info *info,
 	do {
 		struct page *page = module_get_next_page(info);
 
-		if (!page) {
-			retval = -ENOMEM;
+		if (IS_ERR(page)) {
+			retval = PTR_ERR(page);
 			goto out;
 		}
 
Signature · 1 line
2.37.3.671.ge2130fe6da78.dirty
maintainer
#1 lore raw
Quoted 7 lines · Miaoqian Lin

The module_get_next_page() function return error pointers on error instead of NULL.
Use IS_ERR() to check the return value to fix this.

Fixes b1ae6dc41eaa ("module: add in-kernel support for decompressing")

---

Thanks queued up. How did you find out? Just code inspection? I see chances are low of this triggering, but just curious how you found it.

Luis

#2 lore raw

Hi,

Quoted 10 lines · Luis Chamberlain
Quoted 7 lines · Miaoqian Lin

The module_get_next_page() function return error pointers on error instead of NULL.
Use IS_ERR() to check the return value to fix this.

Fixes b1ae6dc41eaa ("module: add in-kernel support for decompressing")

---

Thanks queued up. How did you find out? Just code inspection? I see chances are low of this triggering, but just curious how you found it.

I found this by static analysis, specifically, I obtained functions that return error pointers and

inspected whether their callers followed the correct specification.

Quoted 1 line

Luis

maintainer
#3 lore raw
Quoted 8 lines · Miaoqian Lin

Hi,

Quoted 5 lines · Luis Chamberlain
Quoted 4 lines · Miaoqian Lin

The module_get_next_page() function return error pointers on error instead of NULL.
Use IS_ERR() to check the return value to fix this.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Fixes b1ae6dc41eaa ("module: add in-kernel support for decompressing")

---

Thanks queued up. How did you find out? Just code inspection? I see chances are low of this triggering, but just curious how you found it.

I found this by static analysis, specifically, I obtained functions that return error pointers and inspected whether their callers followed the correct specification.

Which one did you use?

Luis

#4 lore raw
Quoted 9 lines · Luis Chamberlain
Quoted 8 lines · Miaoqian Lin

Hi,

Quoted 5 lines · Luis Chamberlain
Quoted 4 lines · Miaoqian Lin

The module_get_next_page() function return error pointers on error instead of NULL.
Use IS_ERR() to check the return value to fix this.

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Fixes b1ae6dc41eaa ("module: add in-kernel support for decompressing")

---

Thanks queued up. How did you find out? Just code inspection? I see chances are low of this triggering, but just curious how you found it.

I found this by static analysis, specifically, I obtained functions that return error pointers and inspected whether their callers followed the correct specification.

Which one did you use?

I wrote custom checker based on the weggli tool (https://github.com/googleprojectzero/weggli).

Quoted 1 line

Luis