lkml.org 
[lkml]   [2024]   [Feb]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2] ARM: mvebu: Add error handling in i2c_quirk to prevent bugs
Date
The kzalloc() and the two kstrdup in i2c_quirk() will return null
if the physical memory has run out. As a result, if we dereference
these null values, the null pointer dereference bugs will happen.

This patch adds error handling to avoid null pointer dereference.

Fixes: 5fd62066d290 ("ARM: mvebu: Add thermal quirk for the Armada 375 DB board")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
Changes in v2:
- Adds checks to judge whether two kstrdup() fail.

arch/arm/mach-mvebu/board-v7.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c
index fd5d0c8ff69..c31ac08d24a 100644
--- a/arch/arm/mach-mvebu/board-v7.c
+++ b/arch/arm/mach-mvebu/board-v7.c
@@ -125,12 +125,20 @@ static void __init i2c_quirk(void)
struct property *new_compat;

new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL);
+ if (!new_compat)
+ continue;

new_compat->name = kstrdup("compatible", GFP_KERNEL);
new_compat->length = sizeof("marvell,mv78230-a0-i2c");
new_compat->value = kstrdup("marvell,mv78230-a0-i2c",
GFP_KERNEL);

+ if (!new_compat->name || !new_compat->value) {
+ kfree(new_compat->name);
+ kfree(new_compat->value);
+ kfree(new_compat);
+ continue;
+ }
of_update_property(np, new_compat);
}
}
--
2.17.1

\
 
 \ /
  Last update: 2024-05-27 15:20    [W:0.026 / U:1.328 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site