@@ -1298,7 +1298,7 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec)
1298
1298
* signal (via de_thread() or coredump), or will have SEGV raised
1299
1299
* (after exec_mmap()) by search_binary_handlers (see below).
1300
1300
*/
1301
- int flush_old_exec (struct linux_binprm * bprm )
1301
+ int begin_new_exec (struct linux_binprm * bprm )
1302
1302
{
1303
1303
struct task_struct * me = current ;
1304
1304
int retval ;
@@ -1326,12 +1326,12 @@ int flush_old_exec(struct linux_binprm * bprm)
1326
1326
goto out ;
1327
1327
1328
1328
/*
1329
- * After setting bprm->called_exec_mmap (to mark that current is
1330
- * using the prepared mm now), we have nothing left of the original
1331
- * process. If anything from here on returns an error, the check
1332
- * in search_binary_handler() will SEGV current.
1329
+ * With the new mm installed it is completely impossible to
1330
+ * fail and return to the original process. If anything from
1331
+ * here on returns an error, the check in
1332
+ * search_binary_handler() will SEGV current.
1333
1333
*/
1334
- bprm -> called_exec_mmap = 1 ;
1334
+ bprm -> point_of_no_return = true ;
1335
1335
bprm -> mm = NULL ;
1336
1336
1337
1337
#ifdef CONFIG_POSIX_TIMERS
@@ -1344,7 +1344,7 @@ int flush_old_exec(struct linux_binprm * bprm)
1344
1344
*/
1345
1345
retval = unshare_sighand (me );
1346
1346
if (retval )
1347
- goto out ;
1347
+ goto out_unlock ;
1348
1348
1349
1349
set_fs (USER_DS );
1350
1350
me -> flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD |
@@ -1359,36 +1359,7 @@ int flush_old_exec(struct linux_binprm * bprm)
1359
1359
* undergoing exec(2).
1360
1360
*/
1361
1361
do_close_on_exec (me -> files );
1362
- return 0 ;
1363
-
1364
- out :
1365
- return retval ;
1366
- }
1367
- EXPORT_SYMBOL (flush_old_exec );
1368
1362
1369
- void would_dump (struct linux_binprm * bprm , struct file * file )
1370
- {
1371
- struct inode * inode = file_inode (file );
1372
- if (inode_permission (inode , MAY_READ ) < 0 ) {
1373
- struct user_namespace * old , * user_ns ;
1374
- bprm -> interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP ;
1375
-
1376
- /* Ensure mm->user_ns contains the executable */
1377
- user_ns = old = bprm -> mm -> user_ns ;
1378
- while ((user_ns != & init_user_ns ) &&
1379
- !privileged_wrt_inode_uidgid (user_ns , inode ))
1380
- user_ns = user_ns -> parent ;
1381
-
1382
- if (old != user_ns ) {
1383
- bprm -> mm -> user_ns = get_user_ns (user_ns );
1384
- put_user_ns (old );
1385
- }
1386
- }
1387
- }
1388
- EXPORT_SYMBOL (would_dump );
1389
-
1390
- void setup_new_exec (struct linux_binprm * bprm )
1391
- {
1392
1363
/*
1393
1364
* Once here, prepare_binrpm() will not be called any more, so
1394
1365
* the final state of setuid/setgid/fscaps can be merged into the
@@ -1398,7 +1369,7 @@ void setup_new_exec(struct linux_binprm * bprm)
1398
1369
1399
1370
if (bprm -> secureexec ) {
1400
1371
/* Make sure parent cannot signal privileged process. */
1401
- current -> pdeath_signal = 0 ;
1372
+ me -> pdeath_signal = 0 ;
1402
1373
1403
1374
/*
1404
1375
* For secureexec, reset the stack limit to sane default to
@@ -1411,9 +1382,7 @@ void setup_new_exec(struct linux_binprm * bprm)
1411
1382
bprm -> rlim_stack .rlim_cur = _STK_LIM ;
1412
1383
}
1413
1384
1414
- arch_pick_mmap_layout (current -> mm , & bprm -> rlim_stack );
1415
-
1416
- current -> sas_ss_sp = current -> sas_ss_size = 0 ;
1385
+ me -> sas_ss_sp = me -> sas_ss_size = 0 ;
1417
1386
1418
1387
/*
1419
1388
* Figure out dumpability. Note that this checking only of current
@@ -1427,20 +1396,82 @@ void setup_new_exec(struct linux_binprm * bprm)
1427
1396
else
1428
1397
set_dumpable (current -> mm , SUID_DUMP_USER );
1429
1398
1430
- arch_setup_new_exec ();
1431
1399
perf_event_exec ();
1432
- __set_task_comm (current , kbasename (bprm -> filename ), true);
1400
+ __set_task_comm (me , kbasename (bprm -> filename ), true);
1401
+
1402
+ /* An exec changes our domain. We are no longer part of the thread
1403
+ group */
1404
+ WRITE_ONCE (me -> self_exec_id , me -> self_exec_id + 1 );
1405
+ flush_signal_handlers (me , 0 );
1406
+
1407
+ /*
1408
+ * install the new credentials for this executable
1409
+ */
1410
+ security_bprm_committing_creds (bprm );
1411
+
1412
+ commit_creds (bprm -> cred );
1413
+ bprm -> cred = NULL ;
1414
+
1415
+ /*
1416
+ * Disable monitoring for regular users
1417
+ * when executing setuid binaries. Must
1418
+ * wait until new credentials are committed
1419
+ * by commit_creds() above
1420
+ */
1421
+ if (get_dumpable (me -> mm ) != SUID_DUMP_USER )
1422
+ perf_event_exit_task (me );
1423
+ /*
1424
+ * cred_guard_mutex must be held at least to this point to prevent
1425
+ * ptrace_attach() from altering our determination of the task's
1426
+ * credentials; any time after this it may be unlocked.
1427
+ */
1428
+ security_bprm_committed_creds (bprm );
1429
+ return 0 ;
1430
+
1431
+ out_unlock :
1432
+ mutex_unlock (& me -> signal -> exec_update_mutex );
1433
+ out :
1434
+ return retval ;
1435
+ }
1436
+ EXPORT_SYMBOL (begin_new_exec );
1437
+
1438
+ void would_dump (struct linux_binprm * bprm , struct file * file )
1439
+ {
1440
+ struct inode * inode = file_inode (file );
1441
+ if (inode_permission (inode , MAY_READ ) < 0 ) {
1442
+ struct user_namespace * old , * user_ns ;
1443
+ bprm -> interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP ;
1444
+
1445
+ /* Ensure mm->user_ns contains the executable */
1446
+ user_ns = old = bprm -> mm -> user_ns ;
1447
+ while ((user_ns != & init_user_ns ) &&
1448
+ !privileged_wrt_inode_uidgid (user_ns , inode ))
1449
+ user_ns = user_ns -> parent ;
1450
+
1451
+ if (old != user_ns ) {
1452
+ bprm -> mm -> user_ns = get_user_ns (user_ns );
1453
+ put_user_ns (old );
1454
+ }
1455
+ }
1456
+ }
1457
+ EXPORT_SYMBOL (would_dump );
1458
+
1459
+ void setup_new_exec (struct linux_binprm * bprm )
1460
+ {
1461
+ /* Setup things that can depend upon the personality */
1462
+ struct task_struct * me = current ;
1463
+
1464
+ arch_pick_mmap_layout (me -> mm , & bprm -> rlim_stack );
1465
+
1466
+ arch_setup_new_exec ();
1433
1467
1434
1468
/* Set the new mm task size. We have to do that late because it may
1435
1469
* depend on TIF_32BIT which is only updated in flush_thread() on
1436
1470
* some architectures like powerpc
1437
1471
*/
1438
- current -> mm -> task_size = TASK_SIZE ;
1439
-
1440
- /* An exec changes our domain. We are no longer part of the thread
1441
- group */
1442
- WRITE_ONCE (current -> self_exec_id , current -> self_exec_id + 1 );
1443
- flush_signal_handlers (current , 0 );
1472
+ me -> mm -> task_size = TASK_SIZE ;
1473
+ mutex_unlock (& me -> signal -> exec_update_mutex );
1474
+ mutex_unlock (& me -> signal -> cred_guard_mutex );
1444
1475
}
1445
1476
EXPORT_SYMBOL (setup_new_exec );
1446
1477
@@ -1456,7 +1487,7 @@ EXPORT_SYMBOL(finalize_exec);
1456
1487
1457
1488
/*
1458
1489
* Prepare credentials and lock ->cred_guard_mutex.
1459
- * install_exec_creds () commits the new creds and drops the lock.
1490
+ * setup_new_exec () commits the new creds and drops the lock.
1460
1491
* Or, if exec fails before, free_bprm() should release ->cred and
1461
1492
* and unlock.
1462
1493
*/
@@ -1477,8 +1508,6 @@ static void free_bprm(struct linux_binprm *bprm)
1477
1508
{
1478
1509
free_arg_pages (bprm );
1479
1510
if (bprm -> cred ) {
1480
- if (bprm -> called_exec_mmap )
1481
- mutex_unlock (& current -> signal -> exec_update_mutex );
1482
1511
mutex_unlock (& current -> signal -> cred_guard_mutex );
1483
1512
abort_creds (bprm -> cred );
1484
1513
}
@@ -1504,35 +1533,6 @@ int bprm_change_interp(const char *interp, struct linux_binprm *bprm)
1504
1533
}
1505
1534
EXPORT_SYMBOL (bprm_change_interp );
1506
1535
1507
- /*
1508
- * install the new credentials for this executable
1509
- */
1510
- void install_exec_creds (struct linux_binprm * bprm )
1511
- {
1512
- security_bprm_committing_creds (bprm );
1513
-
1514
- commit_creds (bprm -> cred );
1515
- bprm -> cred = NULL ;
1516
-
1517
- /*
1518
- * Disable monitoring for regular users
1519
- * when executing setuid binaries. Must
1520
- * wait until new credentials are committed
1521
- * by commit_creds() above
1522
- */
1523
- if (get_dumpable (current -> mm ) != SUID_DUMP_USER )
1524
- perf_event_exit_task (current );
1525
- /*
1526
- * cred_guard_mutex must be held at least to this point to prevent
1527
- * ptrace_attach() from altering our determination of the task's
1528
- * credentials; any time after this it may be unlocked.
1529
- */
1530
- security_bprm_committed_creds (bprm );
1531
- mutex_unlock (& current -> signal -> exec_update_mutex );
1532
- mutex_unlock (& current -> signal -> cred_guard_mutex );
1533
- }
1534
- EXPORT_SYMBOL (install_exec_creds );
1535
-
1536
1536
/*
1537
1537
* determine how safe it is to execute the proposed program
1538
1538
* - the caller must hold ->cred_guard_mutex to protect against
@@ -1720,7 +1720,7 @@ int search_binary_handler(struct linux_binprm *bprm)
1720
1720
1721
1721
read_lock (& binfmt_lock );
1722
1722
put_binfmt (fmt );
1723
- if (retval < 0 && bprm -> called_exec_mmap ) {
1723
+ if (retval < 0 && bprm -> point_of_no_return ) {
1724
1724
/* we got to flush_old_exec() and failed after it */
1725
1725
read_unlock (& binfmt_lock );
1726
1726
force_sigsegv (SIGSEGV );
0 commit comments