Re: [PATCH] mm: use mm.arg_lock in get_cmdline()

From: Yang Shi
Date: Thu Apr 18 2019 - 12:48:28 EST




On 4/18/19 6:05 AM, Laurent Dufour wrote:
Le 18/04/2019 Ã 15:03, Michal Hocko a ÃcritÂ:
Michal has posted the same patch few days ago http://lkml.kernel.org/r/20190417120347.15397-1-mkoutny@xxxxxxxx

Oups, sorry for the noise, I missed it.

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


On Thu 18-04-19 14:58:27, Laurent Dufour wrote:
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 <yang.shi@xxxxxxxxxxxxxxxxx>
Signed-off-by: Laurent Dufour <ldufour@xxxxxxxxxxxxx>
---
 mm/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/util.c b/mm/util.c
index 05a464929b3e..789760c3028b 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -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