Skip to contentSkip to conversation

mm: add NULL check to avoid potential NULL pointer dereference

PATCH Applied Gustavo A. R. Silva 2 participants 2 messages May 30, 2017 – May 31, 2017

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

PATCH 1/1 mm: add NULL check to avoid potential NULL pointer dereference

NULL check at line 1226: if (!pgdat), implies that pointer pgdat might be NULL.
Function rollback_node_hotadd() dereference this pointer. Add NULL check to avoid a potential NULL pointer dereference.

Addresses-Coverity-ID: 1369133

---
 mm/memory_hotplug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory_hotplug.c +1 -1
index 599c675..ea3bc3e 100644
@@ -1273,7 +1273,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online)
 
 error:
 	/* rollback pgdat allocation and others */
-	if (new_pgdat)
+	if (new_pgdat && pgdat)
 		rollback_node_hotadd(nid, pgdat);
 	memblock_remove(start, size);
 
Signature · 7 lines
2.5.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>
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Gustavo A. R. Silva

NULL check at line 1226: if (!pgdat), implies that pointer pgdat might be NULL.
Function rollback_node_hotadd() dereference this pointer. Add NULL check to avoid a potential NULL pointer dereference.

The changelog is quite cryptic to be honest. Well the code is as well but what do you say about the following replacement.

"
If a new pgdat has to be allocated in add_memory_resource and the initialization fails for some reason we have to rollback_node_hotadd. This, however, assumes that pgdat allocation itself is successful which cannot be assumed. Add a check for pgdat to cover that case and skip rollback_node_hotadd altogether because there is nothing to roll back.

This has been pointed out by coverity.
"

Quoted 3 lines

Addresses-Coverity-ID: 1369133

Quoted 25 lines
---
 mm/memory_hotplug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory_hotplug.c +1 -1
index 599c675..ea3bc3e 100644
@@ -1273,7 +1273,7 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online)
 
 error:
 	/* rollback pgdat allocation and others */
-	if (new_pgdat)
+	if (new_pgdat && pgdat)
 		rollback_node_hotadd(nid, pgdat);
 	memblock_remove(start, size);
 
Signature · 7 lines
2.5.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>
Signature · 8 lines
Michal Hocko
SUSE Labs

--
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>