@@ -34,6 +34,8 @@ along with sysdig. If not, see <http://www.gnu.org/licenses/>.
3434#include <linux/version.h>
3535#include <linux/module.h>
3636#include <linux/quota.h>
37+ #include <linux/tty.h>
38+ #include <linux/uaccess.h>
3739#ifdef CONFIG_CGROUPS
3840#include <linux/cgroup.h>
3941#endif
@@ -292,8 +294,8 @@ const struct ppm_event_entry g_ppm_events[PPM_EVENT_MAX] = {
292294 [PPME_DROP_X ] = {f_sched_drop },
293295 [PPME_SYSCALL_FCNTL_E ] = {f_sched_fcntl_e },
294296 [PPME_SYSCALL_FCNTL_X ] = {f_sys_single_x },
295- [PPME_SYSCALL_EXECVE_16_E ] = {f_sys_empty },
296- [PPME_SYSCALL_EXECVE_16_X ] = {f_proc_startupdate },
297+ [PPME_SYSCALL_EXECVE_17_E ] = {f_sys_empty },
298+ [PPME_SYSCALL_EXECVE_17_X ] = {f_proc_startupdate },
297299 [PPME_SYSCALL_CLONE_20_E ] = {f_sys_empty },
298300 [PPME_SYSCALL_CLONE_20_X ] = {f_proc_startupdate },
299301 [PPME_SYSCALL_BRK_4_E ] = {PPM_AUTOFILL , 1 , APT_REG , {{0 } } },
@@ -1011,6 +1013,52 @@ static int compat_accumulate_argv_or_env(compat_uptr_t argv,
10111013
10121014#endif
10131015
1016+ static int ppm_get_tty (void )
1017+ {
1018+ /* Locking of the signal structures seems too complicated across
1019+ * multiple kernel versions to get it right, so simply do protected
1020+ * memory accesses, and in the worst case we get some garbage,
1021+ * which is not the end of the world. In the vast majority of accesses,
1022+ * we'll be just fine.
1023+ */
1024+ struct signal_struct * sig ;
1025+ struct tty_struct * tty ;
1026+ struct tty_driver * driver ;
1027+ int major ;
1028+ int minor_start ;
1029+ int index ;
1030+ int tty_nr = 0 ;
1031+
1032+ sig = current -> signal ;
1033+ if (!sig )
1034+ return 0 ;
1035+
1036+ if (unlikely (probe_kernel_read (& tty , & sig -> tty , sizeof (tty ))))
1037+ return 0 ;
1038+
1039+ if (!tty )
1040+ return 0 ;
1041+
1042+ if (unlikely (probe_kernel_read (& index , & tty -> index , sizeof (index ))))
1043+ return 0 ;
1044+
1045+ if (unlikely (probe_kernel_read (& driver , & tty -> driver , sizeof (driver ))))
1046+ return 0 ;
1047+
1048+ if (!driver )
1049+ return 0 ;
1050+
1051+ if (unlikely (probe_kernel_read (& major , & driver -> major , sizeof (major ))))
1052+ return 0 ;
1053+
1054+ if (unlikely (probe_kernel_read (& minor_start , & driver -> minor_start , sizeof (minor_start ))))
1055+ return 0 ;
1056+
1057+ tty_nr = new_encode_dev (MKDEV (major , minor_start ) + index );
1058+
1059+ return tty_nr ;
1060+ }
1061+
10141062static int f_proc_startupdate (struct event_filler_arguments * args )
10151063{
10161064 unsigned long val ;
@@ -1035,7 +1083,7 @@ static int f_proc_startupdate(struct event_filler_arguments *args)
10351083 return res ;
10361084
10371085 if (unlikely (retval < 0 &&
1038- args -> event_type != PPME_SYSCALL_EXECVE_16_X )) {
1086+ args -> event_type != PPME_SYSCALL_EXECVE_17_X )) {
10391087
10401088 /* The call failed, but this syscall has no exe, args
10411089 * anyway, so I report empty ones */
@@ -1311,11 +1359,12 @@ static int f_proc_startupdate(struct event_filler_arguments *args)
13111359 if (unlikely (res != PPM_SUCCESS ))
13121360 return res ;
13131361
1314- } else if (args -> event_type == PPME_SYSCALL_EXECVE_16_X ) {
1362+ } else if (args -> event_type == PPME_SYSCALL_EXECVE_17_X ) {
13151363 /*
13161364 * execve-only parameters
13171365 */
13181366 long env_len = 0 ;
1367+ int tty_nr = 0 ;
13191368
13201369 if (likely (retval >= 0 )) {
13211370 /*
@@ -1357,6 +1406,14 @@ static int f_proc_startupdate(struct event_filler_arguments *args)
13571406 res = val_to_ring (args , (int64_t )(long )args -> str_storage , env_len , false, 0 );
13581407 if (unlikely (res != PPM_SUCCESS ))
13591408 return res ;
1409+
1410+ /*
1411+ * tty
1412+ */
1413+ tty_nr = ppm_get_tty ();
1414+ res = val_to_ring (args , tty_nr , 0 , false, 0 );
1415+ if (unlikely (res != PPM_SUCCESS ))
1416+ return res ;
13601417 }
13611418
13621419 return add_sentinel (args );
0 commit comments