Skip to contentSkip to conversation

mm: fix protection of mm_struct fields in get_cmdline()

PATCH In review Konstantin Khlebnikov 3 participants 4 messages May 15, 2019

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

PATCH 1/1 mm: fix protection of mm_struct fields in get_cmdline()

Since commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start| end and env_start|end in mm_struct") related mm fields are protected with separate spinlock and mmap_sem held for read is not enough for protection.

Fixes 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct")
---
 mm/util.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/util.c +2 -2
index e2e4f8c3fa12..540e7c157cf2 100644
@@ -717,12 +717,12 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
 	if (!mm->arg_end)
 		goto out_mm;	/* Shh! No looking before we're done */
 
-	down_read(&mm->mmap_sem);
+	spin_lock(&mm->arg_lock);
 	arg_start = mm->arg_start;
 	arg_end = mm->arg_end;
 	env_start = mm->env_start;
 	env_end = mm->env_end;
-	up_read(&mm->mmap_sem);
+	spin_unlock(&mm->arg_lock);
 
 	len = arg_end - arg_start;
 
#1 lore raw
Quoted 6 lines · Konstantin Khlebnikov

Since commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start| end and env_start|end in mm_struct") related mm fields are protected with separate spinlock and mmap_sem held for read is not enough for protection.

Fixes 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct")

This was already addressed by [1]?

[1] https://patchwork.kernel.org/patch/10923003/

Quoted 24 lines
---
 mm/util.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/util.c +2 -2
index e2e4f8c3fa12..540e7c157cf2 100644
@@ -717,12 +717,12 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
 	if (!mm->arg_end)
 		goto out_mm;	/* Shh! No looking before we're done */
 
-	down_read(&mm->mmap_sem);
+	spin_lock(&mm->arg_lock);
 	arg_start = mm->arg_start;
 	arg_end = mm->arg_end;
 	env_start = mm->env_start;
 	env_end = mm->env_end;
-	up_read(&mm->mmap_sem);
+	spin_unlock(&mm->arg_lock);
 
 	len = arg_end - arg_start;
 
Signature · 2 lines
Oscar Salvador
SUSE L3
#2 lore raw
Quoted 9 lines · Oscar Salvador
Quoted 6 lines · Konstantin Khlebnikov

Since commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start| end and env_start|end in mm_struct") related mm fields are protected with separate spinlock and mmap_sem held for read is not enough for protection.

Fixes 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct")

This was already addressed by [1]?

Yep.

Quoted 28 lines

[1] https://patchwork.kernel.org/patch/10923003/

Quoted 24 lines
---
  mm/util.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
mm/util.c +2 -2
index e2e4f8c3fa12..540e7c157cf2 100644
@@ -717,12 +717,12 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
  	if (!mm->arg_end)
  		goto out_mm;	/* Shh! No looking before we're done */
 
-	down_read(&mm->mmap_sem);
+	spin_lock(&mm->arg_lock);
  	arg_start = mm->arg_start;
  	arg_end = mm->arg_end;
  	env_start = mm->env_start;
  	env_end = mm->env_end;
-	up_read(&mm->mmap_sem);
+	spin_unlock(&mm->arg_lock);
 
  	len = arg_end - arg_start;
 
#3 lore raw
In reply to Konstantin Khlebnikov

Hi, Konstantin,

Quoted 6 lines · Konstantin Khlebnikov

Since commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start| end and env_start|end in mm_struct") related mm fields are protected with separate spinlock and mmap_sem held for read is not enough for protection.

Fixes 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct")

is this already fixed in Michal's series: https://lkml.org/lkml/2019/5/2/422 ?

Thanks,
Kirill

Quoted 24 lines
---
 mm/util.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/util.c +2 -2
index e2e4f8c3fa12..540e7c157cf2 100644
@@ -717,12 +717,12 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
 	if (!mm->arg_end)
 		goto out_mm;	/* Shh! No looking before we're done */
 
-	down_read(&mm->mmap_sem);
+	spin_lock(&mm->arg_lock);
 	arg_start = mm->arg_start;
 	arg_end = mm->arg_end;
 	env_start = mm->env_start;
 	env_end = mm->env_end;
-	up_read(&mm->mmap_sem);
+	spin_unlock(&mm->arg_lock);
 
 	len = arg_end - arg_start;