Skip to contentSkip to conversation

Input: apanel: avoid panic if ioreamp fails

PATCH In review Kefeng Wang 2 participants 7 messages May 10, 2019 – May 11, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Input: apanel: avoid panic if ioreamp fails

If ioremap fails, NULL pointer dereference will happen and leading to a kernel panic when access the virtual address in check_signature().

Fix it by check the return value of ioremap.

---
 drivers/input/misc/apanel.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/input/misc/apanel.c +3 -1
index c1e66f45d552..1c7262ad4b5b 100644
@@ -259,7 +259,9 @@ static int __init apanel_init(void)
 	unsigned char i2c_addr;
 	int found = 0;
 
-	bios = ioremap(0xF0000, 0x10000); /* Can't fail */
+	bios = ioremap(0xF0000, 0x10000);
+	if (!bios)
+		return -ENOMEM;
 
 	p = bios_signature(bios);
 	if (!p) {
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/3 Input: wistron_btns: avoid panic if ioreamp fails

If ioremap fails, NULL pointer dereference will happen and leading to a kernel panic when access the virtual address in check_signature().

Fix it by check the return value of ioremap.

---
 drivers/input/misc/wistron_btns.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/input/misc/wistron_btns.c +4 -1
index 43e67f546366..a82ec3d102b4 100644
@@ -107,7 +107,10 @@ static int __init map_bios(void)
 	ssize_t offset;
 	u32 entry_point;
 
-	base = ioremap(0xF0000, 0x10000); /* Can't fail */
+	base = ioremap(0xF0000, 0x10000);
+	if (!base)
+		return -ENOMEM;
+
 	offset = locate_wistron_bios(base);
 	if (offset < 0) {
 		printk(KERN_ERR "wistron_btns: BIOS entry point not found\n");
Signature · 1 line
2.20.1
#2 lore raw

PATCH 3/3 i2c: i801: avoid panic if ioreamp fails

In reply to Kefeng Wang

If ioremap fails, NULL pointer dereference will happen and leading to a kernel panic when access the virtual address in check_signature().

Fix it by check the return value of ioremap.

---
 drivers/i2c/busses/i2c-i801.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +4 -1
index 679c6c41f64b..fc6ccb8aba17 100644
@@ -1068,7 +1068,10 @@ static void __init input_apanel_init(void)
 	void __iomem *bios;
 	const void __iomem *p;
 
-	bios = ioremap(0xF0000, 0x10000); /* Can't fail */
+	bios = ioremap(0xF0000, 0x10000);
+	if (!base)
+		return -ENOMEM;
+
 	p = bios_signature(bios);
 	if (p) {
 		/* just use the first address */
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH 3/3] i2c: i801: avoid panic if ioreamp fails

Hi Kefeng,

Quoted 20 lines · Kefeng Wang

If ioremap fails, NULL pointer dereference will happen and leading to a kernel panic when access the virtual address in check_signature().

Fix it by check the return value of ioremap.

---
 drivers/i2c/busses/i2c-i801.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +0 -0
index 679c6c41f64b..fc6ccb8aba17 100644

drivers/i2c/busses/i2c-i801.c static void __init input_apanel_init(void) · line 1072

Quoted 6 lines
drivers/i2c/busses/i2c-i801.c +2 -1
@@ -1068,7 +1068,10 @@ static void __init input_apanel_init(void)
 	void __iomem *bios;
 	const void __iomem *p;
 
-	bios = ioremap(0xF0000, 0x10000); /* Can't fail */
+	bios = ioremap(0xF0000, 0x10000);
+	if (!base)

That would be "if (!bios)". Please don't send patches without at least test-building the result.

We don't need this anyway. The comment says it can't fail, so why bother checking for a condition which will never happen?

Quoted 5 lines
drivers/i2c/busses/i2c-i801.c +2 -0
+		return -ENOMEM;
+
 	p = bios_signature(bios);
 	if (p) {
 		/* just use the first address */
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#4 lore raw

Re: [PATCH 3/3] i2c: i801: avoid panic if ioreamp fails

Quoted 26 lines · Jean Delvare

Hi Kefeng,

Quoted 23 lines · Kefeng Wang

If ioremap fails, NULL pointer dereference will happen and leading to a kernel panic when access the virtual address in check_signature().

Fix it by check the return value of ioremap.

---
 drivers/i2c/busses/i2c-i801.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-i801.c +0 -0
index 679c6c41f64b..fc6ccb8aba17 100644
@@ -1068,7 +1068,10 @@ static void __init input_apanel_init(void)
 	void __iomem *bios;
 	const void __iomem *p;
 
Quoted 5 lines

drivers/i2c/busses/i2c-i801.c static void __init input_apanel_init(void) · line 1072

Quoted 3 lines
drivers/i2c/busses/i2c-i801.c +2 -1
-	bios = ioremap(0xF0000, 0x10000); /* Can't fail */
+	bios = ioremap(0xF0000, 0x10000);
+	if (!base)

That would be "if (!bios)". Please don't send patches without at least test-building the result.

sorry,  copy error.

Quoted 2 lines

We don't need this anyway. The comment says it can't fail, so why bother checking for a condition which will never happen?

The ioremap could fails due to no memory, our inner test robot(enable FAULT_INJECTION)

find this issue.

Quoted 7 lines
Quoted 6 lines
drivers/i2c/busses/i2c-i801.c +2 -0
+		return -ENOMEM;
+
 	p = bios_signature(bios);
 	if (p) {
 		/* just use the first address */
#5 lore raw

Re: [PATCH 3/3] i2c: i801: avoid panic if ioreamp fails

Quoted 7 lines · Kefeng Wang
Quoted 2 lines · Jean Delvare

We don't need this anyway. The comment says it can't fail, so why bother checking for a condition which will never happen?

The ioremap could fails due to no memory, our inner test robot(enable FAULT_INJECTION)

find this issue.

The code only runs on x86 where this specific memory segment is standardized for the purpose. That's how we know it "can't fail".

That being said, maybe it could fail for other reasons (internal kernel bug, or bogus BIOS maybe), and I don't care adding the check anyway, as this code path is not performance critical.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
#6 lore raw

Re: [PATCH 3/3] i2c: i801: avoid panic if ioreamp fails

Quoted 6 lines · Jean Delvare
Quoted 5 lines · Kefeng Wang
Quoted 2 lines · Jean Delvare

We don't need this anyway. The comment says it can't fail, so why bother checking for a condition which will never happen?

The ioremap could fails due to no memory, our inner test robot(enable FAULT_INJECTION)

Quoted 7 lines
Quoted 1 line

find this issue.

The code only runs on x86 where this specific memory segment is standardized for the purpose. That's how we know it "can't fail".

That being said, maybe it could fail for other reasons (internal kernel bug, or bogus BIOS maybe), and I don't care adding the check anyway, as this code path is not performance critical.

Got it , please ignore it.

Quoted 1 line