RFC, aiding pid/network correlation
Subsystems (6)
v2 cover RFC, aiding pid/network correlation
I'm interested in having a host-based monitoring mechanism in place in the linux kernel. At this point I'm specifically looking to tie any given packet seen on the network back to the process that sent or received it. This is the sort of information our incident responders are constantly asking for.
This is round 2 of the patchset. It's essentially taking HONE [1], a kernel module originally written by Brandon Carpenter and switches the hooks to use the standard (plus a new one, task_post_create) LSM hooks + a run through cleanfile/checkpatch.
At a high level, Hone hooks process/socket creations/terminations and inet/inet6 packets that are sent or received. A userspace application can then correlate packet to process by reading the events from the kernel.
(Note, there doesn't appear to be outbound version of the callback socket_sock_rcv_skb and the socket_sendmsg/socket_recvmsg are called too early in the process to be used so this uses netfilter hooks.)
This patchset makes the events available as text via securityfs in /sys/kernel/security/hone/text and /sys/kernel/security/hone/pcapng. The text output looks like
3.350826817 EXEC 718 1 0 0 "/usr/sbin/cupsd" /usr/sbin/cupsd -f 3.350826817 SOCK O 718 1 0 0 b14e0000
...
5301.871561546 EXEC 2652 2586 1000 1000 "/bin/less" less 5303.104510870 EXEC 2653 2651 0 0 "/bin/cat" cat /sys/kernel/security/hone/text 5303.110322648 PAKT O 382d0700 2524 TCPv4 169.254.0.11:22 -> 169.254.0.2:49387 120
and the pcapng format is described in hone_pcapng.h.
There are some drawbacks with this method. Notably, it doesn't accurately track the owning pid of sockets passed via dup(), dup2() etc.
This particular approach is all very experimental. We had a need for this level of monitoring on some of our machines (did I mention the incident responders?) and HONE had the best features/efficiency.
I've CC'd the netdev folks at James' suggestion. I CC'd you, Casey as you were the one who suggested this be a proper LSM.
So I'm humbly requesting comments.
* Is there a better (more efficient/extensible) way to do this?
* Is there already an existing mechanism to do this?
* Is there any interest in something like this living in the kernel? Or is the dkms distributed path the way to go?
And if this is all reasonable, is it possible to add a socket_sock_send_skb callback and where might that go?
Finally, the linux-sensor project was released under the GPL but I'm not sure if there are any copyright issues ... ? I've just kept the copyright comments in any event.
This has been tested against security-next
[1] https://github.com/HoneProject/Linux-Sensor
Peter Moody (2):
security: create task_post_create callback.
security: Hone LSM
include/linux/hone.h | 50 +++ include/linux/security.h | 8 + kernel/fork.c | 1 + security/Kconfig | 1 + security/Makefile | 2 + security/capability.c | 5 + security/hone/Kconfig | 8 + security/hone/Makefile | 3 + security/hone/hone.h | 164 ++++++++++ security/hone/hone_event.c | 625 +++++++++++++++++++++++++++++++++++++ security/hone/hone_lsm.c | 183 +++++++++++ security/hone/hone_mmutil.c | 106 +++++++ security/hone/hone_mmutil.h | 20 ++ security/hone/hone_notify.c | 450 ++++++++++++++++++++++++++ security/hone/hone_pcapng.c | 596 +++++++++++++++++++++++++++++++++++ security/hone/hone_pcapng.h | 30 ++ security/hone/hone_ringbuf.c | 51 +++ security/hone/hone_ringbuf.h | 34 ++ security/hone/hone_socket_lookup.c | 264 ++++++++++++++++ security/security.c | 5 + 20 files changed, 2606 insertions(+) create mode 100644 include/linux/hone.h create mode 100644 security/hone/Kconfig create mode 100644 security/hone/Makefile create mode 100644 security/hone/hone.h create mode 100644 security/hone/hone_event.c create mode 100644 security/hone/hone_lsm.c create mode 100644 security/hone/hone_mmutil.c create mode 100644 security/hone/hone_mmutil.h create mode 100644 security/hone/hone_notify.c create mode 100644 security/hone/hone_pcapng.c create mode 100644 security/hone/hone_pcapng.h create mode 100644 security/hone/hone_ringbuf.c create mode 100644 security/hone/hone_ringbuf.h create mode 100644 security/hone/hone_socket_lookup.c
Signature · 1 line
2.0.0.526.g5318336
PATCH v2 1/2 security: create task_post_create callback.
The current LSM framework doesn't have a mechanism for accessing a task after it's been created but before it's been started. This patch adds a task_post_create callback so an LSM can access a newly created task before it has actually started running.
--- include/linux/security.h | 8 ++++++++ kernel/fork.c | 1 + security/capability.c | 5 +++++ security/security.c | 5 +++++ 4 files changed, 19 insertions(+)
include/linux/security.h +8 -0
@@ -668,6 +668,9 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)* manual page for definitions of the @clone_flags. * @clone_flags contains the flags indicating what should be shared. * Return 0 if permission is granted. +* @task_post_create: +* This hook allows a module to update or allocate a per-task security +* structure. * @task_free: * @task task being freed * Handle release of task-related resources. (Note that this can be called
@@ -1566,6 +1569,7 @@ struct security_operations {int (*file_open) (struct file *file,const struct cred *cred);int (*task_create) (unsigned long clone_flags); +void (*task_post_create)(struct task_struct *task);void (*task_free) (struct task_struct *task);int (*cred_alloc_blank) (struct cred *cred,gfp_t gfp);void (*cred_free) (struct cred *cred);
@@ -1840,6 +1844,7 @@ int security_file_send_sigiotask(struct task_struct *tsk,int security_file_receive (struct file *file);int security_file_open (struct file *file,const struct cred *cred);int security_task_create (unsigned long clone_flags); +void security_task_post_create (struct task_struct *task);void security_task_free (struct task_struct *task);int security_cred_alloc_blank (struct cred *cred,gfp_t gfp);void security_cred_free (struct cred *cred);
@@ -2340,6 +2345,9 @@ static inline int security_task_create(unsigned long clone_flags)return 0 ; } +static inline void security_task_post_create (struct task_struct *task) +{ } +static inline void security_task_free (struct task_struct *task) { }
kernel/fork.c +1 -0
@@ -1657,6 +1657,7 @@ long do_fork(unsigned long clone_flags,struct completion vfork;struct pid *pid; +security_task_post_create (p);trace_sched_process_fork (current, p); pid =get_task_pid (p,PIDTYPE_PID );
security/capability.c +5 -0
@@ -369,6 +369,10 @@ static int cap_task_create(unsigned long clone_flags)return 0 ; } +static void cap_task_post_create (struct task_struct *task) +{ +} +static void cap_task_free (struct task_struct *task) { }
@@ -1013,6 +1017,7 @@ void __init security_fixup_ops(struct security_operations *ops)set_to_cap_if_null (ops, file_receive);set_to_cap_if_null (ops, file_open);set_to_cap_if_null (ops, task_create); +set_to_cap_if_null (ops, task_post_create);set_to_cap_if_null (ops, task_free);set_to_cap_if_null (ops, cred_alloc_blank);set_to_cap_if_null (ops, cred_free);
security/security.c +5 -0
@@ -807,6 +807,11 @@ int security_task_create(unsigned long clone_flags)return security_ops->task_create (clone_flags); } +void security_task_post_create (struct task_struct *task) +{ + security_ops->task_post_create (task); +} +void security_task_free (struct task_struct *task) {#ifdef CONFIG_SECURITY_YAMA_STACKED
Signature · 1 line
2.0.0.526.g5318336
PATCH v2 2/2 security: Hone LSM
In reply to Peter MoodyThis adds the Hone (Host/Network) process <-> packet correlation module to the linux security subsystem. Hone aims to provide network administrators with the ability to correlate network activity seen on the network to the process which sent/received it.
--- include/linux/hone.h | 50 +++ security/Kconfig | 1 + security/Makefile | 2 + security/hone/Kconfig | 8 + security/hone/Makefile | 3 + security/hone/hone.h | 164 ++++++++++ security/hone/hone_event.c | 625 +++++++++++++++++++++++++++++++++++++ security/hone/hone_lsm.c | 183 +++++++++++ security/hone/hone_mmutil.c | 106 +++++++ security/hone/hone_mmutil.h | 20 ++ security/hone/hone_notify.c | 450 ++++++++++++++++++++++++++ security/hone/hone_pcapng.c | 596 +++++++++++++++++++++++++++++++++++ security/hone/hone_pcapng.h | 30 ++ security/hone/hone_ringbuf.c | 51 +++ security/hone/hone_ringbuf.h | 34 ++ security/hone/hone_socket_lookup.c | 264 ++++++++++++++++ 16 files changed, 2587 insertions(+) create mode 100644 include/linux/hone.h create mode 100644 security/hone/Kconfig create mode 100644 security/hone/Makefile create mode 100644 security/hone/hone.h create mode 100644 security/hone/hone_event.c create mode 100644 security/hone/hone_lsm.c create mode 100644 security/hone/hone_mmutil.c create mode 100644 security/hone/hone_mmutil.h create mode 100644 security/hone/hone_notify.c create mode 100644 security/hone/hone_pcapng.c create mode 100644 security/hone/hone_pcapng.h create mode 100644 security/hone/hone_ringbuf.c create mode 100644 security/hone/hone_ringbuf.h create mode 100644 security/hone/hone_socket_lookup.c
include/linux/hone.h new file +50 -0
@@ -0,0 +1,50 @@ +/* +* Copyright (C) 2011 Battelle Memorial Institute +* +* Licensed under the GNU General Public License Version 2. +* See LICENSE for the full text of the license. +* See DISCLAIMER for additional disclaimers. +* +* Author: Brandon Carpenter +*/ + +#include <linux/skbuff.h> + +#ifndef _INCLUDE_LINUX_HONE_H +#define _INCLUDE_LINUX_HONE_H + +#define PKTNOT_PACKET_IN 1 +#define PKTNOT_PACKET_OUT 2 + +/* hone block types for pcapng blocks */ +#define HONE_IF_DESC_BLOCK 0x00000001 +#define HONE_IF_STATS_BLOCK 0x00000005 +#define HONE_PACKET_BLOCK 0x00000006 +#define HONE_PROCESS_BLOCK 0x00000101 +#define HONE_CONNECTION_BLOCK 0x00000102 +#define HONE_SECTION_HDR_BLOCK 0x0A0D0D0A + +/* ioctls for controlling hone. */ +#define HEIO_RESTART _IO(0xE0, 0x01) +#define HEIO_GET_AT_HEAD _IO(0xE0, 0x03) +#define HEIO_GET_SNAPLEN _IOR(0xE0, 0x04, int) +#define HEIO_SET_SNAPLEN _IOW(0xE0, 0x05, int) +#define HEIO_SET_FILTER_SOCK _IOW(0xE0, 0x06, int) + +#define HONE_PROCESS 1 +#define HONE_SOCKET 2 +#define HONE_PACKET 3 +#define HONE_USER 0x8000 + +#define PROC_FORK 1 +#define PROC_EXEC 2 +#define PROC_EXIT 3 +#define PROC_KTHD 4 + +void hone_exec_handler (int ); +void hone_exit_handler (void ); +void hone_fork_handler (struct task_struct *); +void hone_raw_rcv_handler (struct sock *,struct sk_buff *); +void hone_inet_create_handler (int ,struct sock *); + +#endif
security/Kconfig +1 -0
@@ -122,6 +122,7 @@ source security/smack/Kconfig source security/tomoyo/Kconfig source security/apparmor/Kconfig source security/yama/Kconfig +source security/hone/Kconfig source security/integrity/Kconfig
security/Makefile +2 -0
@@ -8,6 +8,7 @@ subdir-$(CONFIG_SECURITY_SMACK) += smack subdir-$(CONFIG_SECURITY_TOMOYO) += tomoyo subdir-$(CONFIG_SECURITY_APPARMOR) += apparmor subdir-$(CONFIG_SECURITY_YAMA) += yama +subdir-$(CONFIG_SECURITY_HONE) += hone # always enable default capabilities obj-y += commoncap.o
@@ -22,6 +23,7 @@ obj-$(CONFIG_AUDIT) += lsm_audit.o obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/ obj-$(CONFIG_SECURITY_APPARMOR) += apparmor/ obj-$(CONFIG_SECURITY_YAMA) += yama/ +obj-$(CONFIG_SECURITY_HONE) += hone/ obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o # Object integrity file lists
security/hone/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +config SECURITY_HONE + bool "HOst NEt corrleation engine support" + default n + help + This selects hone, a tool for correlating packets to + processes. + + If you are unsure how to answer this question, answer N.
security/hone/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_SECURITY_HONE) := hone.o +hone-y := hone_lsm.o hone_notify.o hone_ringbuf.o hone_event.o \ + hone_mmutil.o hone_pcapng.o hone_ringbuf.o hone_socket_lookup.o
security/hone/hone.h new file +164 -0
164 lines not on this page · raw message
security/hone/hone_event.c new file +625 -0
625 lines not on this page · raw message
security/hone/hone_lsm.c new file +183 -0
183 lines not on this page · raw message
security/hone/hone_mmutil.c new file +106 -0
106 lines not on this page · raw message
security/hone/hone_mmutil.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2011 Battelle Memorial Institute +* +* Licensed under the GNU General Public License Version 2. +* See LICENSE for the full text of the license. +* See DISCLAIMER for additional disclaimers. +* +* Author: Brandon Carpenter +*/ + +#ifndef _MMUTIL_H +#define _MMUTIL_H + +#include <linux/mm_types.h> + +char *mm_path (struct mm_struct *mm,char *buf,int buflen); +char *mm_path_old (struct mm_struct *mm,char *buf,int buflen); +int mm_argv (struct mm_struct *mm,char *buf,int buflen); + +#endif /* _MMUTIL_H */
security/hone/hone_notify.c new file +450 -0
450 lines not on this page · raw message
security/hone/hone_pcapng.c new file +596 -0
596 lines not on this page · raw message
security/hone/hone_pcapng.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Copyright (C) 2011 Battelle Memorial Institute +* +* Licensed under the GNU General Public License Version 2. +* See LICENSE for the full text of the license. +* See DISCLAIMER for additional disclaimers. +* +* Author: Brandon Carpenter +*/ + +#ifndef _PCAPNG_H +#define _PCAPNG_H + +#include <linux/atomic.h> +#include <linux/time.h> + +#define HONE_USER_HEAD (HONE_USER | 1) +#define HONE_USER_TAIL (HONE_USER | 2) + +#define GUID_FMT "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define GUID_TUPLE (G ) (G)->data1, (G)->data2, (G)->data3, \ + (G)->data4[0], (G)->data4[1], (G)->data4[2], (G)->data4[3], \ + (G)->data4[4], (G)->data4[5], (G)->data4[6], (G)->data4[7] + +unsigned int format_as_pcapng ( +const struct device_info *devinfo,const struct reader_info *info, +struct hone_event *event,char *buf,unsigned int buflen); +int parse_guid (struct guid_struct *guid,const char *input); + +#endif /* _PCAPNG_H */
security/hone/hone_ringbuf.c new file +51 -0
51 lines not on this page · raw message
security/hone/hone_ringbuf.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) 2011 Battelle Memorial Institute +* +* Licensed under the GNU General Public License Version 2. +* See LICENSE for the full text of the license. +* See DISCLAIMER for additional disclaimers. +* +* Author: Brandon Carpenter +* +* Implementation of lock-free ring buffer. +*/ + +#ifndef _RINGBUF_H +#define _RINGBUF_H + +#include <linux/types.h> + +struct ring_buf { +atomic_t front; +atomic_t back; +unsigned int length; +unsigned int pageorder; +void **data; +}; + +#define ring_front (ring) ((unsigned int) atomic_read(&(ring)->front)) +#define ring_back (ring) ((unsigned int) atomic_read(&(ring)->back)) +#define ring_used (ring) (ring_back(ring) - ring_front(ring)) +#define ring_is_empty (ring) (ring_front(ring) == ring_back(ring)) + +int ring_append (struct ring_buf *ring,void *elem); +void *ring_pop (struct ring_buf *ring); + +#endif /* _RINGBUF_H */
security/hone/hone_socket_lookup.c new file +264 -0
264 lines not on this page · raw message
Signature · 1 line
2.0.0.526.g5318336
Quoted 42 lines · Peter Moody
I'm interested in having a host-based monitoring mechanism in place in the linux kernel. At this point I'm specifically looking to tie any given packet seen on the network back to the process that sent or received it. This is the sort of information our incident responders are constantly asking for.
This is round 2 of the patchset. It's essentially taking HONE [1], a kernel module originally written by Brandon Carpenter and switches the hooks to use the standard (plus a new one,
task_post_create) LSM hooks + a run through cleanfile/checkpatch.At a high level, Hone hooks process/socket creations/terminations and inet/inet6 packets that are sent or received. A userspace application can then correlate packet to process by reading the events from the kernel.
(Note, there doesn't appear to be outbound version of the callback
socket_sock_rcv_skband the socket_sendmsg/socket_recvmsg are called too early in the process to be used so this uses netfilter hooks.)This patchset makes the events available as text via securityfs in
/sys/kernel/security/hone/textand/sys/kernel/security/hone/pcapng. The text output looks like3.350826817 EXEC 718 1 0 0 "
/usr/sbin/cupsd"/usr/sbin/cupsd-f 3.350826817 SOCK O 718 1 0 0b14e0000
...
5301.871561546 EXEC 2652 2586 1000 1000 "/bin/less" less 5303.104510870 EXEC 2653 2651 0 0 "/bin/cat" cat/sys/kernel/security/hone/text5303.110322648 PAKT O382d07002524 TCPv4 169.254.0.11:22 -> 169.254.0.2:49387 120and the pcapng format is described in
hone_pcapng.h.There are some drawbacks with this method. Notably, it doesn't accurately track the owning pid of sockets passed via
dup(),dup2()etc.This particular approach is all very experimental. We had a need for this level of monitoring on some of our machines (did I mention the incident responders?) and HONE had the best features/efficiency.
Quoted 7 lines
I've CC'd the netdev folks at James' suggestion. I CC'd you, Casey as you were the one who suggested this be a proper LSM.
So I'm humbly requesting comments.
* Is there a better (more efficient/extensible) way to do this?
* Is there already an existing mechanism to do this?
Hi Peter,
I have built a such subsystem, for years now. Please, you can access latest public patchset here :
https://lkml.org/lkml/2011/5/5/132
monitoring events is possible with snet.
thanks,
(resending, first mail didn't hit lists)
Quoted 61 lines
* Is there any interest in something like this living in the kernel? Or is the dkms distributed path the way to go?
And if this is all reasonable, is it possible to add a
socket_sock_send_skbcallback and where might that go?Finally, the linux-sensor project was released under the GPL but I'm not sure if there are any copyright issues ... ? I've just kept the copyright comments in any event.
This has been tested against security-next
[1] https://github.com/HoneProject/Linux-Sensor
Peter Moody (2):
security: createtask_post_createcallback.
security: Hone LSMinclude/linux/hone.h | 50 +++ include/linux/security.h | 8 + kernel/fork.c | 1 + security/Kconfig | 1 + security/Makefile | 2 + security/capability.c | 5 + security/hone/Kconfig | 8 + security/hone/Makefile | 3 + security/hone/hone.h | 164 ++++++++++ security/hone/hone_event.c | 625 +++++++++++++++++++++++++++++++++++++ security/hone/hone_lsm.c | 183 +++++++++++ security/hone/hone_mmutil.c | 106 +++++++ security/hone/hone_mmutil.h | 20 ++ security/hone/hone_notify.c | 450 ++++++++++++++++++++++++++ security/hone/hone_pcapng.c | 596 +++++++++++++++++++++++++++++++++++ security/hone/hone_pcapng.h | 30 ++ security/hone/hone_ringbuf.c | 51 +++ security/hone/hone_ringbuf.h | 34 ++ security/hone/hone_socket_lookup.c | 264 ++++++++++++++++ security/security.c | 5 + 20 files changed, 2606 insertions(+) create mode 100644 include/linux/hone.h create mode 100644 security/hone/Kconfig create mode 100644 security/hone/Makefile create mode 100644 security/hone/hone.h create mode 100644 security/hone/hone_event.c create mode 100644 security/hone/hone_lsm.c create mode 100644 security/hone/hone_mmutil.c create mode 100644 security/hone/hone_mmutil.h create mode 100644 security/hone/hone_notify.c create mode 100644 security/hone/hone_pcapng.c create mode 100644 security/hone/hone_pcapng.h create mode 100644 security/hone/hone_ringbuf.c create mode 100644 security/hone/hone_ringbuf.h create mode 100644 security/hone/hone_socket_lookup.cSignature · 6 lines
2.0.0.526.g5318336 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Samir,
Quoted 7 lines
Quoted 1 line
* Is there already an existing mechanism to do this?
Hi Peter,
I have built a such subsystem, for years now. Please, you can access latest public patchset here :
Interesting, thanks! I hadn't know about snet.
The patches don't apply cleanly, and while the merge wasn't difficult, it looks like the code has gotten out of sync with mainline and doesn't build (at least when applied to security-next). Did anything ever happen with snet?
Quoted 1 line
From looking at the code, it looks kind of like a 'little-snitch' for
linux, is that right? A process tries to open a socket/etc and snet requests that the user accept/reject the connection, and presumably while the user is being queried one could dig through /proc to find the exe/cmdline of the process making the request.
One thing that Hone does which snet doesn't seem to do (apologies if this is incorrect but I can't test) is that it provides a full process tree for a given pid back to init. When doing an investigation into a system compromise, knowing what started the process making the suspicious connection(s) (and what started *that* process) is often just as important as knowing that there's a compromise to begin with.
Cheers,
Quoted 5 lines
monitoring events is possible with snet.
thanks,
(resending, first mail didn't hit lists)
Quoted 11 lines · Peter Moody
Hi Samir,
Quoted 7 lines
Quoted 1 line
* Is there already an existing mechanism to do this?
Hi Peter,
I have built a such subsystem, for years now. Please, you can access latest public patchset here :Interesting, thanks! I hadn't know about snet.
Peter,
After taking a look at your patchset, I understand that you want to make a link between network packets and applications, by keeping system-related informations inside a memory structure (this process tree).
I started snet because of this. Packet filtering is not enough powerfull to be "easily" used by users. By "users", it includes network specialists too, because of this missing link to informations related to "system" (pid, process, memory, syscall, etc), and not only "network" related (procotol, port, etc.)
I think indeed that LSM hooks are the perfect place to understand the behavior of applications.
Quoted 4 lines
The patches don't apply cleanly, and while the merge wasn't difficult, it looks like the code has gotten out of sync with mainline and doesn't build (at least when applied to security-next). Did anything ever happen with snet?
sure, this public release is out of sync with current kernels (it's 3 years old). I can release a up to date patchset.
Quoted 2 lines
From looking at the code, it looks kind of like a 'little-snitch' for linux, is that right?
Indeed, snet is including this kind of "control application", which is missing to the linux world, as packet filter is the "only way" to go.
Main goal is to build a framework for having a kind of "LSM userspace subsystem", pushing the decision to userspace, and to other related OS in the network.
Why this ?
- LSM are monolithic : applying a system policy on one isolated OS is no more valuable with our connected world.
- network filtering tools are not system related : what is more easiest than this network related analysis : "ok, so that's chromium which is connecting to .." ? But this sentence is only build this system related information (process, syscall "connect"), not on some "packet inspection".
- build new kind of security models, not only related to a isolated OS, but seeing the network as a global system. We are only sharing policy between hosts.. which is pretty inefficent nowsdays.
Quoted 2 lines
A process tries to open a socket/etc and snet requests that the user accept/reject the connection,
indeed, this is one of the possible application of snet.
but by "user", it's not only the physical user. It may be a process from userspace, or a decision from a central server in the network. So to fully agree on this, I may say : "snet requets userspace to accept/reject the connection". Decision comes from user in real time (click) or a security process built on a (local or distributed) formal model.
Quoted 3 lines
and presumably
while the user is being queried one could dig through /proc to find the exe/cmdline of the process making the request.
we don't have dig /proc, and I think it's a bad idea.
In fact, we don't need it at all.
Indeed, LSM hooks are occuring in the process context, so at the time of the syscall, system information is related to the application.
So, pid information is already part of the message sent from kernel subsystem to userspace. see snet_nl_send_event() exe/cmdline is in the same way sent from snet kernel subsystem (but it wasn't in the 2011 patches series)
but I think you get it right on the fact that extracting information *related* to the syscall is the most valuable part.
In the same time, current behavior is to put the process to a wait queue, until a verdict from userspace is coming back. (process context allow to sleep here)
a look at "genetlink attributes" in snet.h will give you access to all possible kind of available informations (at the time of this patch 3 years ago, now the list is more powerfull, and not only related to network)
Quoted 3 lines
One thing that Hone does which snet doesn't seem to do (apologies if this is incorrect but I can't test) is that it provides a full process tree for a given pid back to init.
snet is more like a framework now.
you can interactively register which syscall you want to monitor. then kernel substem will sent you informations. unregister, and the kernel subsystem is going quiet.
in order to build your process tree, you just use the userspace lib (I don't think it is yet publicly available, I have to put this up-to-date too)
the lib is build on the same libpcap callback mecanism : you register a syscall with a callback function. your callback function is called to manage the informations every time the related syscall occured. Here you can build your process tree, or do whatever you want.
Now, kernel subsystem doesn't required always a userspace verdict, as there is a "monitor mode", which is exactly what you will use if you decide to use snet.
As I said, snet is more like a framework to push this valuable informations to userspace, do whatever you want, and send back your policy decision (if it needs one)
Quoted 4 lines
When doing an investigation into a
system compromise, knowing what started the process making the suspicious connection(s) (and what started *that* process) is often just as important as knowing that there's a compromise to begin with.
this is exaclty one exemple of informations which is truly valuable by users or admins, and not direcly/interactively available on ours systems.
for me, best way to do that is building a simple and generic framework which will help you/admins/users to build simple scenarios from userspace to get what you want.
Quoted 1 line
Cheers,
Peter, thank you for pushing this discussion on the list, I think this kind of usability is missing, now for years, from our systems.
cheers,
sam
Peter Moody wrote:
<snip>
Quoted 6 lines
One thing that Hone does which snet doesn't seem to do (apologies if this is incorrect but I can't test) is that it provides a full process tree for a given pid back to init. When doing an investigation into a system compromise, knowing what started the process making the suspicious connection(s) (and what started *that* process) is often just as important as knowing that there's a compromise to begin with.
Out of curiosity, have you looked at Tomoyo much at all? In particular, it:
1.) Keeps a tree all the way back to init
2.) Has network event hooks (see footnote [1])
3.) Has an interactive API for managing policy violations (tomoyo-queryd[2] uses it)
4.) Is in mainline already.
The combination is actually sufficient to implement what you want for Hone _today_ as far as I can tell, and there's even the out-of-tree AKARI variant if you want to use it together with another LSM.
There's also Caitsith[3] (also from Tetsuo Handa), which might be even better suited but is not in mainline yet.
[1] It has these hooks for inet sockets, and similar for unix:
network inet stream bind $ADDRESS $PORT
network inet stream listen $ADDRESS $PORT
network inet stream connect $ADDRESS $PORT
network inet dgram bind $ADDRESS $PORT
network inet dgram send $ADDRESS $PORT
network inet raw bind $ADDRESS $PROTOCOL
network inet raw send $ADDRESS $PROTOCOL
See http://tomoyo.sourceforge.jp/2.5/policy-specification/domain-policy-syntax.html.en#network_inet
[2] http://tomoyo.sourceforge.jp/2.5/man-pages/tomoyo-queryd.html.en
[3] http://caitsith.sourceforge.jp/
Hi Sam
Quoted 14 lines
snet is more like a framework now.
you can interactively register which syscall you want to monitor. then kernel substem will sent you informations. unregister, and the kernel subsystem is going quiet.in order to build your process tree, you just use the userspace lib (I don't think it is yet publicly available, I have to put this up-to-date too)
the lib is build on the same libpcap callback mecanism : you register a syscall with a callback function. your callback function is called to manage the informations every time the related syscall occured. Here you can build your process tree, or do whatever you want.
Quoted 7 lines
Now, kernel subsystem doesn't required always a userspace verdict, as there is a "monitor mode", which is exactly what you will use if you decide to use snet.
As I said, snet is more like a framework to push this valuable informations to userspace, do whatever you want, and send back your policy decision (if it needs one)
It sounds at least in theory like snet can do what I'm looking for. I have a few concerns however:
* since I'm trying to tie individual packets to processes, I think that would mean that I'd have to register for socket_sendmsg/socket_recvmsg. Would that mean a trip to userspace (for the bpf callback at least if this is just in monitor mode) for every packet?
* obviously the current lsm hooks/attributes from snet.h don't account for tracking processes.
In any event, I'm interested in seeing the updated patchset/userspace lib for registering/reading events.
Cheers
Hey Alex,
Quoted 7 lines · Alex Elsayed
Out of curiosity, have you looked at Tomoyo much at all? In particular, it:
1.) Keeps a tree all the way back to init
2.) Has network event hooks (see footnote [1])
3.) Has an interactive API for managing policy violations (tomoyo-queryd[2] uses it)
4.) Is in mainline already.
I have looked at tomoyo before. There were a couple of things that kept it from being suitable for our needs:
The big one is that since the process tree is used to check policy, it's kept in-kernel and I'm primarily interested in having these events be easily exportable. IIRC (at least when I last looked), it wasn't possible to stream the events as they happened. tomoyo-queryd looks like it gets me real-time policy violations, but I don't have any policy per-se. I'm just trying to monitor processes and network activity.
We also already use apparmor so switching to a different LSM was a non-trivial task (admittedly this is now an issue for hone too, but hone wasn't an LSM initially).
Quoted 6 lines
The combination is actually sufficient to implement what you want for Hone _today_ as far as I can tell, and there's even the out-of-tree AKARI variant if you want to use it together with another LSM.
There's also Caitsith[3] (also from Tetsuo Handa), which might be even better suited but is not in mainline yet.
I'm not familiar with AKARI or Caitsith. I'll take a look.
Cheers,
peter
Quoted 16 lines · Peter Moody
Hey Alex,
Quoted 8 lines · Alex Elsayed
Out of curiosity, have you looked at Tomoyo much at all? In particular, it:
1.) Keeps a tree all the way back to init
2.) Has network event hooks (see footnote [1]) 3.) Has an interactive API for managing policy violations (tomoyo-queryd[2] uses it)
4.) Is in mainline already.I have looked at tomoyo before. There were a couple of things that kept it from being suitable for our needs:
Quoted 6 lines
The big one is that since the process tree is used to check policy, it's kept in-kernel and I'm primarily interested in having these events be easily exportable. IIRC (at least when I last looked), it wasn't possible to stream the events as they happened. tomoyo-queryd looks like it gets me real-time policy violations, but I don't have any policy per-se. I'm just trying to monitor processes and network activity.
Well, the simple answer is "define a policy that allows everything except network operations, and denies those" - this is reasonably simple if you use ACL groups because you can set the 'default policy' with acl group 0.
Quoted 3 lines
We also already use apparmor so switching to a different LSM was a non-trivial task (admittedly this is now an issue for hone too, but hone wasn't an LSM initially).
Yeah, there are flavors of Tomoyo (out-of-tree) that can be stacked, and there's the ongoing effort from Casey Schaufler to enable stacking more generally.
Quoted 8 lines
Quoted 6 lines
The combination is actually sufficient to implement what you want for Hone _today_ as far as I can tell, and there's even the out-of-tree AKARI variant if you want to use it together with another LSM.
There's also Caitsith[3] (also from Tetsuo Handa), which might be even better suited but is not in mainline yet.
I'm not familiar with AKARI or Caitsith. I'll take a look.
AKARI is basically just Tomoyo, but as a loadable kernel module and with (IIRC) stacking capability.
CaitSith is rather different, in that rather than having domain be the primary key things operate off of, the action is the central piece. So while Tomoyo's policy syntax is
DOMAIN
POLICY ACTION CONDITION
CaitSith's is
ACTION [QUALIFIER]
PRIORITY POLICY CONDITION [CONDITION...]
That's why I thought it might be a better fit - it'd allow you to specify _exactly_ the actions (socket connect, etc) you care about.
Quoted 7 lines
Cheers,
peter
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Alex Elsayed
Well, the simple answer is "define a policy that allows everything except network operations, and denies those" - this is reasonably simple if you use ACL groups because you can set the 'default policy' with acl group 0.
I'm not understanding. I don't want to deny network operations, I just want to be able to associate the operation with the 'offending' process.
Quoted 3 lines
Yeah, there are flavors of Tomoyo (out-of-tree) that can be stacked, and there's the ongoing effort from Casey Schaufler to enable stacking more generally.
Yeah, Casey was the one who suggested that I re-write this as an LSM. I think he saw the monitoring that I'm trying to do (as opposed to standard LSM deny/permit) as a good candidate for stacking.
Quoted 11 lines
CaitSith is rather different, in that rather than having domain be the primary key things operate off of, the action is the central piece. So while Tomoyo's policy syntax is
DOMAIN
POLICY ACTION CONDITIONCaitSith's is
ACTION [QUALIFIER]
PRIORITY POLICY CONDITION [CONDITION...]
Interesting. It sounds like it's still primary designed to deny/permit actions (based on some policy) and I'm really just looking to monitor.
Cheers,
peter
Quoted 26 lines · Peter Moody
Quoted 3 lines · Alex Elsayed
Well, the simple answer is "define a policy that allows everything except network operations, and denies those" - this is reasonably simple if you use ACL groups because you can set the 'default policy' with acl group 0.
I'm not understanding. I don't want to deny network operations, I just want to be able to associate the operation with the 'offending' process.
Quoted 3 lines
Yeah, there are flavors of Tomoyo (out-of-tree) that can be stacked, and there's the ongoing effort from Casey Schaufler to enable stacking more generally.
Yeah, Casey was the one who suggested that I re-write this as an LSM. I think he saw the monitoring that I'm trying to do (as opposed to standard LSM deny/permit) as a good candidate for stacking.
Quoted 7 lines
CaitSith is rather different, in that rather than having domain be the primary key things operate off of, the action is the central piece. So while Tomoyo's policy syntax is
DOMAIN
POLICY ACTION CONDITION
Quoted 7 lines
Quoted 4 lines
CaitSith's is
ACTION [QUALIFIER]
PRIORITY POLICY CONDITION [CONDITION...]Interesting. It sounds like it's still primary designed to deny/permit actions (based on some policy) and I'm really just looking to monitor.
Oh, I see now. Okay, that's actually considerably simpler - I just had somehow gotten it fixated into my mind that the info would be used to decide on allow/deny actions.
The trick to do what you want is the 'audit' support in both - here I'll use CaitSith as an example since the syntax is nicer.
In the header of a CaitSith policy, you specify resource limits for audit logs in the format
quota audit[$audit_index] allowed=$max_logs_for_allowed_request unmatched=$max_logs_for_unmatched_request denied=$max_logs_for_denied_request
(sans the linewrapping)
Now, by default _everything_ logs into audit index zero, but you can have multiple audit logs, and you can specify which one an action logs into. The result:
# Don't pollute the logs
quota audit[0] allowed=0 unmatched=0 denied=0
# Allow a one-million-item backlog of events that don't
# have an explicit policy allow/deny set on this unusual audit field quota audit[1] allowed=0 unmatched=1000000 denied=0
# Whenever someone tries to bind an AF_UNIX socket... 0 acl unix_stream_bind
# ...log that sucker.
audit 1Quoted 6 lines · Alex Elsayed
Oh, I see now. Okay, that's actually considerably simpler - I just had somehow gotten it fixated into my mind that the info would be used to decide on allow/deny actions.
The trick to do what you want is the 'audit' support in both - here I'll use CaitSith as an example since the syntax is nicer.
Do these audit logs end up with the audit subsystem? My experience with the audit subsystem is that performance takes a big hit when you start sending thousands (or even hundreds) of audit messages per second.
Quoted 2 lines
In the header of a CaitSith policy, you specify resource limits for audit logs in the format
I will definitely check out caitsith though. I think I saw Tetsuo talk about it at LSS in San Diego a few years ago.
Quoted 7 lines · Peter Moody
Quoted 4 lines · Alex Elsayed
Oh, I see now. Okay, that's actually considerably simpler - I just had somehow gotten it fixated into my mind that the info would be used to decide on allow/deny actions.
Quoted 6 lines
Quoted 2 lines
The trick to do what you want is the 'audit' support in both - here I'll use CaitSith as an example since the syntax is nicer.
Do these audit logs end up with the audit subsystem? My experience with the audit subsystem is that performance takes a big hit when you start sending thousands (or even hundreds) of audit messages per second.
No, they go straight to /proc/caitsith/audit and wind up looking like this:
#2012/04/08 05:03:03# global-pid=3720 result=allowed priority=100 / read path="/tmp/file1" task.pid=3720 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
Quoted 5 lines
Quoted 2 lines
In the header of a CaitSith policy, you specify resource limits for audit logs in the format
I will definitely check out caitsith though. I think I saw Tetsuo talk about it at LSS in San Diego a few years ago.
Quoted 19 lines · Alex Elsayed
Quoted 7 lines · Peter Moody
Quoted 4 lines · Alex Elsayed
Oh, I see now. Okay, that's actually considerably simpler - I just had somehow gotten it fixated into my mind that the info would be used to decide on allow/deny actions.
Quoted 6 lines
Quoted 2 lines
The trick to do what you want is the 'audit' support in both - here I'll use CaitSith as an example since the syntax is nicer.
Do these audit logs end up with the audit subsystem? My experience with the audit subsystem is that performance takes a big hit when you start sending thousands (or even hundreds) of audit messages per second.
No, they go straight to
/proc/caitsith/auditand wind up looking like this:
Quoted 10 lines
#2012/04/08 05:03:03# global-pid=3720 result=allowed priority=100 / read path="/tmp/file1" task.pid=3720 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
Actually, now that I look at that, you'd need to audit 'domain transition' events too - since that contains all the relevant PIDs, then the most recent domain transition with all of the right PIDs is sufficient to rebuild the tree back to init (recursively)
Quoted 11 lines · Alex Elsayed
Quoted 10 lines
#2012/04/08 05:03:03# global-pid=3720 result=allowed priority=100 / read path="/tmp/file1" task.pid=3720 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
Quoted 4 lines
Actually, now that I look at that, you'd need to audit 'domain transition' events too - since that contains all the relevant PIDs, then the most recent domain transition with all of the right PIDs is sufficient to rebuild the tree back to init (recursively)
How are network events logged? The documentation on caitsith.sourceforge is lacking.
In any event, it seems like it might be worth testing performance of tomoyo audit vs. hone. At least when the stacking issues are worked out.
Cheers,
peter
Quoted 13 lines · Peter Moody
Quoted 11 lines · Alex Elsayed
Quoted 10 lines
#2012/04/08 05:03:03# global-pid=3720 result=allowed priority=100 / read path="/tmp/file1" task.pid=3720 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
Quoted 7 lines
Quoted 4 lines
Actually, now that I look at that, you'd need to audit 'domain transition' events too - since that contains all the relevant PIDs, then the most recent domain transition with all of the right PIDs is sufficient to rebuild the tree back to init (recursively)
How are network events logged? The documentation on caitsith.sourceforge is lacking.
It depends on the event - if you look at the per-event docs[1], you'll see the variables it'll log. For instance, inet_stream_bind has 'ip', 'port', and 'task.$attribute' listed (and hyperlinked), so it'll log like this:
// These fields are common across all events:
// time, root-pid-ns PID, result, acl-priority, and chroot path #2012/04/08 05:03:03# global-pid=3720 result=unmatched priority=0 / // Then the actioninet_stream_bind
// then the variables
ip=0.0.0.0 port=80 task.pid=2245 task.ppid=3422 task.uid=81 task.gid=81 task.euid=81 task.egid=81 task.suid=0 task.sgid=0 task.fsuid=81 task.fsgid=81 task.type!=execute_handler task.exe="/user/bin/httpd" task.domain="/usr/bin/httpd"
[1] Start at http://caitsith.sourceforge.jp/#5.26 and scroll
Quoted 20 lines · Alex Elsayed
Quoted 18 lines · Peter Moody
Quoted 15 lines · Alex Elsayed
Quoted 10 lines
#2012/04/08 05:03:03# global-pid=3720 result=allowed priority=100 / read path="/tmp/file1" task.pid=3720 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53
Actually, now that I look at that, you'd need to audit 'domain transition' events too - since that contains all the relevant PIDs, then the most recent domain transition with all of the right PIDs is sufficient to rebuild the tree back to init (recursively)
Quoted 6 lines
Quoted 2 lines
How are network events logged? The documentation on caitsith.sourceforge is lacking.
It depends on the event - if you look at the per-event docs[1], you'll see the variables it'll log. For instance,
inet_stream_bindhas 'ip', 'port', and 'task.$attribute' listed (and hyperlinked), so it'll log like this:
Is this all caitsaith-specific? I don't see how to test what you're describing with tomoyo.
Cheers,
peter
Quoted 26 lines · Peter Moody
Quoted 24 lines · Alex Elsayed
Quoted 21 lines · Peter Moody
Quoted 12 lines · Alex Elsayed
Quoted 11 lines
#2012/04/08 05:03:03# global-pid=3720 result=allowed priority=100 / #read
path="/tmp/file1" task.pid=3720 task.ppid=3653 task.uid=0 task.gid=0 task.euid=0 task.egid=0 task.suid=0 task.sgid=0 task.fsuid=0 task.fsgid=0 task.type!=execute_handler task.exe="/bin/cat" task.domain="/usr/sbin/sshd" path.uid=0 path.gid=0 path.ino=2113451 path.major=8 path.minor=1 path.perm=0644 path.type=file path.fsmagic=0xEF53 path.parent.uid=0 path.parent.gid=0 path.parent.ino=2097153 path.parent.major=8 path.parent.minor=1 path.parent.perm=01777 path.parent.type=directory path.parent.fsmagic=0xEF53Quoted 4 lines
Actually, now that I look at that, you'd need to audit 'domain transition' events too - since that contains all the relevant PIDs, then the most recent domain transition with all of the right PIDs is sufficient to rebuild the tree back to init (recursively)
How are network events logged? The documentation on caitsith.sourceforge is lacking.
Quoted 7 lines
Quoted 4 lines
It depends on the event - if you look at the per-event docs[1], you'll see the variables it'll log. For instance,
inet_stream_bindhas 'ip', 'port', and 'task.$attribute' listed (and hyperlinked), so it'll log like this:Is this all caitsaith-specific? I don't see how to test what you're describing with tomoyo.
Looking at Tomoyo, it seems to do it differently (and less conveniently) - the best way might be to:
1.) be in "permissive" mode so that "deny" doesn't actually prevent anything 2.) Set "grant_log=no" and "reject_log=yes" in the CONFIG section 3.) in acl_group zero, allow by default but deny network operations 4.) Watch the logs
It does seem like the logs are less verbose than CaitSith, though.
Note that CaitSith can be built as a kernel module (without patching), so that might be worth testing as well.