Skip to contentSkip to conversation

mm: numa: fix NULL pointer dereference

PATCH In review Mauro Dreissig 2 participants 3 messages Aug 7, 2013

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

PATCH 1/1 mm: numa: fix NULL pointer dereference

From: Mauro Dreissig <[email protected]>

The "pol->mode" field is accessed even when no mempolicy is assigned to the "pol" variable.

---
 mm/mempolicy.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
mm/mempolicy.c +8 -4
index 6b1d426..105fff0 100644
@@ -127,12 +127,16 @@ static struct mempolicy *get_task_policy(struct task_struct *p)
 
 	if (!pol) {
 		node = numa_node_id();
-		if (node != NUMA_NO_NODE)
+		if (node != NUMA_NO_NODE) {
 			pol = &preferred_node_policy[node];
 
-		/* preferred_node_policy is not initialised early in boot */
-		if (!pol->mode)
-			pol = NULL;
+			/*
+			 * preferred_node_policy is not initialised early
+			 * in boot
+			 */
+			if (!pol->mode)
+				pol = NULL;
+		}
 	}
 
 	return pol;
Signature · 7 lines
1.8.1.2

--
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>
#1 lore raw

Is it possible to check pol if it is equal to NULL prior to access to mode field?

Quoted 44 lines · Mauro Dreissig

From: Mauro Dreissig <[email protected]>

The "pol->mode" field is accessed even when no mempolicy is assigned to the "pol" variable.

---
mm/mempolicy.c | 12 ++++++++----

1 file changed, 8 insertions(+), 4 deletions(-)
mm/mempolicy.c +8 -4
index 6b1d426..105fff0 100644
@@ -127,12 +127,16 @@ static struct mempolicy *get_task_policy(struct
 task_struct *p)
 
 	if (!pol) {
 		node = numa_node_id();
-		if (node != NUMA_NO_NODE)
+		if (node != NUMA_NO_NODE) {
 			pol = &preferred_node_policy[node];
 
-		/* preferred_node_policy is not initialised early in boot */
-		if (!pol->mode)
-			pol = NULL;
+			/*
+			 * preferred_node_policy is not initialised early
+			 * in boot
+			 */
+			if (!pol->mode)
+				pol = NULL;
+		}
 	}
 
	return pol;
Signature · 7 lines
1.8.1.2

--
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 · 1 line
Sent from my Android device with Gmail Plus. Please excuse my brevity.
#2 lore raw
In reply to Mauro Dreissig

2013/8/6 Mauro Dreissig <[email protected]>

Quoted 36 lines

From: Mauro Dreissig <[email protected]>

The "pol->mode" field is accessed even when no mempolicy is assigned to the "pol" variable.

---
 mm/mempolicy.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
mm/mempolicy.c +8 -4
index 6b1d426..105fff0 100644
@@ -127,12 +127,16 @@ static struct mempolicy *get_task_policy(struct
 task_struct *p)
 
        if (!pol) {
                node = numa_node_id();
-               if (node != NUMA_NO_NODE)
+               if (node != NUMA_NO_NODE) {
                        pol = &preferred_node_policy[node];
 
-               /* preferred_node_policy is not initialised early in boot
 */
-               if (!pol->mode)
-                       pol = NULL;
+                       /*
+                        * preferred_node_policy is not initialised early
+                        * in boot
+                        */
+                       if (!pol->mode)
+                               pol = NULL;
+               }
        }
Quoted 5 lines
        return pol;

--
1.8.1.2

A patch about this issue already exist, please ignore my message.

http://marc.info/?l=linux-mm&m=137576205227365&w=2