Skip to contentSkip to conversation

mm: use mm.arg_lock in get_cmdline()

PATCH In review Laurent Dufour 3 participants 4 messages Apr 18, 2019

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

PATCH 1/1 mm: use mm.arg_lock in get_cmdline()

The commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct") introduce the spinlock arg_lock to protect the arg_* and env_* field of the mm_struct structure.

While reading the code, I found that this new spinlock was not used in get_cmdline() to protect access to these fields.

Fixing this even if there is no issue reported yet for this.

Fixes 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct")
Cc Yang Shi <[email protected]>
---
 mm/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/util.c +2 -2
index 05a464929b3e..789760c3028b 100644
@@ -758,12 +758,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 · 1 line
2.21.0
#1 lore raw

Michal has posted the same patch few days ago http://lkml.kernel.org/r/[email protected]

Quoted 37 lines · Laurent Dufour

The commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct") introduce the spinlock arg_lock to protect the arg_* and env_* field of the mm_struct structure.

While reading the code, I found that this new spinlock was not used in get_cmdline() to protect access to these fields.

Fixing this even if there is no issue reported yet for this.

Fixes 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct")
Cc Yang Shi <[email protected]>
---
 mm/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/util.c +2 -2
index 05a464929b3e..789760c3028b 100644
@@ -758,12 +758,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 · 1 line
2.21.0
Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw

Le 18/04/2019 à 15:03, Michal Hocko a écrit :

Quoted 1 line

Michal has posted the same patch few days ago http://lkml.kernel.org/r/[email protected]

Oups, sorry for the noise, I missed it.

Quoted 39 lines · Laurent Dufour
Quoted 37 lines

The commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct") introduce the spinlock arg_lock to protect the arg_* and env_* field of the mm_struct structure.

While reading the code, I found that this new spinlock was not used in get_cmdline() to protect access to these fields.

Fixing this even if there is no issue reported yet for this.

Fixes 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct")
Cc Yang Shi <[email protected]>
---
  mm/util.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
mm/util.c +2 -2
index 05a464929b3e..789760c3028b 100644
@@ -758,12 +758,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 · 1 line
2.21.0
#3 lore raw
Quoted 4 lines · Laurent Dufour

Le 18/04/2019 à 15:03, Michal Hocko a écrit :

Quoted 1 line

Michal has posted the same patch few days ago http://lkml.kernel.org/r/[email protected]

Oups, sorry for the noise, I missed it.

Yes, Michal already posted a similar patch. Anyway, thanks for catching this.

Quoted 38 lines
Quoted 38 lines · Laurent Dufour
Quoted 35 lines

The commit 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct") introduce the spinlock arg_lock to protect the arg_* and env_* field of the mm_struct structure.

While reading the code, I found that this new spinlock was not used in get_cmdline() to protect access to these fields.

Fixing this even if there is no issue reported yet for this.

Fixes 88aa7cc688d4 ("mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct")
Cc Yang Shi <[email protected]>

---
  mm/util.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
mm/util.c +0 -0
index 05a464929b3e..789760c3028b 100644
@@ -758,12 +758,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;
  --
2.21.0