Skip to contentSkip to conversation

Syslog are now containerized

PATCH In review Jean-Marc Pigeon 4 participants 12 messages Feb 11, 2010 – Feb 17, 2010 8 messages not in the archive Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Syslog are now containerized

Added syslog.c such container /proc/kmsg and host /proc/kmsg do not leak in each other.
Running rsyslog daemon within a container won't destroy host kernel messages.

---
 Makefile                       |    2 +-
 include/linux/syslog.h         |   29 ++++
 include/linux/user_namespace.h |    1 +
 kernel/Makefile                |    2 +-
 kernel/printk.c                |  292 ++++++++++++++++++----------------------
 kernel/syslog.c                |  157 +++++++++++++++++++++
 kernel/user.c                  |    6 +-
 kernel/user_namespace.c        |    9 ++
 8 files changed, 334 insertions(+), 164 deletions(-)
 create mode 100644 include/linux/syslog.h
 create mode 100644 kernel/syslog.c
Makefile +1 -1
index f8e02e9..4fec8dd 100644
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 6
 SUBLEVEL = 33
-EXTRAVERSION = -rc7
+EXTRAVERSION = -rc7		
 NAME = Man-Eating Seals of Antiquity
 
 # *DOCUMENTATION*
include/linux/syslog.h new file +29 -0
new file mode 100644
index 0000000..98c6898
@@ -0,0 +1,29 @@
+#ifndef _LINUX_SYSLOG_H
+#define _LINUX_SYSLOG_H
+#include	<linux/spinlock_types.h>
+
+struct syslog_ns {
+        wait_queue_head_t wait;
+	spinlock_t logbuf_lock;	/* access conflict locker				*/
+        unsigned log_start;	/* Index into log_buf: next char to be read by syslog() */
+        unsigned con_start;	/* Index into log_buf: next char to be sent to consoles */
+        unsigned log_end;	/* Index into log_buf: most-recently-written-char + 1	*/
+        unsigned logged_chars;	/* Number of chars produced since last read+clear access*/
+        unsigned buf_len;	/* buffer available space size				*/
+        char *buf;		/* allocated ring buffer				*/
+};
+
+/*
+ *  Static structure used by kernel
+ */
+extern struct syslog_ns init_kernel_syslog_ns;
+
+/*
+ * Syslog API
+ *
+ */
+extern struct syslog_ns *syslog_malloc(unsigned container_buf_len);
+extern struct syslog_ns *syslog_realloc(struct syslog_ns *syslog_ns, unsigned container_buf_len);
+extern struct syslog_ns *syslog_free(struct syslog_ns *syslog);
+extern struct syslog_ns *syslog_get_current(void);
+#endif /* _LINUX_SYSLOG_H */
include/linux/user_namespace.h +1 -0
index cc4f453..3d0c73e 100644
@@ -14,6 +14,7 @@ struct user_namespace {
 	struct hlist_head	uidhash_table[UIDHASH_SZ];
 	struct user_struct	*creator;
 	struct work_struct	destroyer;
+	struct syslog_ns        *syslog;
 };
 
 extern struct user_namespace init_user_ns;
kernel/Makefile +1 -1
index 864ff75..e20d64e 100644
@@ -2,7 +2,7 @@
 # Makefile for the linux kernel.
 #
 
-obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
+obj-y     = sched.o fork.o exec_domain.o panic.o printk.o syslog.o \
 	    cpu.o exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
 	    signal.o sys.o kmod.o workqueue.o pid.o \
kernel/printk.c +131 -161

570 lines not on this page · raw message

kernel/syslog.c new file +157 -0

157 lines not on this page · raw message

kernel/user.c +5 -1
index 46d0165..cb2d4ba 100644
@@ -16,13 +16,17 @@
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/user_namespace.h>
+#include <linux/syslog.h>
 #include "cred-internals.h"
 
 struct user_namespace init_user_ns = {
 	.kref = {
 		.refcount	= ATOMIC_INIT(2),
 	},
-	.creator = &root_user,
+#ifdef CONFIG_PRINTK
+	.syslog = &init_kernel_syslog_ns,
+#endif
+	.creator = &root_user
 };
 EXPORT_SYMBOL_GPL(init_user_ns);
 
kernel/user_namespace.c +9 -0
index 076c7c8..9d8014f 100644
@@ -10,6 +10,7 @@
 #include <linux/slab.h>
 #include <linux/user_namespace.h>
 #include <linux/cred.h>
+#include <linux/syslog.h>
 
 /*
  * Create a new user namespace, deriving the creator from the user in the
@@ -21,6 +22,8 @@
  */
 int create_user_ns(struct cred *new)
 {
+#define	CONTAINER_BUF_LEN	4096	/*should be enough for container syslog	*/
+
 	struct user_namespace *ns;
 	struct user_struct *root_user;
 	int n;
@@ -34,6 +37,12 @@ int create_user_ns(struct cred *new)
 	for (n = 0; n < UIDHASH_SZ; ++n)
 		INIT_HLIST_HEAD(ns->uidhash_table + n);
 
+	
+	ns->syslog = syslog_malloc(CONTAINER_BUF_LEN);
+        if (!ns->syslog) {
+                kfree(ns);
+                return -ENOMEM;
+        }
 	/* Alloc new root user.  */
 	root_user = alloc_uid(ns, 0);
 	if (!root_user) {
Signature · 1 line
1.6.6

A message that is not in the archive (sent off-list or not yet received): 201002110552.o1B5qwbL024561-X4ZF2iejbABnc3BsFfMrZw@public.gmane.org

#2 lore raw
Quoted 4 lines · Jean-Marc Pigeon

Added syslog.c such container /proc/kmsg and host /proc/kmsg do not leak in each other.
Running rsyslog daemon within a container won't destroy host kernel messages.

Thanks Jean-Marc. But this really isn't doing most of what I'd recommended in my last emails (both public and private. In particular:

include/linux/user_namespace.h struct user_namespace { · line 17

Quoted 8 lines

index cc4f453..3d0c73e 100644

include/linux/user_namespace.h +1 -0
@@ -14,6 +14,7 @@ struct user_namespace {
 	struct hlist_head	uidhash_table[UIDHASH_SZ];
 	struct user_struct	*creator;
 	struct work_struct	destroyer;
+	struct syslog_ns        *syslog;

syslog_ns should be moved into nsproxy and unshared with a separate clone(CLONE_SYSLOG);

include/linux/user_namespace.h struct user_namespace {

Quoted 12 lines
include/linux/user_namespace.h +2 -9
-static void emit_log_char(char c)
+static void emit_log_char(struct syslog_ns *syslog_ns, char c)
 {
-	LOG_BUF(log_end) = c;
-	log_end++;
-	if (log_end - log_start > log_buf_len)
-		log_start = log_end - log_buf_len;
-	if (log_end - con_start > log_buf_len)
-		con_start = log_end - log_buf_len;
-	if (logged_chars < log_buf_len)
-		logged_chars++;
+	LOG_BUF(syslog_ns, sys_log_end) = c;

Taking syslog_ns from current in emit_log_char is not right. Emit_log_char() is called from printk which (the comment above printk warns us) can be called from any context.

That was why I suggested:

Quoted 14 lines

! I think my patch is fundamentally wrong anyway: we should not ! use current's context at vprintk like i did. We should use an ! optional passed-in context from those callsites where we want to, ! and default to init otherwise. That means
!
! 1. put the core of vprintk() into vnsprintk() which takes a syslog ! namespace as argument
!
! 2. make vprintk() a wrapper around vnsprintk() which passes in ! init_syslog_ns to vnsprintk(). printk can remain unchanged. !
! 4. make nsprintk() a wrapper around vnsprintk() which takes a syslog ! ns argument and pass it to vnsprintk()
!

Quoted 8 lines

! 3. do_syslog() can obviously be containerized the same way it ! is now.
!
! 4. take a printk call like the iptables ones you want and turn ! int into nsprintk syscall.
!
! The very comment above printk explains why I was an idiot to write ! let alone send that patch.

thanks,
-serge

A message that is not in the archive (sent off-list or not yet received): 20100211174843.GF6884-r/[email protected]

#4 lore raw
Quoted 10 lines · Serge E. Hallyn
Quoted 4 lines · Jean-Marc Pigeon

Added syslog.c such container /proc/kmsg and host /proc/kmsg do not leak in each other.
Running rsyslog daemon within a container won't destroy host kernel messages.

Thanks Jean-Marc. But this really isn't doing most of what I'd recommended in my last emails (both public and private. In particular:

Quoted 11 lines

include/linux/user_namespace.h struct user_namespace { · line 17

Quoted 8 lines

index cc4f453..3d0c73e 100644

include/linux/user_namespace.h +1 -0
@@ -14,6 +14,7 @@ struct user_namespace {
 	struct hlist_head	uidhash_table[UIDHASH_SZ];
 	struct user_struct	*creator;
 	struct work_struct	destroyer;
+	struct syslog_ns        *syslog;

syslog_ns should be moved into nsproxy and unshared with a separate clone(CLONE_SYSLOG);

I agree. Keeping it in the user_namespace is strange. It should be in the nsproxy along with all of the other namespace pointers.

Quoted 18 lines

include/linux/user_namespace.h struct user_namespace {

Quoted 13 lines
include/linux/user_namespace.h +2 -9
-static void emit_log_char(char c)
+static void emit_log_char(struct syslog_ns *syslog_ns, char c)
 {
-	LOG_BUF(log_end) = c;
-	log_end++;
-	if (log_end - log_start > log_buf_len)
-		log_start = log_end - log_buf_len;
-	if (log_end - con_start > log_buf_len)
-		con_start = log_end - log_buf_len;
-	if (logged_chars < log_buf_len)
-		logged_chars++;
+	LOG_BUF(syslog_ns, sys_log_end) = c;

Taking syslog_ns from current in emit_log_char is not right. Emit_log_char() is called from printk which (the comment above printk warns us) can be called from any context.

Quoted 21 lines

That was why I suggested:

Quoted 19 lines

! I think my patch is fundamentally wrong anyway: we should not ! use current's context at vprintk like i did. We should use an ! optional passed-in context from those callsites where we want to, ! and default to init otherwise. That means
!
! 1. put the core of vprintk() into vnsprintk() which takes a syslog ! namespace as argument
!
! 2. make vprintk() a wrapper around vnsprintk() which passes in ! init_syslog_ns to vnsprintk(). printk can remain unchanged. !
! 4. make nsprintk() a wrapper around vnsprintk() which takes a syslog ! ns argument and pass it to vnsprintk()
!
! 3. do_syslog() can obviously be containerized the same way it ! is now.
!
! 4. take a printk call like the iptables ones you want and turn ! int into nsprintk syscall.

Definitely. Actually, I think we can go one step further and say that passing syslog_ns directly to nsprintk() is wrong too. It's wrong because we only know the namespace that's relevant to the printk contents -- and that won't usually be a syslog_ns.

Better to have the "find corresponding syslog_ns" logic inside nsprintk(). The great thing about doing it this way is if we ever decide to duplicate printk output to multiple containers it can be done inside nsprintk rather than doing a flag-day patch.

Cheers,
-Matt Helsley

A message that is not in the archive (sent off-list or not yet received): 20100213181158.GY3714-52DBMbEzqgQ/wnmkkaCWp/[email protected]

#6 lore raw
Quoted 71 lines · Matt Helsley
Quoted 10 lines · Serge E. Hallyn
Quoted 4 lines · Jean-Marc Pigeon

Added syslog.c such container /proc/kmsg and host /proc/kmsg do not leak in each other.
Running rsyslog daemon within a container won't destroy host kernel messages.

Thanks Jean-Marc. But this really isn't doing most of what I'd recommended in my last emails (both public and private. In particular:

Quoted 11 lines

include/linux/user_namespace.h struct user_namespace { · line 17

Quoted 8 lines

index cc4f453..3d0c73e 100644

include/linux/user_namespace.h +1 -0
@@ -14,6 +14,7 @@ struct user_namespace {
 	struct hlist_head	uidhash_table[UIDHASH_SZ];
 	struct user_struct	*creator;
 	struct work_struct	destroyer;
+	struct syslog_ns        *syslog;

syslog_ns should be moved into nsproxy and unshared with a separate clone(CLONE_SYSLOG);

I agree. Keeping it in the user_namespace is strange. It should be in the nsproxy along with all of the other namespace pointers.

Quoted 18 lines

include/linux/user_namespace.h struct user_namespace {

Quoted 13 lines
include/linux/user_namespace.h +2 -9
-static void emit_log_char(char c)
+static void emit_log_char(struct syslog_ns *syslog_ns, char c)
 {
-	LOG_BUF(log_end) = c;
-	log_end++;
-	if (log_end - log_start > log_buf_len)
-		log_start = log_end - log_buf_len;
-	if (log_end - con_start > log_buf_len)
-		con_start = log_end - log_buf_len;
-	if (logged_chars < log_buf_len)
-		logged_chars++;
+	LOG_BUF(syslog_ns, sys_log_end) = c;

Taking syslog_ns from current in emit_log_char is not right. Emit_log_char() is called from printk which (the comment above printk warns us) can be called from any context.

Quoted 21 lines

That was why I suggested:

Quoted 19 lines

! I think my patch is fundamentally wrong anyway: we should not ! use current's context at vprintk like i did. We should use an ! optional passed-in context from those callsites where we want to, ! and default to init otherwise. That means
!
! 1. put the core of vprintk() into vnsprintk() which takes a syslog ! namespace as argument
!
! 2. make vprintk() a wrapper around vnsprintk() which passes in ! init_syslog_ns to vnsprintk(). printk can remain unchanged. !
! 4. make nsprintk() a wrapper around vnsprintk() which takes a syslog ! ns argument and pass it to vnsprintk()
!
! 3. do_syslog() can obviously be containerized the same way it ! is now.
!
! 4. take a printk call like the iptables ones you want and turn ! int into nsprintk syscall.

Definitely. Actually, I think we can go one step further and say that passing syslog_ns directly to nsprintk() is wrong too. It's wrong because we only know the namespace that's relevant to the printk contents -- and that won't usually be a syslog_ns.

Quoted 4 lines

Better to have the "find corresponding syslog_ns" logic inside nsprintk(). The great thing about doing it this way is if we ever decide to duplicate printk output to multiple containers it can be done inside nsprintk rather than doing a flag-day patch.

It's also easy to see that current's nsproxy won't always point to the right namespace. Consider kernel threads that do "work" which was initiated by a userspace task (e.g. a process doing a read on an NFS file triggers rpc IO kthreads). Usually the relevant namespace pointer will referenced from the kernel objects related to the work -- not "current" since that's the kernel thread. But those structures don't reference nsproxies -- they refer to a netns for example. So being able to obtain a syslog_ns from a netns is critical yet can't rely on current.

Cheers,
-Matt Helsley

#7 lore raw
In reply to a message not in the archive

Hello,

Quoted 23 lines · Matt Helsley
Quoted 10 lines · Serge E. Hallyn
Quoted 4 lines · Jean-Marc Pigeon

Added syslog.c such container /proc/kmsg and host /proc/kmsg do not leak in each other.
Running rsyslog daemon within a container won't destroy host kernel messages.

Thanks Jean-Marc. But this really isn't doing most of what I'd recommended in my last emails (both public and private. In particular:

Quoted 11 lines

include/linux/user_namespace.h struct user_namespace { · line 17

Quoted 8 lines

index cc4f453..3d0c73e 100644

include/linux/user_namespace.h +1 -0
@@ -14,6 +14,7 @@ struct user_namespace {
 	struct hlist_head	uidhash_table[UIDHASH_SZ];
 	struct user_struct	*creator;
 	struct work_struct	destroyer;
+	struct syslog_ns        *syslog;

syslog_ns should be moved into nsproxy and unshared with a separate clone(CLONE_SYSLOG);

Quoted 2 lines

I agree. Keeping it in the user_namespace is strange. It should be in the nsproxy along with all of the other namespace pointers.

I won't argue on this, I put it in user_namespace as serge proposed it at first and code implementation was a test/trial to me.
Setting syslog in nsproxy is fine to me (seems every body agree.. right?)

[...]

Quoted 10 lines

Definitely. Actually, I think we can go one step further and say that passing syslog_ns directly to nsprintk() is wrong too. It's wrong because we only know the namespace that's relevant to the printk contents -- and that won't usually be a syslog_ns.

Better to have the "find corresponding syslog_ns" logic inside nsprintk(). The great thing about doing it this way is if we ever decide to duplicate printk output to multiple containers it can be done inside nsprintk rather than doing a flag-day patch.

I tend to agree with you Matt.

I strongly disagree about what I understand about Serge proposal to add a "new printk".

What is the purpose of printk?
- Report a system data to the acting authority.

Syslog cant be sent to:
HOST: syslog
CONT: syslog
CONT: + HOST: syslog (duplication) Decision to duplicate syslog can be a printk privilege, lets says "according message level".

Decision to send to HOST: or CONT: syslog is depending execution context, which can be found back within the printk function itself (so no need to have ns_printk).

What is proposing Serge is to HARD CODE WITHIN kernel if we call the genuine printk or ns_printk, which is now a door wide open to coder interpretation ("is printk message containerised or not", my coding decision is as good as yours, and nobody will be satisfied).

My proposal is to say, if a ressource is containerized it must be used in containerized context, this means all printk are called within the context anyway.

What does that mean in real life?. lets call again the iptable example.

We already have a HOST: iptables set AND a CONT: iptables set. I have for my say, to keep consistency we MUST execute CONT: iptables rules checking within the CONT: context (which is not the case now... IMHO).

This approach is coherent, if a ressource (iptable, network device, file system,...) is defined AND managed within
CONT: report must be done TO CONT: (period). Means coding level need to take care ONLY about 'ressource' ownership, if it is "own" by CONT: then access it in its
CONT: context.

Keep in mind, A fully containerized system can be managed by someone with full privilege BUT NOT in charge of the host itself (IE: without host access).

My proposal is a clear cut, if a ressource is containerized report to CONT: (containerized) syslog... no question ask. (sure enough printk could duplicate message to HOST:
my guess it won't be really needed in practical life, but I could be wrong....)

Signature · 13 lines
A bientôt
==========================================================================
Jean-Marc Pigeon                                   Internet: [email protected]
SAFE Inc.                                          Phone: (514) 493-4280
                                                   Fax:   (514) 493-1946
        Clement, 'a kiss solution' to get rid of SPAM (at last)
           Clement' Home base <"http://www.clement.safe.ca">
==========================================================================

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers

A message that is not in the archive (sent off-list or not yet received): 1266088499.19130.295.camel-4BUXZ/[email protected]

#9 lore raw
Quoted 26 lines · Jean-Marc Pigeon

Hello,

Quoted 23 lines · Matt Helsley
Quoted 21 lines · Serge E. Hallyn
Quoted 4 lines · Jean-Marc Pigeon

Added syslog.c such container /proc/kmsg and host /proc/kmsg do not leak in each other.
Running rsyslog daemon within a container won't destroy host kernel messages.

Thanks Jean-Marc. But this really isn't doing most of what I'd recommended in my last emails (both public and private. In particular:

include/linux/user_namespace.h struct user_namespace { · line 17

Quoted 8 lines

index cc4f453..3d0c73e 100644

include/linux/user_namespace.h +1 -0
@@ -14,6 +14,7 @@ struct user_namespace {
 	struct hlist_head	uidhash_table[UIDHASH_SZ];
 	struct user_struct	*creator;
 	struct work_struct	destroyer;
+	struct syslog_ns        *syslog;

syslog_ns should be moved into nsproxy and unshared with a separate clone(CLONE_SYSLOG);

Quoted 7 lines
Quoted 2 lines

I agree. Keeping it in the user_namespace is strange. It should be in the nsproxy along with all of the other namespace pointers.

I won't argue on this, I put it in user_namespace as serge proposed it at first and code implementation was a test/trial to me.
Setting syslog in nsproxy is fine to me (seems every body agree.. right?)

Good, thanks!

Quoted 32 lines

[...]

Quoted 10 lines

Definitely. Actually, I think we can go one step further and say that passing syslog_ns directly to nsprintk() is wrong too. It's wrong because we only know the namespace that's relevant to the printk contents -- and that won't usually be a syslog_ns.

Better to have the "find corresponding syslog_ns" logic inside nsprintk(). The great thing about doing it this way is if we ever decide to duplicate printk output to multiple containers it can be done inside nsprintk rather than doing a flag-day patch.

I tend to agree with you Matt.

I strongly disagree about what I understand about Serge proposal to add a "new printk".

What is the purpose of printk?
- Report a system data to the acting authority.

Syslog cant be sent to:
HOST: syslog
CONT: syslog
CONT: + HOST: syslog (duplication) Decision to duplicate syslog can be a printk privilege, lets says "according message level".

Decision to send to HOST: or CONT: syslog is depending execution context, which can be found back within the printk function itself (so no need to have ns_printk).

Quoted 5 lines

What is proposing Serge is to HARD CODE WITHIN kernel if we call the genuine printk or ns_printk, which is now a door wide open to coder interpretation ("is printk message containerised or not", my coding decision is as good as yours, and nobody will be satisfied).

I think it will be pretty clear from the code which is preferred, printk or nsprintk. For example, output from the the various module __init functions obviously does not belong in an nsprintk().

Quoted 4 lines

My proposal is to say, if a ressource is containerized it must be used in containerized context, this means all printk are called within the context anyway.

But that simply does not happen in all kernel code. Please see my kernel thread point. Not all work happens in a "containerized context". Same thing with the __init example above. It doesn't matter which container caused the module to be loaded -- only that the kernel has loaded it. So nsprintk() doesn't make sense there, even though there is the initial namespace to use.

Quoted 7 lines

What does that mean in real life?. lets call again the iptable example.

We already have a HOST: iptables set AND a CONT: iptables set. I have for my say, to keep consistency we MUST execute CONT: iptables rules checking within the CONT: context (which is not the case now... IMHO).

Enforcing this using "current" would require duplicating kernel threads on a per-container basis. That's simply not going to fly with the kernel community (and for good reason).

Quoted 3 lines

This approach is coherent, if a ressource (iptable, network device, file system,...) is defined AND managed within

It sounds reasonable except you're hand-waving alot of the complexity away first.

Quoted 4 lines

CONT: report must be done TO CONT: (period). Means coding level need to take care ONLY about 'ressource' ownership, if it is "own" by CONT: then access it in its
CONT: context.

Tracking all of these accesses down and ensuring they are only done from "its container context" is difficult or impossible. It's not as easy as you seem to think. In some cases the same resource could be shared between containers. Which should we access it from then?

Quoted 3 lines

Keep in mind, A fully containerized system can be managed by someone with full privilege BUT NOT in charge of the host itself (IE: without host access).

Sure. (We're not there yet but I think we'd like to get there eventually.)

Quoted 2 lines

My proposal is a clear cut, if a ressource is containerized report to CONT: (containerized) syslog... no question ask.

That part of the proposal is simple and makes alot of sense. The ramifcations of it on kernel code are not simple and often there's no clean way to do it.

Have a look at the iptables code. I've been looking at it and the way to make the various printks namespace-clean is far from obvious without drastically changing the core data structures of iptables. It's also not obvious that making them namespace clean is really useful (as Eric seemed to imply). ipt_LOG.c and ipt_ULOG.c are perhaps the best arguments for nsprintk() in iptables.

Quoted 3 lines

(sure enough printk could duplicate message to HOST:
my guess it won't be really needed in practical life, but I could be wrong....)

Yup.

Cheers,
-Matt Helsley

A message that is not in the archive (sent off-list or not yet received): 20100213203610.GA3714-52DBMbEzqgQ/wnmkkaCWp/[email protected]

#11 lore raw

Hello,

[...]

Quoted 4 lines

Tracking all of these accesses down and ensuring they are only done from "its container context" is difficult or impossible. It's not as easy as you seem to think. In some cases the same resource could be shared between containers. Which should we access it from then?

How come?! ressources (a device, Iptable rules,...) containerized within one container could be shared by another unrelated container?.

Does this means (simple example) someone change iptable rules for one container that could change another unrelated container behavior ?!...no way... This only case is a sub-container (a container within a container), but in such case we are are in the HOST: versus CONT: situation. Device will be controlled by CONT: even is used by SUBCONT:
All depends where the device is defined (where is the definition responsability?, that the question to assign syslog..., usage is another story).

Quoted 8 lines
Quoted 4 lines

Keep in mind, A fully containerized system can be managed by someone with full privilege BUT NOT in charge of the host itself (IE: without host access).

Sure. (We're not there yet but I think we'd like to get there eventually.)

Quoted 6 lines
Quoted 2 lines

My proposal is a clear cut, if a ressource is containerized report to CONT: (containerized) syslog... no question ask.

That part of the proposal is simple and makes alot of sense. The ramifcations of it on kernel code are not simple and often there's no clean way to do it.

Well, this trouble me somewhat.... 2.6.18-128.2.1.el5.028stab064.7 (just an example, I am using day to day), is containerising iptables an other syslogs nice way....,
We are now 2.6.33 you are telling me what was experimented, learned, monthssss ago can't still be implemented in current kernel main stream?....

Signature · 13 lines
A bientôt
==========================================================================
Jean-Marc Pigeon                                   Internet: [email protected]
SAFE Inc.                                          Phone: (514) 493-4280
                                                   Fax:   (514) 493-1946
        Clement, 'a kiss solution' to get rid of SPAM (at last)
           Clement' Home base <"http://www.clement.safe.ca">
==========================================================================

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers

A message that is not in the archive (sent off-list or not yet received): 1266098176.19130.320.camel-4BUXZ/[email protected]

#13 lore raw
Quoted 9 lines · Jean-Marc Pigeon

Hello,

[...]

Quoted 4 lines

Tracking all of these accesses down and ensuring they are only done from "its container context" is difficult or impossible. It's not as easy as you seem to think. In some cases the same resource could be shared between containers. Which should we access it from then?

How come?! ressources (a device, Iptable rules,...)

Because it's kernel code. Kernel code implements interrupt handlers, schedules processes, and even does work inside kernel threads. We can't guarantee that some of the work initiated by a process is always done with current == <the process>. Hence ensuring that these accesses are only done from "its container context" is not reasonable. The best we can do is ensure that accesses from the processes in the container are contained.

Quoted 2 lines

containerized within one container could be shared by another unrelated container?.

Yes. namespace boundaries only coincide if userspace chooses to make them coincide. For example, the tasks in a network namespace do not necessarily all share the same mount namespace.

Quoted 3 lines

Does this means (simple example) someone change iptable rules for one container that could change another unrelated container behavior ?!...no way...

Two "unrelated containers" would share the same iptables rules so long as they share a network namespace.

<snip>

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

My proposal is a clear cut, if a ressource is containerized report to CONT: (containerized) syslog... no question ask.

That part of the proposal is simple and makes alot of sense. The ramifcations of it on kernel code are not simple and often there's no clean way to do it.

	Well, this trouble me somewhat....
	2.6.18-128.2.1.el5.028stab064.7 (just an example, I am using
	day to day), is containerising iptables an other syslogs 
	nice way....,

Er.. you have a 2.6.18 kernel "containerising iptables an other syslogs"? I didn't think iptables supported network namespaces until somewhat recently. Is this an openvz-patched kernel you're talking about?

Quoted 3 lines

We are now 2.6.33 you are telling me what was experimented, learned, monthssss ago can't still be implemented in current kernel main stream?....

Careful. "no clean way to do it" does not mean "can't be done".

Cheers,
-Matt Helsley

A message that is not in the archive (sent off-list or not yet received): 20100213223306.GB3714-52DBMbEzqgQ/wnmkkaCWp/[email protected]

#15 lore raw

Hello,

Quoted 10 lines · Matt Helsley
Quoted 3 lines · Jean-Marc Pigeon

Hello,

[...]

Yes. namespace boundaries only coincide if userspace chooses to make them coincide. For example, the tasks in a network namespace do not necessarily all share the same mount namespace.

Quoted 6 lines
Quoted 3 lines

Does this means (simple example) someone change iptable rules for one container that could change another unrelated container behavior ?!...no way...

Two "unrelated containers" would share the same iptables rules so long as they share a network namespace.

So ... logic means.... those two unrelated container do not "own" the iptable rules.
But lets say, for fun, process within container 1 change rules (locking out ssh access), does it mean now ssh connexion on container 2 locked out too... If you say "container 0" which container 1 and 2 are include in, decided to lock ssh access, then its OK.
Container 1 and 2 are still unrelated, right, but both are related to container 0, and syslog report must go to container 0.
(once again it is clean cut.)

[...]

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

That part of the proposal is simple and makes alot of sense. The ramifcations of it on kernel code are not simple and often there's no clean way to do it.

	Well, this trouble me somewhat....
	2.6.18-128.2.1.el5.028stab064.7 (just an example, I am using
	day to day), is containerising iptables an other syslogs 
	nice way....,

Er.. you have a 2.6.18 kernel "containerising iptables an other syslogs"? I didn't think iptables supported network namespaces until somewhat recently. Is this an openvz-patched kernel you're talking about?

Yep! release date 07-Nov-2009, and I am pretty sure 2.6.18-53.1.19.el5.028stab053.14 release date 21-May-2008 was doing it too...

Iptable logs are reported to VZ (I have an example right in front of me)

Feb 13 14:42:13 host1 kernel: RJCT IN=venet0 OUT= MAC= SRC=X.X.X.X

DST=X.X.X.X LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=58325 DF PROTO=TCP SPT=37248 DPT=22 WINDOW=5840 RES=0x00 SYN URGP=0

When I said monthssss, I really mean it.

Quoted 1 line

Careful. "no clean way to do it" does not mean "can't be done".

Agreed....container network, seems to me, implemented in far better way than on VZ, so it is possible to implement good idea in clean way.

Signature · 13 lines
A bientôt
==========================================================================
Jean-Marc Pigeon                                   Internet: [email protected]
SAFE Inc.                                          Phone: (514) 493-4280
                                                   Fax:   (514) 493-1946
        Clement, 'a kiss solution' to get rid of SPAM (at last)
           Clement' Home base <"http://www.clement.safe.ca">
==========================================================================

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers
#16 lore raw
In reply to a message not in the archive

Thanks for working on this. Some minor style issues below:

Quoted 5 lines · Jean-Marc Pigeon

Added syslog.c such container /proc/kmsg and host /proc/kmsg do not leak in each other.
Running rsyslog daemon within a container won't destroy host kernel messages.
---

<snip>

Quoted 6 lines
kernel/syslog.c new file +0 -0
new file mode 100644
index 0000000..69d30a9
@@ -0,0 +1,157 @@

<snip>

kernel/syslog.c line 126

Quoted 3 lines
kernel/syslog.c new file +3 -0
+		(void) kfree(old_buf);
+		}
+	(void) printk(KERN_NOTICE "log_buf_len: %u\n", syslog_ns->buf_len);

I don't understand why you chose to put in all of the "(void)" casts. They do nothing -- they don't change how the code works nor do they improve the readability of the code.

kernel/syslog.c line 136

Quoted 10 lines
kernel/syslog.c new file +10 -0
+	return syslog_ns;
+}
+/*
+ * Procedure to free all ressources tied to syslog
+ *
+ */
+struct syslog_ns *syslog_free(struct syslog_ns *syslog)
+
+{
+	if (syslog != (struct syslog_ns *)0) {

Why aren't you using NULL? Better yet, in these cases it's common to use:

if (syslog) {

Once this gets out of the RFC steps perhaps run these through checkpatch..

Cheers,
-Matt Helsley

#17 lore raw
In reply to a message not in the archive
Quoted 4 lines · Jean-Marc Pigeon

Added syslog.c such container /proc/kmsg and host /proc/kmsg do not leak in each other.
Running rsyslog daemon within a container won't destroy host kernel messages.

If the goal is to not destroy the host kernel messages the much simpler solution would be to simply disable /proc/kmsg in the container. I expect we can get that for free with a some bug fixes to the user namespace (aka if you are not in the global namespace you can't touch /proc/kmsg).

Additionally except for the possible exception of logging firewall rules I can't think of a case where I would want kernel printk's in anything other than the global kernel ring buffer.

Eric

A message that is not in the archive (sent off-list or not yet received): m1pr49ne3y.fsf-+imSwln9KH6u2/kzUuoCbdi2O/[email protected]

#19 lore raw

Hello,

Just got your Email... (Sic :-})

Quoted 13 lines · Eric W. Biederman
Quoted 4 lines · Jean-Marc Pigeon

Added syslog.c such container /proc/kmsg and host /proc/kmsg do not leak in each other.
Running rsyslog daemon within a container won't destroy host kernel messages.

If the goal is to not destroy the host kernel messages the much simpler solution would be to simply disable /proc/kmsg in the container. I expect we can get that for free with a some bug fixes to the user namespace (aka if you are not in the global namespace you can't touch /proc/kmsg).

Quoted 3 lines

Additionally except for the possible exception of logging firewall rules I can't think of a case where I would want kernel printk's in anything other than the global kernel ring buffer.

Beside not to have HOST: syslog corrupted, my very original main concern was indeed to feed container with its own firewall rules.

Thinking about all this, I believe we are not bold enough. We should be reporting all kernel message about devices/units own/defined within the container to the own container syslog.

Let me try explain better by an example. To make container networking you can use veth pair.
One of the veth pair is given to container and related to container own network definition (eth0).

this TACAMO order "ip link set 'from_cont_veth' netns..." make now the container "Take ChArge and Move Out" and all kernel trouble to have the interface fully working within the container should be reported to container syslog.

Keep in mind, CONT: sys-admin could be a different person than HOST: sys-admin. As long veth pair is set properly, CONT: sys-admin problem setting with eth0 is not a HOST: sys-admin concern.

A fully working container syslog will address/resolve this kind of situation.

Signature · 13 lines
A bientôt
==========================================================================
Jean-Marc Pigeon                                   Internet: [email protected]
SAFE Inc.                                          Phone: (514) 493-4280
                                                   Fax:   (514) 493-1946
        Clement, 'a kiss solution' to get rid of SPAM (at last)
           Clement' Home base <"http://www.clement.safe.ca">
==========================================================================

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers