@@ -830,44 +830,6 @@ void audit_filter_inodes(struct task_struct *tsk, struct audit_context *ctx)
830830 rcu_read_unlock ();
831831}
832832
833- /* Transfer the audit context pointer to the caller, clearing it in the tsk's struct */
834- static inline struct audit_context * audit_take_context (struct task_struct * tsk ,
835- int return_valid ,
836- long return_code )
837- {
838- struct audit_context * context = tsk -> audit_context ;
839-
840- if (!context )
841- return NULL ;
842- context -> return_valid = return_valid ;
843-
844- /*
845- * we need to fix up the return code in the audit logs if the actual
846- * return codes are later going to be fixed up by the arch specific
847- * signal handlers
848- *
849- * This is actually a test for:
850- * (rc == ERESTARTSYS ) || (rc == ERESTARTNOINTR) ||
851- * (rc == ERESTARTNOHAND) || (rc == ERESTART_RESTARTBLOCK)
852- *
853- * but is faster than a bunch of ||
854- */
855- if (unlikely (return_code <= - ERESTARTSYS ) &&
856- (return_code >= - ERESTART_RESTARTBLOCK ) &&
857- (return_code != - ENOIOCTLCMD ))
858- context -> return_code = - EINTR ;
859- else
860- context -> return_code = return_code ;
861-
862- if (context -> in_syscall && !context -> dummy ) {
863- audit_filter_syscall (tsk , context , & audit_filter_list [AUDIT_FILTER_EXIT ]);
864- audit_filter_inodes (tsk , context );
865- }
866-
867- audit_set_context (tsk , NULL );
868- return context ;
869- }
870-
871833static inline void audit_proctitle_free (struct audit_context * context )
872834{
873835 kfree (context -> proctitle .value );
@@ -1296,15 +1258,18 @@ static inline int audit_proctitle_rtrim(char *proctitle, int len)
12961258 return len ;
12971259}
12981260
1299- static void audit_log_proctitle (struct task_struct * tsk ,
1300- struct audit_context * context )
1261+ static void audit_log_proctitle (void )
13011262{
13021263 int res ;
13031264 char * buf ;
13041265 char * msg = "(null)" ;
13051266 int len = strlen (msg );
1267+ struct audit_context * context = audit_context ();
13061268 struct audit_buffer * ab ;
13071269
1270+ if (!context || context -> dummy )
1271+ return ;
1272+
13081273 ab = audit_log_start (context , GFP_KERNEL , AUDIT_PROCTITLE );
13091274 if (!ab )
13101275 return ; /* audit_panic or being filtered */
@@ -1317,7 +1282,7 @@ static void audit_log_proctitle(struct task_struct *tsk,
13171282 if (!buf )
13181283 goto out ;
13191284 /* Historically called this from procfs naming */
1320- res = get_cmdline (tsk , buf , MAX_PROCTITLE_AUDIT_LEN );
1285+ res = get_cmdline (current , buf , MAX_PROCTITLE_AUDIT_LEN );
13211286 if (res == 0 ) {
13221287 kfree (buf );
13231288 goto out ;
@@ -1337,15 +1302,15 @@ static void audit_log_proctitle(struct task_struct *tsk,
13371302 audit_log_end (ab );
13381303}
13391304
1340- static void audit_log_exit (struct audit_context * context , struct task_struct * tsk )
1305+ static void audit_log_exit (void )
13411306{
13421307 int i , call_panic = 0 ;
1308+ struct audit_context * context = audit_context ();
13431309 struct audit_buffer * ab ;
13441310 struct audit_aux_data * aux ;
13451311 struct audit_names * n ;
13461312
1347- /* tsk == current */
1348- context -> personality = tsk -> personality ;
1313+ context -> personality = current -> personality ;
13491314
13501315 ab = audit_log_start (context , GFP_KERNEL , AUDIT_SYSCALL );
13511316 if (!ab )
@@ -1367,7 +1332,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
13671332 context -> argv [3 ],
13681333 context -> name_count );
13691334
1370- audit_log_task_info (ab , tsk );
1335+ audit_log_task_info (ab );
13711336 audit_log_key (ab , context -> filterkey );
13721337 audit_log_end (ab );
13731338
@@ -1456,7 +1421,7 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
14561421 audit_log_name (context , n , NULL , i ++ , & call_panic );
14571422 }
14581423
1459- audit_log_proctitle (tsk , context );
1424+ audit_log_proctitle ();
14601425
14611426 /* Send end of event record to help user space know we are finished */
14621427 ab = audit_log_start (context , GFP_KERNEL , AUDIT_EOE );
@@ -1474,22 +1439,31 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
14741439 */
14751440void __audit_free (struct task_struct * tsk )
14761441{
1477- struct audit_context * context ;
1442+ struct audit_context * context = tsk -> audit_context ;
14781443
1479- context = audit_take_context (tsk , 0 , 0 );
14801444 if (!context )
14811445 return ;
14821446
1483- /* Check for system calls that do not go through the exit
1484- * function (e.g., exit_group), then free context block.
1485- * We use GFP_ATOMIC here because we might be doing this
1486- * in the context of the idle thread */
1487- /* that can happen only if we are called from do_exit() */
1488- if (context -> in_syscall && context -> current_state == AUDIT_RECORD_CONTEXT )
1489- audit_log_exit (context , tsk );
1447+ /* We are called either by do_exit() or the fork() error handling code;
1448+ * in the former case tsk == current and in the latter tsk is a
1449+ * random task_struct that doesn't doesn't have any meaningful data we
1450+ * need to log via audit_log_exit().
1451+ */
1452+ if (tsk == current && !context -> dummy && context -> in_syscall ) {
1453+ context -> return_valid = 0 ;
1454+ context -> return_code = 0 ;
1455+
1456+ audit_filter_syscall (tsk , context ,
1457+ & audit_filter_list [AUDIT_FILTER_EXIT ]);
1458+ audit_filter_inodes (tsk , context );
1459+ if (context -> current_state == AUDIT_RECORD_CONTEXT )
1460+ audit_log_exit ();
1461+ }
1462+
14901463 if (!list_empty (& context -> killed_trees ))
14911464 audit_kill_trees (& context -> killed_trees );
14921465
1466+ audit_set_context (tsk , NULL );
14931467 audit_free_context (context );
14941468}
14951469
@@ -1559,17 +1533,40 @@ void __audit_syscall_exit(int success, long return_code)
15591533{
15601534 struct audit_context * context ;
15611535
1562- if (success )
1563- success = AUDITSC_SUCCESS ;
1564- else
1565- success = AUDITSC_FAILURE ;
1566-
1567- context = audit_take_context (current , success , return_code );
1536+ context = audit_context ();
15681537 if (!context )
15691538 return ;
15701539
1571- if (context -> in_syscall && context -> current_state == AUDIT_RECORD_CONTEXT )
1572- audit_log_exit (context , current );
1540+ if (!context -> dummy && context -> in_syscall ) {
1541+ if (success )
1542+ context -> return_valid = AUDITSC_SUCCESS ;
1543+ else
1544+ context -> return_valid = AUDITSC_FAILURE ;
1545+
1546+ /*
1547+ * we need to fix up the return code in the audit logs if the
1548+ * actual return codes are later going to be fixed up by the
1549+ * arch specific signal handlers
1550+ *
1551+ * This is actually a test for:
1552+ * (rc == ERESTARTSYS ) || (rc == ERESTARTNOINTR) ||
1553+ * (rc == ERESTARTNOHAND) || (rc == ERESTART_RESTARTBLOCK)
1554+ *
1555+ * but is faster than a bunch of ||
1556+ */
1557+ if (unlikely (return_code <= - ERESTARTSYS ) &&
1558+ (return_code >= - ERESTART_RESTARTBLOCK ) &&
1559+ (return_code != - ENOIOCTLCMD ))
1560+ context -> return_code = - EINTR ;
1561+ else
1562+ context -> return_code = return_code ;
1563+
1564+ audit_filter_syscall (current , context ,
1565+ & audit_filter_list [AUDIT_FILTER_EXIT ]);
1566+ audit_filter_inodes (current , context );
1567+ if (context -> current_state == AUDIT_RECORD_CONTEXT )
1568+ audit_log_exit ();
1569+ }
15731570
15741571 context -> in_syscall = 0 ;
15751572 context -> prio = context -> state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0 ;
@@ -1591,7 +1588,6 @@ void __audit_syscall_exit(int success, long return_code)
15911588 kfree (context -> filterkey );
15921589 context -> filterkey = NULL ;
15931590 }
1594- audit_set_context (current , context );
15951591}
15961592
15971593static inline void handle_one (const struct inode * inode )
@@ -2025,7 +2021,7 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
20252021 uid = from_kuid (& init_user_ns , task_uid (current ));
20262022 oldloginuid = from_kuid (& init_user_ns , koldloginuid );
20272023 loginuid = from_kuid (& init_user_ns , kloginuid ),
2028- tty = audit_get_tty (current );
2024+ tty = audit_get_tty ();
20292025
20302026 audit_log_format (ab , "pid=%d uid=%u" , task_tgid_nr (current ), uid );
20312027 audit_log_task_context (ab );
@@ -2046,7 +2042,6 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
20462042 */
20472043int audit_set_loginuid (kuid_t loginuid )
20482044{
2049- struct task_struct * task = current ;
20502045 unsigned int oldsessionid , sessionid = AUDIT_SID_UNSET ;
20512046 kuid_t oldloginuid ;
20522047 int rc ;
@@ -2065,8 +2060,8 @@ int audit_set_loginuid(kuid_t loginuid)
20652060 sessionid = (unsigned int )atomic_inc_return (& session_id );
20662061 }
20672062
2068- task -> sessionid = sessionid ;
2069- task -> loginuid = loginuid ;
2063+ current -> sessionid = sessionid ;
2064+ current -> loginuid = loginuid ;
20702065out :
20712066 audit_log_set_loginuid (oldloginuid , loginuid , oldsessionid , sessionid , rc );
20722067 return rc ;
0 commit comments