Skip to content

Commit 7d503fe

Browse files
committed
exec: In setup_new_exec cache current in the local variable me
At least gcc 8.3 when generating code for x86_64 has a hard time consolidating multiple calls to current aka get_current(), and winds up unnecessarily rereading %gs:current_task several times in setup_new_exec. Caching the value of current in the local variable of me generates slightly better and shorter assembly. Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Greg Ungerer <[email protected]> Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 96ecee2 commit 7d503fe

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

fs/exec.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ EXPORT_SYMBOL(would_dump);
13911391

13921392
void setup_new_exec(struct linux_binprm * bprm)
13931393
{
1394+
struct task_struct *me = current;
13941395
/*
13951396
* Once here, prepare_binrpm() will not be called any more, so
13961397
* the final state of setuid/setgid/fscaps can be merged into the
@@ -1400,7 +1401,7 @@ void setup_new_exec(struct linux_binprm * bprm)
14001401

14011402
if (bprm->secureexec) {
14021403
/* Make sure parent cannot signal privileged process. */
1403-
current->pdeath_signal = 0;
1404+
me->pdeath_signal = 0;
14041405

14051406
/*
14061407
* For secureexec, reset the stack limit to sane default to
@@ -1413,9 +1414,9 @@ void setup_new_exec(struct linux_binprm * bprm)
14131414
bprm->rlim_stack.rlim_cur = _STK_LIM;
14141415
}
14151416

1416-
arch_pick_mmap_layout(current->mm, &bprm->rlim_stack);
1417+
arch_pick_mmap_layout(me->mm, &bprm->rlim_stack);
14171418

1418-
current->sas_ss_sp = current->sas_ss_size = 0;
1419+
me->sas_ss_sp = me->sas_ss_size = 0;
14191420

14201421
/*
14211422
* Figure out dumpability. Note that this checking only of current
@@ -1431,18 +1432,18 @@ void setup_new_exec(struct linux_binprm * bprm)
14311432

14321433
arch_setup_new_exec();
14331434
perf_event_exec();
1434-
__set_task_comm(current, kbasename(bprm->filename), true);
1435+
__set_task_comm(me, kbasename(bprm->filename), true);
14351436

14361437
/* Set the new mm task size. We have to do that late because it may
14371438
* depend on TIF_32BIT which is only updated in flush_thread() on
14381439
* some architectures like powerpc
14391440
*/
1440-
current->mm->task_size = TASK_SIZE;
1441+
me->mm->task_size = TASK_SIZE;
14411442

14421443
/* An exec changes our domain. We are no longer part of the thread
14431444
group */
1444-
WRITE_ONCE(current->self_exec_id, current->self_exec_id + 1);
1445-
flush_signal_handlers(current, 0);
1445+
WRITE_ONCE(me->self_exec_id, me->self_exec_id + 1);
1446+
flush_signal_handlers(me, 0);
14461447

14471448
/*
14481449
* install the new credentials for this executable
@@ -1458,16 +1459,16 @@ void setup_new_exec(struct linux_binprm * bprm)
14581459
* wait until new credentials are committed
14591460
* by commit_creds() above
14601461
*/
1461-
if (get_dumpable(current->mm) != SUID_DUMP_USER)
1462-
perf_event_exit_task(current);
1462+
if (get_dumpable(me->mm) != SUID_DUMP_USER)
1463+
perf_event_exit_task(me);
14631464
/*
14641465
* cred_guard_mutex must be held at least to this point to prevent
14651466
* ptrace_attach() from altering our determination of the task's
14661467
* credentials; any time after this it may be unlocked.
14671468
*/
14681469
security_bprm_committed_creds(bprm);
1469-
mutex_unlock(&current->signal->exec_update_mutex);
1470-
mutex_unlock(&current->signal->cred_guard_mutex);
1470+
mutex_unlock(&me->signal->exec_update_mutex);
1471+
mutex_unlock(&me->signal->cred_guard_mutex);
14711472
}
14721473
EXPORT_SYMBOL(setup_new_exec);
14731474

0 commit comments

Comments
 (0)