Skip to contentSkip to conversation

ARM: mm: only adjust sections of valid mm structures

PATCH In review Doug Berger 4 participants 4 messages Jun 27, 2019 – Jul 9, 2019 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: mm: only adjust sections of valid mm structures

A timing hazard exists when an early fork/exec thread begins exiting and sets its mm pointer to NULL while a separate core tries to update the section information.

This commit ensures that the mm pointer is not NULL before setting its section parameters. The arguments provided by commit 11ce4b33aedc ("ARM: 8672/1: mm: remove tasklist locking from update_sections_early()") are equally valid for not requiring grabbing the task_lock around this check.

Fixes 08925c2f124f ("ARM: 8464/1: Update all mm structures with section adjustments")
---
 arch/arm/mm/init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mm/init.c +2 -1
index be0b42937888..bdc70dff477b 100644
@@ -616,7 +616,8 @@ static void update_sections_early(struct section_perm perms[], int n)
 		if (t->flags & PF_KTHREAD)
 			continue;
 		for_each_thread(t, s)
-			set_section_perms(perms, n, true, s->mm);
+			if (s->mm)
+				set_section_perms(perms, n, true, s->mm);
 	}
 	set_section_perms(perms, n, true, current->active_mm);
 	set_section_perms(perms, n, true, &init_mm);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 9 lines · Doug Berger

A timing hazard exists when an early fork/exec thread begins exiting and sets its mm pointer to NULL while a separate core tries to update the section information.

This commit ensures that the mm pointer is not NULL before setting its section parameters. The arguments provided by commit 11ce4b33aedc ("ARM: 8672/1: mm: remove tasklist locking from update_sections_early()") are equally valid for not requiring grabbing the task_lock around this check.

This looks like an appropriate fix to me. For what it is worth, we were able to reproduce this problem with a 4.9 kernel with:

CONFIG_UEVENT_HELPER=y
CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"

It is made much more reliable with a lower default loglevel (e.g.: 1) than the default log level, but if you have e.g.: an USB thumb drive that needs to be scanned by the SCSI layer, then this is 100% reliable.

Quoted 22 lines
Fixes 08925c2f124f ("ARM: 8464/1: Update all mm structures with section adjustments")
---
 arch/arm/mm/init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mm/init.c +2 -1
index be0b42937888..bdc70dff477b 100644
@@ -616,7 +616,8 @@ static void update_sections_early(struct section_perm perms[], int n)
 		if (t->flags & PF_KTHREAD)
 			continue;
 		for_each_thread(t, s)
-			set_section_perms(perms, n, true, s->mm);
+			if (s->mm)
+				set_section_perms(perms, n, true, s->mm);
 	}
 	set_section_perms(perms, n, true, current->active_mm);
 	set_section_perms(perms, n, true, &init_mm);
Signature · 1 line
Florian
Acked-by on v1 1/1
#2 lore raw
In reply to Doug Berger
Quoted 22 lines · Doug Berger

A timing hazard exists when an early fork/exec thread begins exiting and sets its mm pointer to NULL while a separate core tries to update the section information.

This commit ensures that the mm pointer is not NULL before setting its section parameters. The arguments provided by commit 11ce4b33aedc ("ARM: 8672/1: mm: remove tasklist locking from update_sections_early()") are equally valid for not requiring grabbing the task_lock around this check.

Fixes 08925c2f124f ("ARM: 8464/1: Update all mm structures with section adjustments")
---
  arch/arm/mm/init.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mm/init.c +0 -0
index be0b42937888..bdc70dff477b 100644

arch/arm/mm/init.c static void update_sections_early(struct section_perm perms[], int n) · line 623

Quoted 9 lines
arch/arm/mm/init.c +2 -1
@@ -616,7 +616,8 @@ static void update_sections_early(struct section_perm perms[], int n)
  		if (t->flags & PF_KTHREAD)
  			continue;
  		for_each_thread(t, s)
-			set_section_perms(perms, n, true, s->mm);
+			if (s->mm)
+				set_section_perms(perms, n, true, s->mm);
  	}
  	set_section_perms(perms, n, true, current->active_mm);
  	set_section_perms(perms, n, true, &init_mm);
#3 lore raw
In reply to Doug Berger
Quoted 4 lines · Doug Berger

A timing hazard exists when an early fork/exec thread begins exiting and sets its mm pointer to NULL while a separate core tries to update the section information.

Quoted 8 lines

This commit ensures that the mm pointer is not NULL before setting its section parameters. The arguments provided by commit 11ce4b33aedc ("ARM: 8672/1: mm: remove tasklist locking from update_sections_early()") are equally valid for not requiring grabbing the task_lock around this check.

Fixes 08925c2f124f ("ARM: 8464/1: Update all mm structures with section adjustments")

I'm not smart enough to say whether it is the right solution, but I also want to test this on some boards I have. I suspect this may be part of the problem I have with mounting root on a USB stick on some early mpcore machines, so I might come back with a Tested-by.

Yours,
Linus Walleij