namespaces: log namespaces per task
Subsystems (7)
v3 cover namespaces: log namespaces per task
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
1/6 defines a function to generate them and assigns them.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs). It could be argued that the inode numbers have now become a defacto interface and can't change now, but I'm proposing this approach to see if this helps address some of the objections to the earlier patchset.
2/6 adds access functions to get to the serial numbers in a similar way to inode access for namespace proc operations.
3/6 implements, as suggested by Serge Hallyn, making these serial numbers available in /proc/self/ns/{ipc,mnt,net,pid,user,uts}_snum. I chose "snum" instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.
4/6 exposes proc's ns entries structure which lists a number of useful operations per namespace type for other subsystems to use.
5/6 provides an example of usage for audit_log_task_info() which is used by syscall audits, among others. audit_log_task() and audit_common_recv_message() would be other potential use cases.
Proposed output format:
This differs slightly from Aristeu's patch because of the label conflict with "pid=" due to including it in existing records rather than it being a seperate record. The serial numbers are printed in hex.
type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)
6/6 tracks the creation and deletion of of namespaces, listing the type of namespace instance, related namespace id if there is one and the newly minted serial number.
Proposed output format:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a1 res=1 type=NS_DEL msg=audit(1400217435.730:95): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 snum=a1 res=1
v2 -> v3:
Use atomic64_t in ns_serial to simplify it.
Avoid funciton duplication in proc, keying on dentry. Squash down audit patch to avoid rcu sleep issues. Add tracking for creation and deletion of namespace instances.
v1 -> v2:
Avoid rollover by switching from an int to a long long. Change rollover behaviour from simply avoiding zero to raising a BUG. Expose serial numbers in /proc/<pid>/ns/*_snum.
Expose ns_entries and use it in audit.
Notes:
There has been some progress made for audit in net namespaces and pid namespaces since this previous thread. net namespaces are now served as peers by one auditd in the init_net namespace with processes in a non-init_net namespace being able to write records if they are in the init_user_ns and have CAP_AUDIT_WRITE. Processes in a non-init_pid_ns can now similarly write records. As for CAP_AUDIT_READ, I just posted a patchset to check capabilities of userspace processes that try to join netlink broadcast groups.
This set does not try to solve the non-init namespace audit messages and auditd problem yet. That will come later, likely with additional auditd instances running in another namespace with a limited ability to influence the master auditd. I echo Eric B's idea that messages destined for different namespaces would have to be tailored for that namespace with references that make sense (such as the right pid number reported to that pid namespace, and not leaking info about parents or peers).
Bugs:
Patch 6/6 has a timing bug such that mnt and net namespace initial namespaces never get logged, I suspect because they are initialized before the audit subsystem. I've tried moving audit from __initcall to subsys_initcall, but that doesn't help.
Questions:
Is there a way to link serial numbers of namespaces involved in migration of a container to another kernel? It sounds like what is needed is a part of a mangement application that is able to pull the audit rcords from constituent hosts to build an audit trail of a container.
What additional events should list this information?
Does this present any problematic information leaks? Only CAP_AUDIT_CONTROL (and proposed CAP_AUDIT_READ) in init_user_ns can get to this information in the init namespace at the moment from audit. *However*, the addition of the proc/<pid>/ns/*_snum does make it available to other processes now.
Richard Guy Briggs (6):
namespaces: assign each namespace instance a serial number
namespaces: expose namespace instance serial number in proc_ns_operations
namespaces: expose ns instance serial numbers in proc
namespaces: expose ns_entries
audit: log namespace serial numbers
audit: log creation and deletion of namespace instances
fs/mount.h | 1 + fs/namespace.c | 12 +++++++++ fs/proc/namespaces.c | 35 +++++++++++++++++++------- include/linux/audit.h | 15 +++++++++++ include/linux/ipc_namespace.h | 1 + include/linux/nsproxy.h | 8 ++++++ include/linux/pid_namespace.h | 1 + include/linux/proc_ns.h | 2 + include/linux/user_namespace.h | 1 + include/linux/utsname.h | 1 + include/net/net_namespace.h | 1 + include/uapi/linux/audit.h | 2 + init/version.c | 1 + ipc/msgutil.c | 1 + ipc/namespace.c | 20 +++++++++++++++ kernel/audit.c | 53 +++++++++++++++++++++++++++++++++++++++- kernel/nsproxy.c | 17 +++++++++++++ kernel/pid.c | 1 + kernel/pid_namespace.c | 19 ++++++++++++++ kernel/user.c | 1 + kernel/user_namespace.c | 18 +++++++++++++ kernel/utsname.c | 20 +++++++++++++++ net/core/net_namespace.c | 20 ++++++++++++++- 23 files changed, 240 insertions(+), 11 deletions(-)
PATCH v3 1/6 namespaces: assign each namespace instance a serial number
Generate and assign a serial number per namespace instance since boot.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs) to uniquely identify it per kernel boot.
--- fs/mount.h | 1 + fs/namespace.c | 1 + include/linux/ipc_namespace.h | 1 + include/linux/nsproxy.h | 8 ++++++++ include/linux/pid_namespace.h | 1 + include/linux/user_namespace.h | 1 + include/linux/utsname.h | 1 + include/net/net_namespace.h | 1 + init/version.c | 1 + ipc/msgutil.c | 1 + ipc/namespace.c | 2 ++ kernel/nsproxy.c | 17 +++++++++++++++++ kernel/pid.c | 1 + kernel/pid_namespace.c | 2 ++ kernel/user.c | 1 + kernel/user_namespace.c | 2 ++ kernel/utsname.c | 2 ++ net/core/net_namespace.c | 8 +++++++- 18 files changed, 51 insertions(+), 1 deletions(-)
fs/mount.h +1 -0
@@ -5,6 +5,7 @@struct mnt_namespace {atomic_t count;unsigned int proc_inum; +long long serial_num;struct mount * root;struct list_head list;struct user_namespace *user_ns;
fs/namespace.c +1 -0
@@ -2472,6 +2472,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)kfree (new_ns);return ERR_PTR (ret); } + new_ns->serial_num =ns_serial (); new_ns->seq =atomic64_add_return (1 , &mnt_ns_seq);atomic_set (&new_ns->count,1 ); new_ns->root =NULL ;
include/linux/ipc_namespace.h +1 -0
@@ -69,6 +69,7 @@ struct ipc_namespace {struct user_namespace *user_ns;unsigned int proc_inum; +long long serial_num; };extern struct ipc_namespace init_ipc_ns;
include/linux/nsproxy.h +8 -0
@@ -66,6 +66,14 @@ static inline struct nsproxy *task_nsproxy(struct task_struct *tsk)return rcu_dereference (tsk->nsproxy); } +long long ns_serial (void ); +enum { +NS_IPC_INIT_SN =1 , +NS_UTS_INIT_SN =2 , +NS_USER_INIT_SN =3 , +NS_PID_INIT_SN =4 , +}; +int copy_namespaces (unsigned long flags,struct task_struct *tsk);void exit_task_namespaces (struct task_struct *tsk);void switch_task_namespaces (struct task_struct *tsk,struct nsproxy *new);
include/linux/pid_namespace.h +1 -0
@@ -43,6 +43,7 @@ struct pid_namespace {int hide_pid;int reboot;/* group exit code if this pidns was rebooted */ unsigned int proc_inum; +long long serial_num; };extern struct pid_namespace init_pid_ns;
include/linux/user_namespace.h +1 -0
@@ -27,6 +27,7 @@ struct user_namespace {kuid_t owner;kgid_t group;unsigned int proc_inum; +long long serial_num;/* Register of per-UID persistent keyrings for this namespace */ #ifdef CONFIG_PERSISTENT_KEYRINGS
include/linux/utsname.h +1 -0
@@ -24,6 +24,7 @@ struct uts_namespace {struct new_utsname name;struct user_namespace *user_ns;unsigned int proc_inum; +long long serial_num; };extern struct uts_namespace init_uts_ns;
include/net/net_namespace.h +1 -0
@@ -59,6 +59,7 @@ struct net {struct user_namespace *user_ns;/* Owning user namespace */ unsigned int proc_inum; +long long serial_num;struct proc_dir_entry *proc_net;struct proc_dir_entry *proc_net_stat;
init/version.c +1 -0
@@ -36,6 +36,7 @@ struct uts_namespace init_uts_ns = { }, .user_ns = &init_user_ns, .proc_inum = PROC_UTS_INIT_INO, + .serial_num = NS_UTS_INIT_SN /* ns_serial() */, };EXPORT_SYMBOL_GPL (init_uts_ns);
ipc/msgutil.c +1 -0
@@ -32,6 +32,7 @@ struct ipc_namespace init_ipc_ns = { .count = ATOMIC_INIT(1), .user_ns = &init_user_ns, .proc_inum = PROC_IPC_INIT_INO, + .serial_num = NS_IPC_INIT_SN /* ns_serial() */, };atomic_t nr_ipc_ns =ATOMIC_INIT (1 );
ipc/namespace.c +2 -0
@@ -41,6 +41,8 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, }atomic_inc (&nr_ipc_ns); + ns->serial_num =ns_serial (); +sem_init_ns (ns);msg_init_ns (ns);shm_init_ns (ns);
kernel/nsproxy.c +17 -0
@@ -41,6 +41,23 @@ struct nsproxy init_nsproxy = {#endif }; +/** +* ns_serial - compute a serial number for the namespace +* +* Compute a serial number for the namespace to uniquely identify it in +* audit records. +*/ +long long ns_serial (void ) +{ +static atomic64_t serial =ATOMIC_INIT (4 );/* reserved for IPC, UTS, user, PID */ +long long ret; + + ret =atomic64_add_return (1 , &serial); +BUG_ON (!ret); + +return ret; +} +static inline struct nsproxy *create_nsproxy (void ) {struct nsproxy *nsproxy;
kernel/pid.c +1 -0
@@ -80,6 +80,7 @@ struct pid_namespace init_pid_ns = { .child_reaper = &init_task, .user_ns = &init_user_ns, .proc_inum = PROC_PID_INIT_INO, + .serial_num = NS_PID_INIT_SN /* ns_serial() */, };EXPORT_SYMBOL_GPL (init_pid_ns);
kernel/pid_namespace.c +2 -0
@@ -109,6 +109,8 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_nsif (err) goto out_free_map; + ns->serial_num =ns_serial (); +kref_init (&ns->kref); ns->level = level; ns->parent =get_pid_ns (parent_pid_ns);
kernel/user.c +1 -0
@@ -51,6 +51,7 @@ struct user_namespace init_user_ns = { .owner = GLOBAL_ROOT_UID, .group = GLOBAL_ROOT_GID, .proc_inum = PROC_USER_INIT_INO, + .serial_num =NS_USER_INIT_SN /* ns_serial() */ , #ifdef CONFIG_PERSISTENT_KEYRINGS .persistent_keyring_register_sem = __RWSEM_INITIALIZER(init_user_ns.persistent_keyring_register_sem),
kernel/user_namespace.c +2 -0
@@ -92,6 +92,8 @@ int create_user_ns(struct cred *new)return ret; } + ns->serial_num =ns_serial (); +atomic_set (&ns->count,1 );/* Leave the new->user_ns reference with the new user namespace. */ ns->parent = parent_ns;
kernel/utsname.c +2 -0
@@ -48,6 +48,8 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,return ERR_PTR (err); } + ns->serial_num =ns_serial (); +down_read (&uts_sem);memcpy (&ns->name, &old_ns->name,sizeof (ns->name)); ns->user_ns =get_user_ns (user_ns);
net/core/net_namespace.c +7 -1
@@ -384,7 +384,13 @@ EXPORT_SYMBOL_GPL(get_net_ns_by_pid);static __net_init int net_ns_net_init (struct net *net) { -return proc_alloc_inum (&net->proc_inum); +int ret; + + ret =proc_alloc_inum (&net->proc_inum); +if (ret) +return ret; + net->serial_num =ns_serial (); +return 0 ; } static __net_exit void net_ns_net_exit(struct net *net)
Signature · 1 line
1.7.1
PATCH v3 2/6 namespaces: expose namespace instance serial number in proc_ns_operations
In reply to Richard Guy BriggsExpose the namespace instance serial number for each namespace type in the proc namespace operations structure to make it available for the proc filesystem.
--- fs/namespace.c | 7 +++++++ include/linux/proc_ns.h | 1 + ipc/namespace.c | 8 ++++++++ kernel/pid_namespace.c | 7 +++++++ kernel/user_namespace.c | 7 +++++++ kernel/utsname.c | 8 ++++++++ net/core/net_namespace.c | 7 +++++++ 7 files changed, 45 insertions(+), 0 deletions(-)
fs/namespace.c +7 -0
@@ -3014,6 +3014,12 @@ static unsigned int mntns_inum(void *ns)return mnt_ns->proc_inum; } +static long long mntns_snum (void *ns) +{ +struct mnt_namespace *mnt_ns = ns; +return mnt_ns->serial_num; +} +const struct proc_ns_operations mntns_operations = { .name ="mnt" , .type =CLONE_NEWNS ,
@@ -3021,4 +3027,5 @@ const struct proc_ns_operations mntns_operations = { .put = mntns_put, .install = mntns_install, .inum = mntns_inum, + .snum = mntns_snum, };
include/linux/proc_ns.h +1 -0
@@ -14,6 +14,7 @@ struct proc_ns_operations {void (*put)(void *ns);int (*install)(struct nsproxy *nsproxy,void *ns);unsigned int (*inum)(void *ns); +long long (*snum)(void *ns); };struct proc_ns {
ipc/namespace.c +8 -0
@@ -191,6 +191,13 @@ static unsigned int ipcns_inum(void *vp)return ns->proc_inum; } +static long long ipcns_snum (void *vp) +{ +struct ipc_namespace *ns = vp; + +return ns->serial_num; +} +const struct proc_ns_operations ipcns_operations = { .name ="ipc" , .type =CLONE_NEWIPC ,
@@ -198,4 +205,5 @@ const struct proc_ns_operations ipcns_operations = { .put = ipcns_put, .install = ipcns_install, .inum = ipcns_inum, + .snum = ipcns_snum, };
kernel/pid_namespace.c +7 -0
@@ -368,6 +368,12 @@ static unsigned int pidns_inum(void *ns)return pid_ns->proc_inum; } +static long long pidns_snum (void *ns) +{ +struct pid_namespace *pid_ns = ns; +return pid_ns->serial_num; +} +const struct proc_ns_operations pidns_operations = { .name ="pid" , .type =CLONE_NEWPID ,
@@ -375,6 +381,7 @@ const struct proc_ns_operations pidns_operations = { .put = pidns_put, .install = pidns_install, .inum = pidns_inum, + .snum = pidns_snum, };static __init int pid_namespaces_init (void )
kernel/user_namespace.c +7 -0
@@ -890,6 +890,12 @@ static unsigned int userns_inum(void *ns)return user_ns->proc_inum; } +static long long userns_snum (void *ns) +{ +struct user_namespace *user_ns = ns; +return user_ns->serial_num; +} +const struct proc_ns_operations userns_operations = { .name ="user" , .type =CLONE_NEWUSER ,
@@ -897,6 +903,7 @@ const struct proc_ns_operations userns_operations = { .put = userns_put, .install = userns_install, .inum = userns_inum, + .snum = userns_snum, };static __init int user_namespaces_init (void )
kernel/utsname.c +8 -0
@@ -132,6 +132,13 @@ static unsigned int utsns_inum(void *vp)return ns->proc_inum; } +static long long utsns_snum (void *vp) +{ +struct uts_namespace *ns = vp; + +return ns->serial_num; +} +const struct proc_ns_operations utsns_operations = { .name ="uts" , .type =CLONE_NEWUTS ,
@@ -139,4 +146,5 @@ const struct proc_ns_operations utsns_operations = { .put = utsns_put, .install = utsns_install, .inum = utsns_inum, + .snum = utsns_snum, };
net/core/net_namespace.c +7 -0
@@ -671,6 +671,12 @@ static unsigned int netns_inum(void *ns)return net->proc_inum; } +static long long netns_snum (void *ns) +{ +struct net *net = ns; +return net->serial_num; +} +const struct proc_ns_operations netns_operations = { .name ="net" , .type =CLONE_NEWNET ,
@@ -678,5 +684,6 @@ const struct proc_ns_operations netns_operations = { .put = netns_put, .install = netns_install, .inum = netns_inum, + .snum = netns_snum, };#endif
Signature · 1 line
1.7.1
PATCH v3 3/6 namespaces: expose ns instance serial numbers in proc
In reply to Richard Guy BriggsExpose the namespace instace serial numbers in the proc filesystem at /proc/<pid>/ns/<ns>_snum. The link text gives the serial number in hex.
"snum" was chosen instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.
--- fs/proc/namespaces.c | 33 +++++++++++++++++++++++++-------- 1 files changed, 25 insertions(+), 8 deletions(-)
fs/proc/namespaces.c +25 -8
@@ -47,12 +47,15 @@ static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)struct inode *inode = dentry->d_inode;const struct proc_ns_operations *ns_ops =PROC_I (inode)->ns.ns_ops; -return dynamic_dname (dentry, buffer, buflen,"%s:[%lu]" , - ns_ops->name, inode->i_ino); +if (strstr (dentry->d_iname,"_snum" )) +return dynamic_dname (dentry, buffer, buflen,"%s_snum:[%llx]" , + ns_ops->name, ns_ops->snum (PROC_I (inode)->ns.ns)); +else +return dynamic_dname (dentry, buffer, buflen,"%s:[%lu]" , + ns_ops->name, inode->i_ino); } -const struct dentry_operations ns_dentry_operations = -{ +const struct dentry_operations ns_dentry_operations = { .d_delete = always_delete_dentry, .d_dname = ns_dname, };
@@ -160,7 +163,10 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int buflif (!ns) goto out_put_task; -snprintf (name,sizeof (name),"%s:[%u]" , ns_ops->name, ns_ops->inum (ns)); +if (strstr (dentry->d_iname,"_snum" )) +snprintf (name,sizeof (name),"%s_snum:[%llx]" , ns_ops->name, ns_ops->snum (ns)); +else +snprintf (name,sizeof (name),"%s:[%u]" , ns_ops->name, ns_ops->inum (ns)); len =strlen (name);if (len > buflen)
@@ -216,16 +222,23 @@ static int proc_ns_dir_readdir(struct file *file, struct dir_context *ctx)if (!dir_emit_dots (file, ctx)) goto out; -if (ctx->pos >=2 +ARRAY_SIZE (ns_entries)) +if (ctx->pos >=2 +2 *ARRAY_SIZE (ns_entries)) goto out; entry = ns_entries + (ctx->pos -2 ); last = &ns_entries[ARRAY_SIZE (ns_entries) -1 ];while (entry <= last) {const struct proc_ns_operations *ops = *entry; +char name[50 ]; +if (!proc_fill_cache (file, ctx, ops->name,strlen (ops->name), proc_ns_instantiate, task, ops))break ; ctx->pos++; +snprintf (name,sizeof (name),"%s_snum" , ops->name); +if (!proc_fill_cache (file, ctx, name,strlen (name), + proc_ns_instantiate, task, ops)) +break ; + ctx->pos++; entry++; } out:
@@ -253,9 +266,13 @@ static struct dentry *proc_ns_dir_lookup(struct inode *dir, last = &ns_entries[ARRAY_SIZE (ns_entries)];for (entry = ns_entries; entry < last; entry++) { -if (strlen ((*entry)->name) != len) +char name[50 ]; + +snprintf (name,sizeof (name),"%s_snum" , (*entry)->name); +if (strlen ((*entry)->name) != len &&strlen (name) != len)continue ; -if (!memcmp (dentry->d_name.name, (*entry)->name, len)) +if (!memcmp (dentry->d_name.name, (*entry)->name, len) + || !memcmp (dentry->d_name.name, name, len))break ; }if (entry == last)
Signature · 1 line
1.7.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 3/6 namespaces: expose ns instance serial numbers in proc
Expose the namespace instace serial numbers in the proc filesystem at /proc/<pid>/ns/<ns>_snum. The link text gives the serial number in hex.
"snum" was chosen instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.
--- fs/proc/namespaces.c | 33 +++++++++++++++++++++++++-------- 1 files changed, 25 insertions(+), 8 deletions(-)
fs/proc/namespaces.c +25 -8
@@ -47,12 +47,15 @@ static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)struct inode *inode = dentry->d_inode;const struct proc_ns_operations *ns_ops =PROC_I (inode)->ns.ns_ops; -return dynamic_dname (dentry, buffer, buflen,"%s:[%lu]" , - ns_ops->name, inode->i_ino); +if (strstr (dentry->d_iname,"_snum" )) +return dynamic_dname (dentry, buffer, buflen,"%s_snum:[%llx]" , + ns_ops->name, ns_ops->snum (PROC_I (inode)->ns.ns)); +else +return dynamic_dname (dentry, buffer, buflen,"%s:[%lu]" , + ns_ops->name, inode->i_ino); } -const struct dentry_operations ns_dentry_operations = -{ +const struct dentry_operations ns_dentry_operations = { .d_delete = always_delete_dentry, .d_dname = ns_dname, };
@@ -160,7 +163,10 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int buflif (!ns) goto out_put_task; -snprintf (name,sizeof (name),"%s:[%u]" , ns_ops->name, ns_ops->inum (ns)); +if (strstr (dentry->d_iname,"_snum" )) +snprintf (name,sizeof (name),"%s_snum:[%llx]" , ns_ops->name, ns_ops->snum (ns)); +else +snprintf (name,sizeof (name),"%s:[%u]" , ns_ops->name, ns_ops->inum (ns)); len =strlen (name);if (len > buflen)
@@ -216,16 +222,23 @@ static int proc_ns_dir_readdir(struct file *file, struct dir_context *ctx)if (!dir_emit_dots (file, ctx)) goto out; -if (ctx->pos >=2 +ARRAY_SIZE (ns_entries)) +if (ctx->pos >=2 +2 *ARRAY_SIZE (ns_entries)) goto out; entry = ns_entries + (ctx->pos -2 ); last = &ns_entries[ARRAY_SIZE (ns_entries) -1 ];while (entry <= last) {const struct proc_ns_operations *ops = *entry; +char name[50 ]; +if (!proc_fill_cache (file, ctx, ops->name,strlen (ops->name), proc_ns_instantiate, task, ops))break ; ctx->pos++; +snprintf (name,sizeof (name),"%s_snum" , ops->name); +if (!proc_fill_cache (file, ctx, name,strlen (name), + proc_ns_instantiate, task, ops)) +break ; + ctx->pos++; entry++; } out:
@@ -253,9 +266,13 @@ static struct dentry *proc_ns_dir_lookup(struct inode *dir, last = &ns_entries[ARRAY_SIZE (ns_entries)];for (entry = ns_entries; entry < last; entry++) { -if (strlen ((*entry)->name) != len) +char name[50 ]; + +snprintf (name,sizeof (name),"%s_snum" , (*entry)->name); +if (strlen ((*entry)->name) != len &&strlen (name) != len)continue ; -if (!memcmp (dentry->d_name.name, (*entry)->name, len)) +if (!memcmp (dentry->d_name.name, (*entry)->name, len) + || !memcmp (dentry->d_name.name, name, len))break ; }if (entry == last)
Signature · 1 line
1.7.1
PATCH v3 4/6 namespaces: expose ns_entries
In reply to a message not in the archiveExpose ns_entries so subsystems other than proc can use this set of namespace operations.
--- fs/proc/namespaces.c | 2 +- include/linux/proc_ns.h | 1 + 2 files changed, 2 insertions(+), 1 deletions(-)
fs/proc/namespaces.c +1 -1
@@ -15,7 +15,7 @@#include "internal.h" -static const struct proc_ns_operations *ns_entries[] = { +const struct proc_ns_operations *ns_entries[] = { #ifdef CONFIG_NET_NS &netns_operations, #endif
include/linux/proc_ns.h +1 -0
@@ -28,6 +28,7 @@ extern const struct proc_ns_operations ipcns_operations;extern const struct proc_ns_operations pidns_operations;extern const struct proc_ns_operations userns_operations;extern const struct proc_ns_operations mntns_operations; +extern const struct proc_ns_operations *ns_entries[];/* * We always define these enumerators
Signature · 1 line
1.7.1
PATCH v3 5/6 audit: log namespace serial numbers
In reply to a message not in the archiveLog the namespace serial numbers of a task in audit_log_task_info() which is used by syscall audits, among others..
Idea first presented:
https://www.redhat.com/archives/linux-audit/2013-March/msg00020.html
Typical output format would look something like:
type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)
The serial numbers are printed in hex.
--- include/linux/audit.h | 7 +++++++ kernel/audit.c | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletions(-)
include/linux/audit.h +7 -0
@@ -101,6 +101,13 @@ extern int __weak audit_classify_compat_syscall(int abi, unsigned syscall);struct filename ;extern void audit_log_session_info (struct audit_buffer *ab); +#ifdef CONFIG_NAMESPACES +extern void audit_log_namespace_info (struct audit_buffer *ab,struct task_struct *tsk); +#else +void audit_log_namespace_info (struct audit_buffer *ab,struct task_struct *tsk) +{ +} +#endif #ifdef CONFIG_AUDIT_COMPAT_GENERIC #define audit_is_compat (arch) (!((arch) & __AUDIT_ARCH_64BIT))
kernel/audit.c +20 -1
@@ -64,7 +64,7 @@#endif #include <linux/freezer.h> #include <linux/tty.h> -#include <linux/pid_namespace.h> +#include <linux/proc_ns.h> #include <net/netns/generic.h> #include "audit.h"
@@ -1617,6 +1617,24 @@ void audit_log_session_info(struct audit_buffer *ab)audit_log_format (ab," auid=%u ses=%u" , auid, sessionid); } +#ifdef CONFIG_NAMESPACES +void audit_log_namespace_info (struct audit_buffer *ab,struct task_struct *tsk) +{ +const struct proc_ns_operations **entry; +bool end = false; + +if (!tsk) +return ; +for (entry = ns_entries; !end; entry++) { +void *ns = (*entry)->get (tsk); +audit_log_format (ab," %sns=%llx" , (*entry)->name, + (*entry)->snum (ns)); + (*entry)->put (ns); + end = (*entry)->type ==CLONE_NEWNS ; + } +} +#endif /* CONFIG_NAMESPACES */ +void audit_log_key (struct audit_buffer *ab,char *key) {audit_log_format (ab," key=" );
@@ -1861,6 +1879,7 @@ void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)up_read (&mm->mmap_sem); }else audit_log_format (ab," exe=(null)" ); +audit_log_namespace_info (ab, tsk);audit_log_task_context (ab); }EXPORT_SYMBOL (audit_log_task_info);
Signature · 1 line
1.7.1
PATCH v3 4/6 namespaces: expose ns_entries
In reply to Richard Guy BriggsExpose ns_entries so subsystems other than proc can use this set of namespace operations.
--- fs/proc/namespaces.c | 2 +- include/linux/proc_ns.h | 1 + 2 files changed, 2 insertions(+), 1 deletions(-)
fs/proc/namespaces.c +1 -1
@@ -15,7 +15,7 @@#include "internal.h" -static const struct proc_ns_operations *ns_entries[] = { +const struct proc_ns_operations *ns_entries[] = { #ifdef CONFIG_NET_NS &netns_operations, #endif
include/linux/proc_ns.h +1 -0
@@ -28,6 +28,7 @@ extern const struct proc_ns_operations ipcns_operations;extern const struct proc_ns_operations pidns_operations;extern const struct proc_ns_operations userns_operations;extern const struct proc_ns_operations mntns_operations; +extern const struct proc_ns_operations *ns_entries[];/* * We always define these enumerators
Signature · 1 line
1.7.1
PATCH v3 5/6 audit: log namespace serial numbers
In reply to Richard Guy BriggsLog the namespace serial numbers of a task in audit_log_task_info() which is used by syscall audits, among others..
Idea first presented:
https://www.redhat.com/archives/linux-audit/2013-March/msg00020.html
Typical output format would look something like:
type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)
The serial numbers are printed in hex.
--- include/linux/audit.h | 7 +++++++ kernel/audit.c | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletions(-)
include/linux/audit.h +7 -0
@@ -101,6 +101,13 @@ extern int __weak audit_classify_compat_syscall(int abi, unsigned syscall);struct filename ;extern void audit_log_session_info (struct audit_buffer *ab); +#ifdef CONFIG_NAMESPACES +extern void audit_log_namespace_info (struct audit_buffer *ab,struct task_struct *tsk); +#else +void audit_log_namespace_info (struct audit_buffer *ab,struct task_struct *tsk) +{ +} +#endif #ifdef CONFIG_AUDIT_COMPAT_GENERIC #define audit_is_compat (arch) (!((arch) & __AUDIT_ARCH_64BIT))
kernel/audit.c +20 -1
@@ -64,7 +64,7 @@#endif #include <linux/freezer.h> #include <linux/tty.h> -#include <linux/pid_namespace.h> +#include <linux/proc_ns.h> #include <net/netns/generic.h> #include "audit.h"
@@ -1617,6 +1617,24 @@ void audit_log_session_info(struct audit_buffer *ab)audit_log_format (ab," auid=%u ses=%u" , auid, sessionid); } +#ifdef CONFIG_NAMESPACES +void audit_log_namespace_info (struct audit_buffer *ab,struct task_struct *tsk) +{ +const struct proc_ns_operations **entry; +bool end = false; + +if (!tsk) +return ; +for (entry = ns_entries; !end; entry++) { +void *ns = (*entry)->get (tsk); +audit_log_format (ab," %sns=%llx" , (*entry)->name, + (*entry)->snum (ns)); + (*entry)->put (ns); + end = (*entry)->type ==CLONE_NEWNS ; + } +} +#endif /* CONFIG_NAMESPACES */ +void audit_log_key (struct audit_buffer *ab,char *key) {audit_log_format (ab," key=" );
@@ -1861,6 +1879,7 @@ void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)up_read (&mm->mmap_sem); }else audit_log_format (ab," exe=(null)" ); +audit_log_namespace_info (ab, tsk);audit_log_task_context (ab); }EXPORT_SYMBOL (audit_log_task_info);
Signature · 1 line
1.7.1
PATCH v3 6/6 audit: log creation and deletion of namespace instances
In reply to Richard Guy BriggsLog the creation and deletion of namespace instances in all 6 types of namespaces.
Two new audit message types have been introduced:
AUDIT_NS_INIT 1329 AUDIT_NS_DEL 1330
The output format should look roughly:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a res=1 type=NS_DEL msg=audit(1400217435.730:95): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 snum=a res=1
If non-zero, old_snum lists the namespace from which it was cloned. The types are CLONE_NEW* listed in include/uapi/linux/sched.h.
--- fs/namespace.c | 4 ++++ include/linux/audit.h | 8 ++++++++ include/uapi/linux/audit.h | 2 ++ ipc/namespace.c | 10 ++++++++++ kernel/audit.c | 32 ++++++++++++++++++++++++++++++++ kernel/pid_namespace.c | 10 ++++++++++ kernel/user_namespace.c | 9 +++++++++ kernel/utsname.c | 10 ++++++++++ net/core/net_namespace.c | 5 +++++ 9 files changed, 90 insertions(+), 0 deletions(-)
fs/namespace.c +4 -0
@@ -24,6 +24,7 @@#include <linux/proc_ns.h> #include <linux/magic.h> #include <linux/bootmem.h> +#include <linux/audit.h> #include "pnode.h" #include "internal.h"
@@ -2445,6 +2446,7 @@ dput_out:static void free_mnt_ns (struct mnt_namespace *ns) { +audit_log_ns_del (CLONE_NEWNS , ns->serial_num);proc_free_inum (ns->proc_inum);put_user_ns (ns->user_ns);kfree (ns);
@@ -2505,6 +2507,7 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns, new_ns =alloc_mnt_ns (user_ns);if (IS_ERR (new_ns))return new_ns; +audit_log_ns_init (CLONE_NEWNS , ns->serial_num, new_ns->serial_num);namespace_lock ();/* First pass: copy the tree topology */
@@ -2568,6 +2571,7 @@ static struct mnt_namespace *create_mnt_ns(struct vfsmount *m) mnt->mnt_ns = new_ns; new_ns->root = mnt;list_add (&mnt->mnt_list, &new_ns->list); +audit_log_ns_init (CLONE_NEWNS ,0 , new_ns->serial_num); }else {mntput (m); }
include/linux/audit.h +8 -0
@@ -466,6 +466,9 @@ extern void audit_log_key(struct audit_buffer *ab, char *key);extern void audit_log_link_denied (const char *operation,struct path *link); +extern int audit_log_ns_init (int type,long long old_snum, +long long snum); +extern int audit_log_ns_del (int type,long long snum);extern void audit_log_lost (const char *message);#ifdef CONFIG_SECURITY extern void audit_log_secctx (struct audit_buffer *ab,u32 secid);
@@ -524,6 +527,11 @@ static inline void audit_log_key(struct audit_buffer *ab, char *key)static inline void audit_log_link_denied (const char *string,const struct path *link) { } +static inline int audit_log_ns_init (int type,long long old_snum, +long long snum) +{ } +static inline int audit_log_ns_del (int type,long long snum) +{ }static inline void audit_log_secctx (struct audit_buffer *ab,u32 secid) { }static inline int audit_log_task_context (struct audit_buffer *ab)
include/uapi/linux/audit.h +2 -0
@@ -110,6 +110,8 @@#define AUDIT_SECCOMP 1326/* Secure Computing event */ #define AUDIT_PROCTITLE 1327/* Proctitle emit event */ #define AUDIT_FEATURE_CHANGE 1328/* audit log listing feature changes */ +#define AUDIT_NS_INIT 1329/* Record namespace instance creation */ +#define AUDIT_NS_DEL 1330/* Record namespace instance deletion */ #define AUDIT_AVC 1400/* SE Linux avc denial or grant */ #define AUDIT_SELINUX_ERR 1401/* Internal SE Linux Errors */
ipc/namespace.c +10 -0
@@ -13,6 +13,7 @@#include <linux/mount.h> #include <linux/user_namespace.h> #include <linux/proc_ns.h> +#include <linux/audit.h> #include "util.h"
@@ -42,6 +43,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,atomic_inc (&nr_ipc_ns); ns->serial_num =ns_serial (); +audit_log_ns_init (CLONE_NEWIPC , old_ns->serial_num, ns->serial_num);sem_init_ns (ns);msg_init_ns (ns);
@@ -121,6 +123,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)*/ ipcns_notify (IPCNS_REMOVED );put_user_ns (ns->user_ns); +audit_log_ns_del (CLONE_NEWIPC , ns->serial_num);proc_free_inum (ns->proc_inum);kfree (ns); }
@@ -207,3 +210,10 @@ const struct proc_ns_operations ipcns_operations = { .inum = ipcns_inum, .snum = ipcns_snum, }; + +static int __init ipc_namespaces_init (void ) +{ +return audit_log_ns_init (CLONE_NEWIPC ,0 , init_ipc_ns.serial_num); +} + +late_initcall (ipc_namespaces_init);
kernel/audit.c +32 -0
@@ -1917,6 +1917,38 @@ out: }/** +* audit_log_ns_init - report a namespace instance creation +* @type: type of namespace instance created +* @old_snum: the serial number of the cloned namespace instance +* @snum: the serial number of the new namespace instance +*/ +int audit_log_ns_init (int type,long long old_snum,long long snum) +{ +struct audit_buffer *ab; + +audit_log_common_recv_msg (&ab,AUDIT_NS_INIT ); +audit_log_format (ab," type=%x old_snum=%llx snum=%llx res=1" , + type, old_snum, snum); +audit_log_end (ab); +return 0 ; +} + +/** +* audit_log_ns_del - report a namespace instance deleted +* @type: type of namespace instance deleted +* @snum: the serial number of the namespace instance +*/ +int audit_log_ns_del (int type,long long snum) +{ +struct audit_buffer *ab; + +audit_log_common_recv_msg (&ab,AUDIT_NS_DEL ); +audit_log_format (ab," type=%x snum=%llx res=1" , type, snum); +audit_log_end (ab); +return 0 ; +} + +/** * audit_log_end - end one audit record * @ab: the audit_buffer *
kernel/pid_namespace.c +10 -0
@@ -18,6 +18,7 @@#include <linux/proc_ns.h> #include <linux/reboot.h> #include <linux/export.h> +#include <linux/audit.h> struct pid_cache {int nr_ids;
@@ -110,6 +111,8 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns goto out_free_map; ns->serial_num =ns_serial (); +audit_log_ns_init (CLONE_NEWPID , parent_pid_ns->serial_num, + ns->serial_num);kref_init (&ns->kref); ns->level = level;
@@ -144,6 +147,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns) {int i; +audit_log_ns_del (CLONE_NEWPID , ns->serial_num);proc_free_inum (ns->proc_inum);for (i =0 ; i <PIDMAP_ENTRIES ; i++)kfree (ns->pidmap[i].page);
@@ -395,3 +399,9 @@ static __init int pid_namespaces_init(void) }__initcall (pid_namespaces_init); + +static __init int pid_namespaces_late_init (void ) +{ +return audit_log_ns_init (CLONE_NEWPID ,0 , init_pid_ns.serial_num); +} +late_initcall (pid_namespaces_late_init);
kernel/user_namespace.c +9 -0
@@ -22,6 +22,7 @@#include <linux/ctype.h> #include <linux/projid.h> #include <linux/fs_struct.h> +#include <linux/audit.h> static struct kmem_cache *user_ns_cachep__read_mostly ;
@@ -93,6 +94,7 @@ int create_user_ns(struct cred *new) } ns->serial_num =ns_serial (); +audit_log_ns_init (CLONE_NEWUSER , parent_ns->serial_num, ns->serial_num);atomic_set (&ns->count,1 );/* Leave the new->user_ns reference with the new user namespace. */
@@ -138,6 +140,7 @@ void free_user_ns(struct user_namespace *ns)#ifdef CONFIG_PERSISTENT_KEYRINGS key_put (ns->persistent_keyring_register);#endif +audit_log_ns_del (CLONE_NEWUSER , ns->serial_num);proc_free_inum (ns->proc_inum);kmem_cache_free (user_ns_cachep, ns); ns = parent;
@@ -912,3 +915,9 @@ static __init int user_namespaces_init(void)return 0 ; }module_init (user_namespaces_init); + +static __init int user_namespaces_late_init (void ) +{ +return audit_log_ns_init (CLONE_NEWUSER ,0 , init_user_ns.serial_num); +} +late_initcall (user_namespaces_late_init);
kernel/utsname.c +10 -0
@@ -16,6 +16,7 @@#include <linux/slab.h> #include <linux/user_namespace.h> #include <linux/proc_ns.h> +#include <linux/audit.h> static struct uts_namespace *create_uts_ns (void ) {
@@ -49,6 +50,7 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns, } ns->serial_num =ns_serial (); +audit_log_ns_init (CLONE_NEWUTS , old_ns->serial_num, ns->serial_num);down_read (&uts_sem);memcpy (&ns->name, &old_ns->name,sizeof (ns->name));
@@ -86,6 +88,7 @@ void free_uts_ns(struct kref *kref) ns = container_of(kref, struct uts_namespace, kref);put_user_ns (ns->user_ns); +audit_log_ns_del (CLONE_NEWUTS , ns->serial_num);proc_free_inum (ns->proc_inum);kfree (ns); }
@@ -148,3 +151,10 @@ const struct proc_ns_operations utsns_operations = { .inum = utsns_inum, .snum = utsns_snum, }; + +static int __init uts_namespaces_init (void ) +{ +return audit_log_ns_init (CLONE_NEWUTS ,0 , init_uts_ns.serial_num); +} + +late_initcall (uts_namespaces_init);
net/core/net_namespace.c +5 -0
@@ -17,6 +17,7 @@#include <linux/user_namespace.h> #include <net/net_namespace.h> #include <net/netns/generic.h> +#include <linux/audit.h> /* * Our network namespace constructor/destructor lists
@@ -253,6 +254,8 @@ struct net *copy_net_ns(unsigned long flags,mutex_lock (&net_mutex); rv =setup_net (net, user_ns);if (rv ==0 ) { +audit_log_ns_init (CLONE_NEWNET , old_net->serial_num, + net->serial_num);rtnl_lock ();list_add_tail_rcu (&net->list, &net_namespace_list);rtnl_unlock ();
@@ -395,6 +398,7 @@ static __net_init int net_ns_net_init(struct net *net) static __net_exit void net_ns_net_exit(struct net *net) { +audit_log_ns_del (CLONE_NEWNET , net->serial_num);proc_free_inum (net->proc_inum); }
@@ -428,6 +432,7 @@ static int __init net_ns_init(void)if (setup_net (&init_net, &init_user_ns))panic ("Could not setup the initial network namespace" ); +audit_log_ns_init (CLONE_NEWNET ,0 , init_net.serial_num);rtnl_lock ();list_add_tail_rcu (&init_net.list, &net_namespace_list);rtnl_unlock ();
Signature · 1 line
1.7.1
Eric Paris
maintainerQuoted 27 lines · Richard Guy Briggs
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
1/6 defines a function to generate them and assigns them.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs). It could be argued that the inode numbers have now become a defacto interface and can't change now, but I'm proposing this approach to see if this helps address some of the objections to the earlier patchset.
2/6 adds access functions to get to the serial numbers in a similar way to inode access for namespace proc operations.
3/6 implements, as suggested by Serge Hallyn, making these serial numbers available in
/proc/self/ns/{ipc,mnt,net,pid,user,uts}_snum. I chose "snum" instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.4/6 exposes proc's ns entries structure which lists a number of useful operations per namespace type for other subsystems to use.
5/6 provides an example of usage for
audit_log_task_info()which is used by syscall audits, among others.audit_log_task()andaudit_common_recv_message()would be other potential use cases.
Quoted 5 lines
Proposed output format:
This differs slightly from Aristeu's patch because of the label conflict with "pid=" due to including it in existing records rather than it being a seperate record. The serial numbers are printed in hex.type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)
I'm undecided if I'd rather see this as a separate NS_INFO record type. It would mean we could filter them out of the logs...
Do we print out lots of pidns=0 for tasks not in a newly created NS? Do we want to?
Quoted 6 lines
6/6 tracks the creation and deletion of of namespaces, listing the type of namespace instance, related namespace id if there is one and the newly minted serial number.
Proposed output format:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a1 res=1
I'd love to be able to grep for netns=20 and find both the NS_INIT and the SYSCALL/NS_INFO records, instead of having them named different things. So basically I think you want to translate the type= into a string for the old_X= and X=...
Quoted 28 lines · Eric Paris
Quoted 27 lines · Richard Guy Briggs
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
1/6 defines a function to generate them and assigns them.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs). It could be argued that the inode numbers have now become a defacto interface and can't change now, but I'm proposing this approach to see if this helps address some of the objections to the earlier patchset.
2/6 adds access functions to get to the serial numbers in a similar way to inode access for namespace proc operations.
3/6 implements, as suggested by Serge Hallyn, making these serial numbers available in
/proc/self/ns/{ipc,mnt,net,pid,user,uts}_snum. I chose "snum" instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.4/6 exposes proc's ns entries structure which lists a number of useful operations per namespace type for other subsystems to use.
5/6 provides an example of usage for
audit_log_task_info()which is used by syscall audits, among others.audit_log_task()andaudit_common_recv_message()would be other potential use cases.
Quoted 8 lines
Quoted 5 lines
Proposed output format:
This differs slightly from Aristeu's patch because of the label conflict with "pid=" due to including it in existing records rather than it being a seperate record. The serial numbers are printed in hex.type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)I'm undecided if I'd rather see this as a separate
NS_INFOrecord type. It would mean we could filter them out of the logs...
I don't have a strong opinion either way. Steve G.'s opinion would be helpful here.
Quoted 2 lines
Do we print out lots of pidns=0 for tasks not in a newly created NS? Do we want to?
There is no "pidns=0", but I understand your point. This would come back to Steve G.'s point about disappearing fields, and the value of having it as a seperate record that could be filtered.
Quoted 11 lines
Quoted 6 lines
6/6 tracks the creation and deletion of of namespaces, listing the type of namespace instance, related namespace id if there is one and the newly minted serial number.
Proposed output format:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a1 res=1I'd love to be able to grep for netns=20 and find both the
NS_INITand the SYSCALL/NS_INFO records, instead of having them named different things. So basically I think you want to translate the type= into a string for the old_X= and X=...
That actually makes a bit more sense, and we could do away with the "type=" field since the "Xns=" fields are self-describing.
Any hints on the timing issues mentioned in one of the notes? I'm missing initial mntns and netns messages.
- RGB
--
Richard Guy Briggs <[email protected]> Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
Quoted 4 lines · Richard Guy Briggs
Quoted 3 lines · Eric Paris
Quoted 2 lines · Richard Guy Briggs
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
(Including the Linux API list due to the additions to /proc/<pid>/ns/. Please see http://www.kernelhub.org/?p=2&msg=477668 and in particular
http://www.kernelhub.org/?msg=477678&p=2 )
<snip>
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
5/6 provides an example of usage for
audit_log_task_info()which is used by syscall audits, among others.audit_log_task()andaudit_common_recv_message()would be other potential use cases.Proposed output format:
This differs slightly from Aristeu's patch because of the label conflict with "pid=" due to including it in existing records rather than it being a seperate record. The serial numbers are printed in hex.type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)
Quoted 5 lines
Quoted 2 lines
I'm undecided if I'd rather see this as a separate
NS_INFOrecord type. It would mean we could filter them out of the logs...I don't have a strong opinion either way. Steve G.'s opinion would be helpful here.
Breaking this out into a seperate record type would mean calling audit_log_namespace_info() from the callers of audit_log_task_info() (presently audit_log_link_denied(), ima_audit_measurement(), audit_log_exit() ), but would make it easier to emit with other record types.
Quoted 14 lines
Quoted 2 lines
Do we print out lots of pidns=0 for tasks not in a newly created NS? Do we want to?
There is no "pidns=0", but I understand your point. This would come back to Steve G.'s point about disappearing fields, and the value of having it as a seperate record that could be filtered.
Quoted 7 lines
Quoted 6 lines
6/6 tracks the creation and deletion of of namespaces, listing the type of namespace instance, related namespace id if there is one and the newly minted serial number.
Proposed output format:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a1 res=1
Quoted 7 lines
Quoted 4 lines
I'd love to be able to grep for netns=20 and find both the
NS_INITand the SYSCALL/NS_INFO records, instead of having them named different things. So basically I think you want to translate the type= into a string for the old_X= and X=...That actually makes a bit more sense, and we could do away with the "type=" field since the "Xns=" fields are self-describing.
Steve, how do you feel about this since the NS_INIT/NS_DEL record type would have changing fields amongst the 6 namespace types. Only one of the 6 would be present in each message. I suppose we could have an NS_INIT_XXX/NS_DEL_XXX for each namespace type.
Quoted 1 line
- RGB
- RGB
--
Richard Guy Briggs <[email protected]> Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
Quoted 9 lines · Richard Guy Briggs
Quoted 4 lines · Richard Guy Briggs
Quoted 3 lines · Eric Paris
Quoted 2 lines · Richard Guy Briggs
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
(Including the Linux API list due to the additions to /proc/<pid>/ns/. Please see http://www.kernelhub.org/?p=2&msg=477668 and in particular
http://www.kernelhub.org/?msg=477678&p=2 )
Sigh if you have to use something like this use the proc inode number. It is the same thing.
I hate to claim it is unique absent of the proc superblock but it is and will be for the forseable future.
It would be better to include the block device number that appears in proc of 3h of the primary mount of to qualify the number. But it is not particularly important. Coming up with an additional unique number that needs to be maintained seems stronlgy silly.
Eric
Quoted 60 lines
<snip>
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
5/6 provides an example of usage for
audit_log_task_info()which is used by syscall audits, among others.audit_log_task()andaudit_common_recv_message()would be other potential use cases.Proposed output format:
This differs slightly from Aristeu's patch because of the label conflict with "pid=" due to including it in existing records rather than it being a seperate record. The serial numbers are printed in hex.type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)Quoted 5 lines
Quoted 2 lines
I'm undecided if I'd rather see this as a separate
NS_INFOrecord type. It would mean we could filter them out of the logs...I don't have a strong opinion either way. Steve G.'s opinion would be helpful here.
Breaking this out into a seperate record type would mean calling
audit_log_namespace_info()from the callers ofaudit_log_task_info()(presentlyaudit_log_link_denied(),ima_audit_measurement(),audit_log_exit()), but would make it easier to emit with other record types.Quoted 14 lines
Quoted 2 lines
Do we print out lots of pidns=0 for tasks not in a newly created NS? Do we want to?
There is no "pidns=0", but I understand your point. This would come back to Steve G.'s point about disappearing fields, and the value of having it as a seperate record that could be filtered.
Quoted 7 lines
Quoted 6 lines
6/6 tracks the creation and deletion of of namespaces, listing the type of namespace instance, related namespace id if there is one and the newly minted serial number.
Proposed output format:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a1 res=1Quoted 7 lines
Quoted 4 lines
I'd love to be able to grep for netns=20 and find both the
NS_INITand the SYSCALL/NS_INFO records, instead of having them named different things. So basically I think you want to translate the type= into a string for the old_X= and X=...That actually makes a bit more sense, and we could do away with the "type=" field since the "Xns=" fields are self-describing.
Steve, how do you feel about this since the NS_INIT/NS_DEL record type would have changing fields amongst the 6 namespace types. Only one of the 6 would be present in each message. I suppose we could have an NS_INIT_XXX/NS_DEL_XXX for each namespace type.
Quoted 1 line
- RGB
- RGB
--
Richard Guy Briggs <[email protected]> Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
Quoted 15 lines · Eric W. Biederman
Quoted 9 lines · Richard Guy Briggs
Quoted 4 lines · Richard Guy Briggs
Quoted 3 lines · Eric Paris
Quoted 2 lines · Richard Guy Briggs
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
(Including the Linux API list due to the additions to /proc/<pid>/ns/. Please see http://www.kernelhub.org/?p=2&msg=477668 and in particular
http://www.kernelhub.org/?msg=477678&p=2 )Sigh if you have to use something like this use the proc inode number. It is the same thing.
Quoted 7 lines
I hate to claim it is unique absent of the proc superblock but it is and will be for the forseable future.
It would be better to include the block device number that appears in proc of 3h of the primary mount of to qualify the number. But it is not particularly important. Coming up with an additional unique number that needs to be maintained seems stronlgy silly.
I am reading a contradiction here:
https://www.redhat.com/archives/linux-audit/2013-March/msg00032.html
and this posting went completely ignored:
https://www.redhat.com/archives/linux-audit/2014-January/msg00180.html
And then there was this patchset and thread where there was some good discussion to clarify the use case:
https://lkml.org/lkml/2014/4/22/662
Then V2:
https://lkml.org/lkml/2014/5/9/637
Then V3 3 months ago:
https://www.redhat.com/archives/linux-audit/2014-May/msg00071.html
I'm about to post another version of the patchset addressing Eric Paris' concerns about record types, field naming...
Quoted 62 lines
Eric
Quoted 60 lines
<snip>
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
5/6 provides an example of usage for
audit_log_task_info()which is used by syscall audits, among others.audit_log_task()andaudit_common_recv_message()would be other potential use cases.Proposed output format:
This differs slightly from Aristeu's patch because of the label conflict with "pid=" due to including it in existing records rather than it being a seperate record. The serial numbers are printed in hex.type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)Quoted 5 lines
Quoted 2 lines
I'm undecided if I'd rather see this as a separate
NS_INFOrecord type. It would mean we could filter them out of the logs...I don't have a strong opinion either way. Steve G.'s opinion would be helpful here.
Breaking this out into a seperate record type would mean calling
audit_log_namespace_info()from the callers ofaudit_log_task_info()(presentlyaudit_log_link_denied(),ima_audit_measurement(),audit_log_exit()), but would make it easier to emit with other record types.Quoted 14 lines
Quoted 2 lines
Do we print out lots of pidns=0 for tasks not in a newly created NS? Do we want to?
There is no "pidns=0", but I understand your point. This would come back to Steve G.'s point about disappearing fields, and the value of having it as a seperate record that could be filtered.
Quoted 7 lines
Quoted 6 lines
6/6 tracks the creation and deletion of of namespaces, listing the type of namespace instance, related namespace id if there is one and the newly minted serial number.
Proposed output format:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a1 res=1Quoted 7 lines
Quoted 4 lines
I'd love to be able to grep for netns=20 and find both the
NS_INITand the SYSCALL/NS_INFO records, instead of having them named different things. So basically I think you want to translate the type= into a string for the old_X= and X=...That actually makes a bit more sense, and we could do away with the "type=" field since the "Xns=" fields are self-describing.
Steve, how do you feel about this since the NS_INIT/NS_DEL record type would have changing fields amongst the 6 namespace types. Only one of the 6 would be present in each message. I suppose we could have an NS_INIT_XXX/NS_DEL_XXX for each namespace type.
Quoted 1 line
- RGB
- RGB
--
Richard Guy Briggs <[email protected]> Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
- RGB
--
Richard Guy Briggs <[email protected]> Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
Quoted 34 lines · Richard Guy Briggs
Quoted 15 lines · Eric W. Biederman
Quoted 9 lines · Richard Guy Briggs
Quoted 4 lines · Richard Guy Briggs
Quoted 3 lines · Eric Paris
Quoted 2 lines · Richard Guy Briggs
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
(Including the Linux API list due to the additions to /proc/<pid>/ns/. Please see http://www.kernelhub.org/?p=2&msg=477668 and in particular
http://www.kernelhub.org/?msg=477678&p=2 )Sigh if you have to use something like this use the proc inode number. It is the same thing.
Quoted 7 lines
I hate to claim it is unique absent of the proc superblock but it is and will be for the forseable future.
It would be better to include the block device number that appears in proc of 3h of the primary mount of to qualify the number. But it is not particularly important. Coming up with an additional unique number that needs to be maintained seems stronlgy silly.
I am reading a contradiction here:
https://www.redhat.com/archives/linux-audit/2013-March/msg00032.htmland this posting went completely ignored:
https://www.redhat.com/archives/linux-audit/2014-January/msg00180.htmlAnd then there was this patchset and thread where there was some good discussion to clarify the use case:
https://lkml.org/lkml/2014/4/22/662
Quoted 8 lines
Then V2:
https://lkml.org/lkml/2014/5/9/637Then V3 3 months ago:
https://www.redhat.com/archives/linux-audit/2014-May/msg00071.htmlI'm about to post another version of the patchset addressing Eric Paris' concerns about record types, field naming...
I also try to find a solution to identify netns in userland to solve
some network problems (see http://thread.gmane.org/gmane.linux.network/315933/focus=321753).
This serial number solution may be reused for this. We really need to find a way to solve this.
Regards,
Nicolas
A message that is not in the archive (sent off-list or not yet received): 20140819164617.GE9003-bcJWsdo4jJjeVoXN4CMphl7TgLCtbB0G@public.gmane.org
Quoted 9 lines · Richard Guy Briggs
Quoted 4 lines · Richard Guy Briggs
Quoted 3 lines · Eric Paris
Quoted 2 lines · Richard Guy Briggs
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
(Including the Linux API list due to the additions to /proc/<pid>/ns/. Please see http://www.kernelhub.org/?p=2&msg=477668 and in particular
http://www.kernelhub.org/?msg=477678&p=2 )
Sigh if you have to use something like this use the proc inode number. It is the same thing.
I hate to claim it is unique absent of the proc superblock but it is and will be for the forseable future.
It would be better to include the block device number that appears in proc of 3h of the primary mount of to qualify the number. But it is not particularly important. Coming up with an additional unique number that needs to be maintained seems stronlgy silly.
Eric
Quoted 60 lines
<snip>
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
5/6 provides an example of usage for
audit_log_task_info()which is used by syscall audits, among others.audit_log_task()andaudit_common_recv_message()would be other potential use cases.Proposed output format:
This differs slightly from Aristeu's patch because of the label conflict with "pid=" due to including it in existing records rather than it being a seperate record. The serial numbers are printed in hex.type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)Quoted 5 lines
Quoted 2 lines
I'm undecided if I'd rather see this as a separate
NS_INFOrecord type. It would mean we could filter them out of the logs...I don't have a strong opinion either way. Steve G.'s opinion would be helpful here.
Breaking this out into a seperate record type would mean calling
audit_log_namespace_info()from the callers ofaudit_log_task_info()(presentlyaudit_log_link_denied(),ima_audit_measurement(),audit_log_exit()), but would make it easier to emit with other record types.Quoted 14 lines
Quoted 2 lines
Do we print out lots of pidns=0 for tasks not in a newly created NS? Do we want to?
There is no "pidns=0", but I understand your point. This would come back to Steve G.'s point about disappearing fields, and the value of having it as a seperate record that could be filtered.
Quoted 7 lines
Quoted 6 lines
6/6 tracks the creation and deletion of of namespaces, listing the type of namespace instance, related namespace id if there is one and the newly minted serial number.
Proposed output format:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a1 res=1Quoted 7 lines
Quoted 4 lines
I'd love to be able to grep for netns=20 and find both the
NS_INITand the SYSCALL/NS_INFO records, instead of having them named different things. So basically I think you want to translate the type= into a string for the old_X= and X=...That actually makes a bit more sense, and we could do away with the "type=" field since the "Xns=" fields are self-describing.
Steve, how do you feel about this since the NS_INIT/NS_DEL record type would have changing fields amongst the 6 namespace types. Only one of the 6 would be present in each message. I suppose we could have an NS_INIT_XXX/NS_DEL_XXX for each namespace type.
Quoted 1 line
- RGB
- RGB
--
Richard Guy Briggs <[email protected]> Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
Richard,
Quoted 15 lines · Richard Guy Briggs
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
1/6 defines a function to generate them and assigns them.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs). It could be argued that the inode numbers have now become a defacto interface and can't change now, but I'm proposing this approach to see if this helps address some of the objections to the earlier patchset.
2/6 adds access functions to get to the serial numbers in a similar way to inode access for namespace proc operations.
Quoted 7 lines
3/6 implements, as suggested by Serge Hallyn, making these serial numbers available in
/proc/self/ns/{ipc,mnt,net,pid,user,uts}_snum. I chose "snum" instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.4/6 exposes proc's ns entries structure which lists a number of useful operations per namespace type for other subsystems to use.
Since the 3 and 4 change the ABI, please CC iterations of this patch series to [email protected], as per Documentation/SubmitChecklist.
Cheers,
Michael
Quoted 106 lines
5/6 provides an example of usage for
audit_log_task_info()which is used by syscall audits, among others.audit_log_task()andaudit_common_recv_message()would be other potential use cases.Proposed output format:
This differs slightly from Aristeu's patch because of the label conflict with "pid=" due to including it in existing records rather than it being a seperate record. The serial numbers are printed in hex.type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)6/6 tracks the creation and deletion of of namespaces, listing the type of namespace instance, related namespace id if there is one and the newly minted serial number.
Proposed output format:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a1 res=1 type=NS_DEL msg=audit(1400217435.730:95): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 snum=a1 res=1v2 -> v3:
Useatomic64_tinns_serialto simplify it.
Avoid funciton duplication in proc, keying on dentry. Squash down audit patch to avoid rcu sleep issues. Add tracking for creation and deletion of namespace instances.v1 -> v2:
Avoid rollover by switching from an int to a long long. Change rollover behaviour from simply avoiding zero to raising a BUG. Expose serial numbers in /proc/<pid>/ns/*_snum.
Exposens_entriesand use it in audit.Notes:
There has been some progress made for audit in net namespaces and pid namespaces since this previous thread. net namespaces are now served as peers by one auditd in theinit_netnamespace with processes in a non-init_net namespace being able to write records if they are in theinit_user_nsand haveCAP_AUDIT_WRITE. Processes in a non-init_pid_ns can now similarly write records. As forCAP_AUDIT_READ, I just posted a patchset to check capabilities of userspace processes that try to join netlink broadcast groups.This set does not try to solve the non-init namespace audit messages and auditd problem yet. That will come later, likely with additional auditd instances running in another namespace with a limited ability to influence the master auditd. I echo Eric B's idea that messages destined for different namespaces would have to be tailored for that namespace with references that make sense (such as the right pid number reported to that pid namespace, and not leaking info about parents or peers).
Bugs:
Patch 6/6 has a timing bug such that mnt and net namespace initial namespaces never get logged, I suspect because they are initialized before the audit subsystem. I've tried moving audit from__initcalltosubsys_initcall, but that doesn't help.Questions:
Is there a way to link serial numbers of namespaces involved in migration of a container to another kernel? It sounds like what is needed is a part of a mangement application that is able to pull the audit rcords from constituent hosts to build an audit trail of a container.What additional events should list this information?
Does this present any problematic information leaks? Only
CAP_AUDIT_CONTROL(and proposedCAP_AUDIT_READ) ininit_user_nscan get to this information in the init namespace at the moment from audit. *However*, the addition of the proc/<pid>/ns/*_snum does make it available to other processes now.Richard Guy Briggs (6):
namespaces: assign each namespace instance a serial number
namespaces: expose namespace instance serial number inproc_ns_operations
namespaces: expose ns instance serial numbers in proc
namespaces: exposens_entries
audit: log namespace serial numbers
audit: log creation and deletion of namespace instancesfs/mount.h | 1 + fs/namespace.c | 12 +++++++++ fs/proc/namespaces.c | 35 +++++++++++++++++++------- include/linux/audit.h | 15 +++++++++++ include/linux/ipc_namespace.h | 1 + include/linux/nsproxy.h | 8 ++++++ include/linux/pid_namespace.h | 1 + include/linux/proc_ns.h | 2 + include/linux/user_namespace.h | 1 + include/linux/utsname.h | 1 + include/net/net_namespace.h | 1 + include/uapi/linux/audit.h | 2 + init/version.c | 1 + ipc/msgutil.c | 1 + ipc/namespace.c | 20 +++++++++++++++ kernel/audit.c | 53 +++++++++++++++++++++++++++++++++++++++- kernel/nsproxy.c | 17 +++++++++++++ kernel/pid.c | 1 + kernel/pid_namespace.c | 19 ++++++++++++++ kernel/user.c | 1 + kernel/user_namespace.c | 18 +++++++++++++ kernel/utsname.c | 20 +++++++++++++++ net/core/net_namespace.c | 20 ++++++++++++++- 23 files changed, 240 insertions(+), 11 deletions(-)_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linuxfoundation.org/mailman/listinfo/containers
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Author of "The Linux Programming Interface", http://blog.man7.org/
Quoted 1 line · Michael Kerrisk
Richard,
Hi Michael,
Quoted 21 lines · Richard Guy Briggs
Quoted 20 lines
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
1/6 defines a function to generate them and assigns them.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs). It could be argued that the inode numbers have now become a defacto interface and can't change now, but I'm proposing this approach to see if this helps address some of the objections to the earlier patchset.
2/6 adds access functions to get to the serial numbers in a similar way to inode access for namespace proc operations.
3/6 implements, as suggested by Serge Hallyn, making these serial numbers available in
/proc/self/ns/{ipc,mnt,net,pid,user,uts}_snum. I chose "snum" instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.
Quoted 5 lines
Quoted 2 lines
4/6 exposes proc's ns entries structure which lists a number of useful operations per namespace type for other subsystems to use.
Since the 3 and 4 change the ABI, please CC iterations of this patch
series to [email protected], as perDocumentation/SubmitChecklist.
Neither patch 3/6 nor 4/6 changes the syscall interface.
Patch 3/6 adds /proc/<pid>/ns/ entries, which looks more like #16 in that document (for which /proc/<pid>/ns/<nstype> was never added).
Patch 4/6 adds internel kernel symbols which are never exposed to the user.
Perhaps "expose" was the wrong word to use in the patch description. This usage implies that it is no longer labelled "static" in its source files to be able to expose that interface to other internal kernel subsystems.
Ref:
SubmitChecklist (#16)
Documentation/stable_api_nonsense.txt
Documentation/ABI/README
Quoted 104 lines
Michael
Quoted 102 lines
5/6 provides an example of usage for
audit_log_task_info()which is used by syscall audits, among others.audit_log_task()andaudit_common_recv_message()would be other potential use cases.Proposed output format:
This differs slightly from Aristeu's patch because of the label conflict with "pid=" due to including it in existing records rather than it being a seperate record. The serial numbers are printed in hex.type=SYSCALL msg=audit(1399651071.433:72): arch=c000003e syscall=272 success=yes exit=0 a0=40000000 a1=ffffffffffffffff a2=0 a3=22 items=0 ppid=1 pid=483 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="(t-daemon)" exe="/usr/lib/systemd/systemd" netns=97 utsns=2 ipcns=1 pidns=4 userns=3 mntns=5 subj=system_u:system_r:init_t:s0 key=(null)6/6 tracks the creation and deletion of of namespaces, listing the type of namespace instance, related namespace id if there is one and the newly minted serial number.
Proposed output format:
type=NS_INIT msg=audit(1400217435.706:94): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 old_snum=0 snum=a1 res=1 type=NS_DEL msg=audit(1400217435.730:95): pid=524 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:mount_t:s0 type=20000 snum=a1 res=1v2 -> v3:
Useatomic64_tinns_serialto simplify it.
Avoid funciton duplication in proc, keying on dentry. Squash down audit patch to avoid rcu sleep issues. Add tracking for creation and deletion of namespace instances.v1 -> v2:
Avoid rollover by switching from an int to a long long. Change rollover behaviour from simply avoiding zero to raising a BUG. Expose serial numbers in /proc/<pid>/ns/*_snum.
Exposens_entriesand use it in audit.Notes:
There has been some progress made for audit in net namespaces and pid namespaces since this previous thread. net namespaces are now served as peers by one auditd in theinit_netnamespace with processes in a non-init_net namespace being able to write records if they are in theinit_user_nsand haveCAP_AUDIT_WRITE. Processes in a non-init_pid_ns can now similarly write records. As forCAP_AUDIT_READ, I just posted a patchset to check capabilities of userspace processes that try to join netlink broadcast groups.This set does not try to solve the non-init namespace audit messages and auditd problem yet. That will come later, likely with additional auditd instances running in another namespace with a limited ability to influence the master auditd. I echo Eric B's idea that messages destined for different namespaces would have to be tailored for that namespace with references that make sense (such as the right pid number reported to that pid namespace, and not leaking info about parents or peers).
Bugs:
Patch 6/6 has a timing bug such that mnt and net namespace initial namespaces never get logged, I suspect because they are initialized before the audit subsystem. I've tried moving audit from__initcalltosubsys_initcall, but that doesn't help.Questions:
Is there a way to link serial numbers of namespaces involved in migration of a container to another kernel? It sounds like what is needed is a part of a mangement application that is able to pull the audit rcords from constituent hosts to build an audit trail of a container.What additional events should list this information?
Does this present any problematic information leaks? Only
CAP_AUDIT_CONTROL(and proposedCAP_AUDIT_READ) ininit_user_nscan get to this information in the init namespace at the moment from audit. *However*, the addition of the proc/<pid>/ns/*_snum does make it available to other processes now.Richard Guy Briggs (6):
namespaces: assign each namespace instance a serial number
namespaces: expose namespace instance serial number inproc_ns_operations
namespaces: expose ns instance serial numbers in proc
namespaces: exposens_entries
audit: log namespace serial numbers
audit: log creation and deletion of namespace instancesfs/mount.h | 1 + fs/namespace.c | 12 +++++++++ fs/proc/namespaces.c | 35 +++++++++++++++++++------- include/linux/audit.h | 15 +++++++++++ include/linux/ipc_namespace.h | 1 + include/linux/nsproxy.h | 8 ++++++ include/linux/pid_namespace.h | 1 + include/linux/proc_ns.h | 2 + include/linux/user_namespace.h | 1 + include/linux/utsname.h | 1 + include/net/net_namespace.h | 1 + include/uapi/linux/audit.h | 2 + init/version.c | 1 + ipc/msgutil.c | 1 + ipc/namespace.c | 20 +++++++++++++++ kernel/audit.c | 53 +++++++++++++++++++++++++++++++++++++++- kernel/nsproxy.c | 17 +++++++++++++ kernel/pid.c | 1 + kernel/pid_namespace.c | 19 ++++++++++++++ kernel/user.c | 1 + kernel/user_namespace.c | 18 +++++++++++++ kernel/utsname.c | 20 +++++++++++++++ net/core/net_namespace.c | 20 ++++++++++++++- 23 files changed, 240 insertions(+), 11 deletions(-)
Quoted 11 lines
Quoted 4 lines
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linuxfoundation.org/mailman/listinfo/containersSignature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Author of "The Linux Programming Interface", http://blog.man7.org/
- RGB
--
Richard Guy Briggs <[email protected]> Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
Hi Richard
Quoted 26 lines · Richard Guy Briggs
Quoted 1 line · Michael Kerrisk
Richard,
Hi Michael,
Quoted 21 lines · Richard Guy Briggs
Quoted 20 lines
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
1/6 defines a function to generate them and assigns them.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs). It could be argued that the inode numbers have now become a defacto interface and can't change now, but I'm proposing this approach to see if this helps address some of the objections to the earlier patchset.
2/6 adds access functions to get to the serial numbers in a similar way to inode access for namespace proc operations.
3/6 implements, as suggested by Serge Hallyn, making these serial numbers available in
/proc/self/ns/{ipc,mnt,net,pid,user,uts}_snum. I chose "snum" instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
4/6 exposes proc's ns entries structure which lists a number of useful operations per namespace type for other subsystems to use.
Since the 3 and 4 change the ABI, please CC iterations of this patch
series to [email protected], as perDocumentation/SubmitChecklist.Neither patch 3/6 nor 4/6 changes the syscall interface.
(Agreed.)
Quoted 2 lines
Patch 3/6 adds /proc/<pid>/ns/ entries, which looks more like #16 in that document (for which /proc/<pid>/ns/<nstype> was never added).
But, that's a change to the surface that the kernel exposes to user space, right? If so, it is best CCed to linux-api.
Thanks,
Michael
Quoted 37 lines · Michael Kerrisk (man-pages)
Hi Richard
Quoted 26 lines · Richard Guy Briggs
Quoted 1 line · Michael Kerrisk
Richard,
Hi Michael,
Quoted 21 lines · Richard Guy Briggs
Quoted 20 lines
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
1/6 defines a function to generate them and assigns them.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs). It could be argued that the inode numbers have now become a defacto interface and can't change now, but I'm proposing this approach to see if this helps address some of the objections to the earlier patchset.
2/6 adds access functions to get to the serial numbers in a similar way to inode access for namespace proc operations.
3/6 implements, as suggested by Serge Hallyn, making these serial numbers available in
/proc/self/ns/{ipc,mnt,net,pid,user,uts}_snum. I chose "snum" instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
4/6 exposes proc's ns entries structure which lists a number of useful operations per namespace type for other subsystems to use.
Since the 3 and 4 change the ABI, please CC iterations of this patch
series to [email protected], as perDocumentation/SubmitChecklist.Neither patch 3/6 nor 4/6 changes the syscall interface.
Quoted 7 lines
(Agreed.)
Quoted 2 lines
Patch 3/6 adds /proc/<pid>/ns/ entries, which looks more like #16 in that document (for which /proc/<pid>/ns/<nstype> was never added).
But, that's a change to the surface that the kernel exposes to user space, right? If so, it is best CCed to linux-api.
Got it. Thanks!
Quoted 3 lines
Thanks,
Michael
- RGB
--
Richard Guy Briggs <[email protected]> Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
A message that is not in the archive (sent off-list or not yet received): CAKgNAkgfV5K6BWjibCVwzJE3GYfmAHNzk+aU05M0xEdrfZmzPg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 37 lines · Michael Kerrisk (man-pages)
Hi Richard
Quoted 26 lines · Richard Guy Briggs
Quoted 1 line · Michael Kerrisk
Richard,
Hi Michael,
Quoted 21 lines · Richard Guy Briggs
Quoted 20 lines
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
1/6 defines a function to generate them and assigns them.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs). It could be argued that the inode numbers have now become a defacto interface and can't change now, but I'm proposing this approach to see if this helps address some of the objections to the earlier patchset.
2/6 adds access functions to get to the serial numbers in a similar way to inode access for namespace proc operations.
3/6 implements, as suggested by Serge Hallyn, making these serial numbers available in
/proc/self/ns/{ipc,mnt,net,pid,user,uts}_snum. I chose "snum" instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
4/6 exposes proc's ns entries structure which lists a number of useful operations per namespace type for other subsystems to use.
Since the 3 and 4 change the ABI, please CC iterations of this patch
series to [email protected], as perDocumentation/SubmitChecklist.Neither patch 3/6 nor 4/6 changes the syscall interface.
Quoted 7 lines
(Agreed.)
Quoted 2 lines
Patch 3/6 adds /proc/<pid>/ns/ entries, which looks more like #16 in that document (for which /proc/<pid>/ns/<nstype> was never added).
But, that's a change to the surface that the kernel exposes to user space, right? If so, it is best CCed to linux-api.
Got it. Thanks!
Quoted 3 lines
Thanks,
Michael
- RGB
--
Richard Guy Briggs <[email protected]> Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
A message that is not in the archive (sent off-list or not yet received): 20140526165858.GC8079-bcJWsdo4jJjeVoXN4CMphl7TgLCtbB0G@public.gmane.org
Hi Richard
Quoted 26 lines · Richard Guy Briggs
Quoted 1 line · Michael Kerrisk
Richard,
Hi Michael,
Quoted 21 lines · Richard Guy Briggs
Quoted 20 lines
The purpose is to track namespaces in use by logged processes from the perspective of init_*_ns.
1/6 defines a function to generate them and assigns them.
Use a serial number per namespace (unique across one boot of one kernel) instead of the inode number (which is claimed to have had the right to change reserved and is not necessarily unique if there is more than one proc fs). It could be argued that the inode numbers have now become a defacto interface and can't change now, but I'm proposing this approach to see if this helps address some of the objections to the earlier patchset.
2/6 adds access functions to get to the serial numbers in a similar way to inode access for namespace proc operations.
3/6 implements, as suggested by Serge Hallyn, making these serial numbers available in
/proc/self/ns/{ipc,mnt,net,pid,user,uts}_snum. I chose "snum" instead of "seq" for consistency with inum and there are a number of other uses of "seq" in the namespace code.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
4/6 exposes proc's ns entries structure which lists a number of useful operations per namespace type for other subsystems to use.
Since the 3 and 4 change the ABI, please CC iterations of this patch
series to [email protected], as perDocumentation/SubmitChecklist.Neither patch 3/6 nor 4/6 changes the syscall interface.
(Agreed.)
Quoted 2 lines
Patch 3/6 adds /proc/<pid>/ns/ entries, which looks more like #16 in that document (for which /proc/<pid>/ns/<nstype> was never added).
But, that's a change to the surface that the kernel exposes to user space, right? If so, it is best CCed to linux-api.
Thanks,
Michael