Skip to contentSkip to conversation

exec: move ->recursion_depth out of critical sections

PATCH New Alexey Dobriyan 1 participant 1 message Apr 17, 2019

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

PATCH 1/1 exec: move ->recursion_depth out of critical sections

->recursion_depth is changed only by current, therefore decrementing can be done without taking any locks.

---

 fs/exec.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/exec.c +3 -1
@@ -1652,11 +1652,13 @@ int search_binary_handler(struct linux_binprm *bprm)
 		if (!try_module_get(fmt->module))
 			continue;
 		read_unlock(&binfmt_lock);
+
 		bprm->recursion_depth++;
 		retval = fmt->load_binary(bprm);
+		bprm->recursion_depth--;
+
 		read_lock(&binfmt_lock);
 		put_binfmt(fmt);
-		bprm->recursion_depth--;
 		if (retval < 0 && !bprm->mm) {
 			/* we got to flush_old_exec() and failed after it */
 			read_unlock(&binfmt_lock);