From: Daniel Lezcano <dlezcano-juSfH4iHXoxBDgjK7y7TUQ@public.gmane.org>
To: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Cc: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org
Subject: Re: [RFC][patch 3/3] activate filtering for the bind
Date: Wed, 05 Sep 2007 18:38:57 +0200 [thread overview]
Message-ID: <46DEDBA1.9010706@meiosys.com> (raw)
In-Reply-To: <20070905161848.GN1403-6s5zFf/epYLPQpwDFJZrxKsjOiXwFzmk@public.gmane.org>
Serge E. Hallyn wrote:
> Quoting dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org (dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org):
>> From: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
>>
>> For the moment, I only made this patch for the RFC. It shows how simple it is
>> to hook different socket syscalls. This patch denies bind to any addresses
>> which are not in the container IPV4 address list, except for the INADDR_ANY.
>>
>> Signed-off-by: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
>>
>> ---
>> kernel/container_network.c | 66 +++++++++++++++++++++++----------------------
>> 1 file changed, 35 insertions(+), 31 deletions(-)
>>
>> Index: 2.6-mm/kernel/container_network.c
>> ===================================================================
>> --- 2.6-mm.orig/kernel/container_network.c
>> +++ 2.6-mm/kernel/container_network.c
>> @@ -12,6 +12,9 @@
>> #include <linux/list.h>
>> #include <linux/spinlock.h>
>> #include <linux/security.h>
>> +#include <linux/in.h>
>> +#include <linux/net.h>
>> +#include <linux/socket.h>
>>
>> struct network {
>> struct container_subsys_state css;
>> @@ -53,24 +56,14 @@
>>
>> static int network_socket_create(int family, int type, int protocol, int kern)
>> {
>> - struct network *network;
>> -
>> - network = task_network(current);
>> - if (!network || network == &top_network)
>> - return 0;
>> -
>> + /* nothing to do right now */
>> return 0;
>> }
>>
>> static int network_socket_post_create(struct socket *sock, int family,
>> int type, int protocol, int kern)
>> {
>> - struct network *network;
>> -
>> - network = task_network(current);
>> - if (!network || network == &top_network)
>> - return 0;
>> -
>> + /* nothing to do right now */
>> return 0;
>> }
>>
>> @@ -79,47 +72,58 @@
>
> Please so send -p diffs. I'll assume this is network_socket_bind()
> given your patch description :)
>
>> int addrlen)
>> {
>> struct network *network;
>> + struct list_head *l;
>> + rwlock_t *lock;
>> + struct ipv4_list *entry;
>> + __be32 addr;
>> + int ret = -EPERM;
>>
>> + /* Do nothing for the root container */
>> network = task_network(current);
>> if (!network || network == &top_network)
>> return 0;
>>
>> - return 0;
>> + /* Check we have to do some filtering */
>> + if (sock->ops->family != AF_INET)
>> + return 0;
>> +
>> + l = &network->ipv4_list;
>> + lock = &network->ipv4_list_lock;
>> + addr = ((struct sockaddr_in *)address)->sin_addr.s_addr;
>> +
>> + if (addr == INADDR_ANY)
>
> In bsdjail, if addr == INADDR_ANY, I set addr = jailaddr. Do you think
> you want to do that?
Good question. This is one think I would like to define. If we do that
we can not connect via 127.0.0.1. and|or a container can have more than
one IP address, no ?
IMHO, we should have the loopback address available for all containers
and that means 127.0.0.1 is an IP address which is not isolated.
If we choose to deny access to 127.0.0.1, then there will be some issues
with the routing. If we connect to 127.0.0.1 (this address belongs to
the root container) from a child container, the source address should be
filled with an IP address belonging to a container (eg 10.0.0.10), so we
have (src)10.0.0.1 -> (dst)127.0.0.1, that means the root container will
answer to 10.0.0.1 and use this address. This is no sense because
routing should be for the loopback: 127.0.0.1<->127.0.0.1, and we break
isolation. Tricky.
>
>> + return 0;
>> +
>> + read_lock(lock);
>> + list_for_each_entry(entry, l, list) {
>> + if (entry->address != addr)
>> + continue;
>> + ret = 0;
>> + break;
>> + }
>> + read_unlock(lock);
>> +
>> + return ret;
>> }
>>
>> static int network_socket_connect(struct socket * sock,
>> struct sockaddr * address,
>> int addrlen)
>> {
>> - struct network *network;
>> -
>> - network = task_network(current);
>> - if (!network || network == &top_network)
>> - return 0;
>> -
>> + /* nothing to do right now */
>> return 0;
>> }
>>
>> static int network_socket_listen(struct socket * sock, int backlog)
>> {
>> - struct network *network;
>> -
>> - network = task_network(current);
>> - if (!network || network == &top_network)
>> - return 0;
>> -
>> + /* nothing to do right now */
>> return 0;
>> }
>>
>> static int network_socket_accept(struct socket *sock,
>> struct socket *newsock)
>> {
>> - struct network *network;
>> -
>> - network = task_network(current);
>> - if (!network || network == &top_network)
>> - return 0;
>> -
>> + /* nothing to do right now */
>> return 0;
>> }
>>
>>
>> --
>> _______________________________________________
>> Containers mailing list
>> Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
>> https://lists.linux-foundation.org/mailman/listinfo/containers
>
next prev parent reply other threads:[~2007-09-05 16:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-04 17:00 [RFC][patch 0/3] Network container subsystem - bind filtering dlezcano-NmTC/0ZBporQT0dZR+AlfA
2007-09-04 17:00 ` [RFC][patch 1/3] network container subsystem dlezcano-NmTC/0ZBporQT0dZR+AlfA
[not found] ` <20070904171525.771956554-lUQnSZrVijcklpeYT4thRqpRWpusSO0yQ3R/GR7Q8HurIzol8Bc5pA@public.gmane.org>
2007-09-05 11:50 ` Benjamin Thery
[not found] ` <46DE97F5.3090609-6ktuUTfB/bM@public.gmane.org>
2007-09-05 12:43 ` Daniel Lezcano
2007-09-05 15:49 ` Serge E. Hallyn
2007-09-04 17:00 ` [RFC][patch 2/3] network security hooks dlezcano-NmTC/0ZBporQT0dZR+AlfA
[not found] ` <20070904171527.201921132-lUQnSZrVijcklpeYT4thRqpRWpusSO0yQ3R/GR7Q8HurIzol8Bc5pA@public.gmane.org>
2007-09-05 16:04 ` Serge E. Hallyn
2007-09-04 17:00 ` [RFC][patch 3/3] activate filtering for the bind dlezcano-NmTC/0ZBporQT0dZR+AlfA
[not found] ` <20070904171528.704108193-lUQnSZrVijcklpeYT4thRqpRWpusSO0yQ3R/GR7Q8HurIzol8Bc5pA@public.gmane.org>
2007-09-05 16:18 ` Serge E. Hallyn
[not found] ` <20070905161848.GN1403-6s5zFf/epYLPQpwDFJZrxKsjOiXwFzmk@public.gmane.org>
2007-09-05 16:38 ` Daniel Lezcano [this message]
[not found] ` <46DEDBA1.9010706-juSfH4iHXoxBDgjK7y7TUQ@public.gmane.org>
2007-09-10 13:23 ` Serge E. Hallyn
[not found] ` <20070910132330.GB9565-6s5zFf/epYLPQpwDFJZrxKsjOiXwFzmk@public.gmane.org>
2007-09-10 13:52 ` Daniel Lezcano
[not found] ` <46E54C11.1050403-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2007-09-10 15:46 ` Serge E. Hallyn
[not found] ` <20070910154630.GA3905-6s5zFf/epYLPQpwDFJZrxKsjOiXwFzmk@public.gmane.org>
2007-09-10 17:49 ` [Devel] " Paul Menage
[not found] ` <6599ad830709101049g5ea45749k66e362326264b4b0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-09-10 18:11 ` Serge E. Hallyn
[not found] ` <20070910181131.GB31638-6s5zFf/epYLPQpwDFJZrxKsjOiXwFzmk@public.gmane.org>
2007-09-10 18:15 ` Paul Menage
[not found] ` <20070904170022.964253374-lUQnSZrVijcklpeYT4thRqpRWpusSO0yQ3R/GR7Q8HurIzol8Bc5pA@public.gmane.org>
2007-09-05 14:05 ` [RFC][patch 0/3] Network container subsystem - bind filtering Benjamin Thery
2007-09-05 15:37 ` Serge E. Hallyn
[not found] ` <20070905153741.GK1403-6s5zFf/epYLPQpwDFJZrxKsjOiXwFzmk@public.gmane.org>
2007-09-05 15:41 ` Daniel Lezcano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46DEDBA1.9010706@meiosys.com \
--to=dlezcano-jusfh4ihxoxbdgjk7y7tuq@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
--cc=serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.