* [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v2)
2009-12-18 3:00 ` Michael Stone
@ 2009-12-18 3:29 ` Michael Stone
2009-12-18 4:43 ` Valdis.Kletnieks
2009-12-18 15:46 ` Alan Cox
2009-12-18 3:31 ` [PATCH 2/3] Security: Implement prctl(PR_SET_NETWORK, PR_NETWORK_OFF) semantics. (v2) Michael Stone
` (3 subsequent siblings)
4 siblings, 2 replies; 35+ messages in thread
From: Michael Stone @ 2009-12-18 3:29 UTC (permalink / raw)
To: Mark Seaborn
Cc: linux-kernel, netdev, linux-security-module, Andi Kleen,
David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang,
Michael Stone
Daniel Bernstein has observed [1] that security-conscious userland processes
may benefit from the ability to irrevocably remove their ability to create,
bind, connect to, or send messages except in the case of previously connected
sockets or AF_UNIX filesystem sockets. We provide this facility by implementing
support for a new prctl(PR_SET_NETWORK) flag named PR_NETWORK_OFF.
This facility is particularly attractive to security platforms like OLPC
Bitfrost [2] and to isolation programs like Rainbow [3] and Plash [4].
[1]: http://cr.yp.to/unix/disablenetwork.html
[2]: http://wiki.laptop.org/go/OLPC_Bitfrost
[3]: http://wiki.laptop.org/go/Rainbow
[4]: http://plash.beasts.org/
Signed-off-by: Michael Stone <michael@laptop.org>
---
include/linux/prctl.h | 7 +++++++
include/linux/prctl_network.h | 7 +++++++
include/linux/sched.h | 2 ++
kernel/sys.c | 32 ++++++++++++++++++++++++++++++++
4 files changed, 48 insertions(+), 0 deletions(-)
create mode 100644 include/linux/prctl_network.h
diff --git a/include/linux/prctl.h b/include/linux/prctl.h
index a3baeb2..4eb4110 100644
--- a/include/linux/prctl.h
+++ b/include/linux/prctl.h
@@ -102,4 +102,11 @@
#define PR_MCE_KILL_GET 34
+/* Get/set process disable-network flags */
+#define PR_SET_NETWORK 35
+#define PR_GET_NETWORK 36
+# define PR_NETWORK_ON 0
+# define PR_NETWORK_OFF 1
+# define PR_NETWORK_ALL_FLAGS 1
+
#endif /* _LINUX_PRCTL_H */
diff --git a/include/linux/prctl_network.h b/include/linux/prctl_network.h
new file mode 100644
index 0000000..2db83eb
--- /dev/null
+++ b/include/linux/prctl_network.h
@@ -0,0 +1,7 @@
+#ifndef _LINUX_PRCTL_NETWORK_H
+#define _LINUX_PRCTL_NETWORK_H
+
+extern long prctl_get_network(void);
+extern long prctl_set_network(unsigned long);
+
+#endif /* _LINUX_PRCTL_NETWORK_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 5c858f3..751d372 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1395,6 +1395,8 @@ struct task_struct {
unsigned int sessionid;
#endif
seccomp_t seccomp;
+/* Flags for limiting networking via prctl(PR_SET_NETWORK). */
+ unsigned long network;
/* Thread group tracking */
u32 parent_exec_id;
diff --git a/kernel/sys.c b/kernel/sys.c
index 20ccfb5..411a2ff 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -35,6 +35,7 @@
#include <linux/cpu.h>
#include <linux/ptrace.h>
#include <linux/fs_struct.h>
+#include <linux/prctl_network.h>
#include <linux/compat.h>
#include <linux/syscalls.h>
@@ -1576,6 +1577,12 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
else
error = PR_MCE_KILL_DEFAULT;
break;
+ case PR_SET_NETWORK:
+ error = prctl_set_network(arg2);
+ break;
+ case PR_GET_NETWORK:
+ error = prctl_get_network();
+ break;
default:
error = -EINVAL;
break;
@@ -1583,6 +1590,31 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
return error;
}
+long prctl_get_network(void)
+{
+ return current->network;
+}
+
+long prctl_set_network(unsigned long network_flags)
+{
+ long ret;
+
+ /* only dropping access is permitted */
+ ret = -EPERM;
+ if (current->network & ~network_flags)
+ goto out;
+
+ ret = -EINVAL;
+ if (network_flags & ~PR_NETWORK_ALL_FLAGS)
+ goto out;
+
+ current->network = network_flags;
+ ret = 0;
+
+out:
+ return ret;
+}
+
SYSCALL_DEFINE3(getcpu, unsigned __user *, cpup, unsigned __user *, nodep,
struct getcpu_cache __user *, unused)
{
--
1.6.6.rc1
^ permalink raw reply related [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v2)
2009-12-18 3:29 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v2) Michael Stone
@ 2009-12-18 4:43 ` Valdis.Kletnieks
2009-12-18 15:46 ` Alan Cox
1 sibling, 0 replies; 35+ messages in thread
From: Valdis.Kletnieks @ 2009-12-18 4:43 UTC (permalink / raw)
To: Michael Stone
Cc: Mark Seaborn, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Bryan Donlan, Evgeniy Polyakov, C. Scott Ananian, James Morris,
Eric W. Biederman, Bernie Innocenti, Randy Dunlap,
Américo Wang
[-- Attachment #1: Type: text/plain, Size: 850 bytes --]
On Thu, 17 Dec 2009 22:29:57 EST, Michael Stone said:
> Daniel Bernstein has observed [1] that security-conscious userland processes
> may benefit from the ability to irrevocably remove their ability to create,
> bind, connect to, or send messages except in the case of previously connected
> sockets or AF_UNIX filesystem sockets. We provide this facility by implementing
> support for a new prctl(PR_SET_NETWORK) flag named PR_NETWORK_OFF.
Dan does indeed have a point - but is this better achieved via either
the already-existing LSM interfaces (opening the stacking-LSM can of worms
again), or the SECCOMP framework? We already have 2 other ways to turn off
stuff, do we really want a third way?
Alternatively, could a more generalized prctl interface be leveraged to handle
SECCOMP, and/or other targeted things that want to stack with LSM?
[-- Attachment #2: Type: application/pgp-signature, Size: 227 bytes --]
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v2)
2009-12-18 3:29 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v2) Michael Stone
2009-12-18 4:43 ` Valdis.Kletnieks
@ 2009-12-18 15:46 ` Alan Cox
2009-12-18 16:33 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) Michael Stone
1 sibling, 1 reply; 35+ messages in thread
From: Alan Cox @ 2009-12-18 15:46 UTC (permalink / raw)
To: Michael Stone
Cc: Mark Seaborn, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Randy Dunlap, Américo Wang, Michael Stone
On Thu, 17 Dec 2009 22:29:57 -0500
Michael Stone <michael@laptop.org> wrote:
> Daniel Bernstein has observed [1] that security-conscious userland processes
Dan Bernstein has observed many things .. ;)
> may benefit from the ability to irrevocably remove their ability to create,
> bind, connect to, or send messages except in the case of previously connected
> sockets or AF_UNIX filesystem sockets. We provide this facility by implementing
> support for a new prctl(PR_SET_NETWORK) flag named PR_NETWORK_OFF.
This is a security model, it belongs as a security model using LSM. You
can already do it with SELinux and the like as far as I can see but
that's not to say you shouldn't submit it also as a small handy
standalone security module for people who don't want to load the big
security modules.
Otherwise you end up putting crap in fast paths that nobody needs but
everyone pays for and weird tests and hacks for address family and like
into core network code.
The fact the patches look utterly ugly should be telling you something -
which is that you are using the wrong hammer
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK)
2009-12-18 15:46 ` Alan Cox
@ 2009-12-18 16:33 ` Michael Stone
2009-12-18 17:20 ` Alan Cox
` (2 more replies)
0 siblings, 3 replies; 35+ messages in thread
From: Michael Stone @ 2009-12-18 16:33 UTC (permalink / raw)
To: Alan Cox
Cc: Michael Stone, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang
Alan Cox wrote:
> This is a security model, it belongs as a security model using LSM.
I'll see what I can cook up for you.
However, please don't be surprised when the resulting cover letter states that
the LSM-based version *does not* resolve the situation to my satisfaction as a
userland hacker due to the well-known and long-standing adoption and
compositionality problems facing small LSMs. ;)
Regards,
Michael
P.S. - Dan is cited in my patch because I wish to honor him for anticipating my
desires early, clearly, and in writing. However, if you know of an earlier
citation, then I'll be happy to include that one too.
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK)
2009-12-18 16:33 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) Michael Stone
@ 2009-12-18 17:20 ` Alan Cox
2009-12-18 17:47 ` Eric W. Biederman
2009-12-24 1:42 ` [PATCH 0/3] Discarding networking privilege via LSM Michael Stone
2009-12-25 17:09 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) Pavel Machek
2 siblings, 1 reply; 35+ messages in thread
From: Alan Cox @ 2009-12-18 17:20 UTC (permalink / raw)
To: Michael Stone
Cc: Michael Stone, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang
> the LSM-based version *does not* resolve the situation to my satisfaction as a
> userland hacker due to the well-known and long-standing adoption and
> compositionality problems facing small LSMs. ;)
For things like Fedora it's probably an "interesting idea, perhaps we
should do it using SELinux" sort of problem, but a config option for a
magic network prctl is also going to be hard to adopt without producing a
good use case - and avoiding that by dumping crap into everyones kernel
fast paths isn't a good idea either.
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK)
2009-12-18 17:20 ` Alan Cox
@ 2009-12-18 17:47 ` Eric W. Biederman
2009-12-24 6:13 ` Michael Stone
0 siblings, 1 reply; 35+ messages in thread
From: Eric W. Biederman @ 2009-12-18 17:47 UTC (permalink / raw)
To: Michael Stone
Cc: linux-kernel, Alan Cox, netdev, linux-security-module, Andi Kleen,
David Lang, Oliver Hartkopp, Herbert Xu, Valdis Kletnieks,
Bryan Donlan, Evgeniy Polyakov, C. Scott Ananian, James Morris,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang
Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
>> the LSM-based version *does not* resolve the situation to my satisfaction as a
>> userland hacker due to the well-known and long-standing adoption and
>> compositionality problems facing small LSMs. ;)
>
> For things like Fedora it's probably an "interesting idea, perhaps we
> should do it using SELinux" sort of problem, but a config option for a
> magic network prctl is also going to be hard to adopt without producing a
> good use case - and avoiding that by dumping crap into everyones kernel
> fast paths isn't a good idea either.
If I understand the problem the goal is to disable access to ipc
mechanism that don't have the usual unix permissions. To get
something that is usable for non-root processes, and to get something
that is widely deployed so you don't have to jump through hoops in
end user applications to use it.
We have widely deployed mechanisms that are what you want or nearly
what you want already in the form of the various namespaces built for
containers.
I propose you introduce a permanent disable of executing suid
applications.
After which point it is another trivial patch to allow unsharing of
the network namespace if executing suid applications are disabled.
Eric
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK)
2009-12-18 17:47 ` Eric W. Biederman
@ 2009-12-24 6:13 ` Michael Stone
2009-12-24 12:37 ` Eric W. Biederman
0 siblings, 1 reply; 35+ messages in thread
From: Michael Stone @ 2009-12-24 6:13 UTC (permalink / raw)
To: Eric W. Biederman
Cc: linux-kernel, netdev, linux-security-module, Andi Kleen,
David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang,
Michael Stone
> Eric Biederman writes:
>> Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
>>> Michael Stone writes:
>>>> the LSM-based version *does not* resolve the situation to my satisfaction as a
>>>> userland hacker due to the well-known and long-standing adoption and
>>>> compositionality problems facing small LSMs. ;)
>>>
>>> For things like Fedora it's probably an "interesting idea, perhaps we
>>> should do it using SELinux" sort of problem, but a config option for a
>>> magic network prctl is also going to be hard to adopt without producing a
>>> good use case - and avoiding that by dumping crap into everyones kernel
>>> fast paths isn't a good idea either.
>
>If I understand the problem the goal is to disable access to ipc
>mechanism that don't have the usual unix permissions. To get
>something that is usable for non-root processes, and to get something
>that is widely deployed so you don't have to jump through hoops in
>end user applications to use it.
Eric,
You understand correctly. Thank you for this cogent restatement.
>We have widely deployed mechanisms that are what you want or nearly
>what you want already in the form of the various namespaces built for
>containers.
It's true that your work is closer to what I want than anything else that I've
seen so far...
>I propose you introduce a permanent disable of executing suid
>applications.
I'm open to the idea but I don't understand the need that motivates it yet.
Could you please explain further? (or point me to an existing explanation?)
>After which point it is another trivial patch to allow unsharing of
>the network namespace if executing suid applications are disabled.
How do you propose to address the problem with the Unix sockets?
Regards,
Michael
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK)
2009-12-24 6:13 ` Michael Stone
@ 2009-12-24 12:37 ` Eric W. Biederman
0 siblings, 0 replies; 35+ messages in thread
From: Eric W. Biederman @ 2009-12-24 12:37 UTC (permalink / raw)
To: Michael Stone
Cc: linux-kernel, netdev, linux-security-module, Andi Kleen,
David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Bernie Innocenti, Mark Seaborn,
Randy Dunlap, Américo Wang
Michael Stone <michael@laptop.org> writes:
>> Eric Biederman writes:
>>> Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
>>>> Michael Stone writes:
>>>>> the LSM-based version *does not* resolve the situation to my satisfaction as a
>>>>> userland hacker due to the well-known and long-standing adoption and
>>>>> compositionality problems facing small LSMs. ;)
>>>>
>>>> For things like Fedora it's probably an "interesting idea, perhaps we
>>>> should do it using SELinux" sort of problem, but a config option for a
>>>> magic network prctl is also going to be hard to adopt without producing a
>>>> good use case - and avoiding that by dumping crap into everyones kernel
>>>> fast paths isn't a good idea either.
>>
>>If I understand the problem the goal is to disable access to ipc
>>mechanism that don't have the usual unix permissions. To get
>>something that is usable for non-root processes, and to get something
>>that is widely deployed so you don't have to jump through hoops in
>>end user applications to use it.
>
> Eric,
>
> You understand correctly. Thank you for this cogent restatement.
>
>>We have widely deployed mechanisms that are what you want or nearly
>>what you want already in the form of the various namespaces built for
>>containers.
>
> It's true that your work is closer to what I want than anything else that I've
> seen so far...
>
>> I propose you introduce a permanent disable of executing suid applications.
>
> I'm open to the idea but I don't understand the need that motivates it yet.
> Could you please explain further? (or point me to an existing explanation?)
With namespaces it is possible to masquarade as a trusted source,
of information to a suid program such as /etc/passwd or a NIS server.
A one-way removal of the ability to exec suid programs is generally
simple and handy like chroot, and removes the need for CAP_SYS_ADMIN
in most cases.
Plan 9 did not support suid executables and supported an unprivileged
equivalent of unshare(NEWNS).
I need the full unprivileged unshare of USERNS for my primary
uses today as I need to perform normally root only activities
like mounting loopback devices, and setting up networking. Your
uses of limiting of ipc do not appear to require that.
>>After which point it is another trivial patch to allow unsharing of
>>the network namespace if executing suid applications are disabled.
>
> How do you propose to address the problem with the Unix sockets?
Careful code review of the patch to allow talking between network
namespaces with unix domain sockets. This is a feature that we
simply have not merged yet. Semantically it is fine today. It is
simply no one has answered the question what other implications
could there be. Now that I know of 2 or 3 compelling use
cases and most of the rest of the work done. It seems time to
relax the restriction.
Eric
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 0/3] Discarding networking privilege via LSM
2009-12-18 16:33 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) Michael Stone
2009-12-18 17:20 ` Alan Cox
@ 2009-12-24 1:42 ` Michael Stone
2009-12-24 1:44 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v3) Michael Stone
` (2 more replies)
2009-12-25 17:09 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) Pavel Machek
2 siblings, 3 replies; 35+ messages in thread
From: Michael Stone @ 2009-12-24 1:42 UTC (permalink / raw)
To: Alan Cox
Cc: Michael Stone, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang
Alan,
As you requested, here's a (rough) draft of my patch series which uses the
security_* hooks instead of direct modification of the networking functions.
Have you further suggestions for improvement?
Regards,
Michael
P.S. - The most notable behavioral difference between this patch and the
previous one is that abstract unix sockets are exempted from control in this
patch but are restricted by the previous one. We can revisit this detail in
subsequent patches if this approach seems viable.
Michael Stone (3):
Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v3)
Security: Implement prctl(PR_SET_NETWORK, PR_NETWORK_OFF) semantics. (v3)
Security: Document prctl(PR_{GET,SET}_NETWORK). (v3)
Documentation/prctl/network.txt | 74 ++++++++++++++++++++++++++
include/linux/prctl.h | 7 +++
include/linux/prctl_network.h | 7 +++
include/linux/sched.h | 2 +
kernel/sys.c | 32 +++++++++++
security/Kconfig | 13 +++++
security/Makefile | 1 +
security/prctl_network.c | 110 +++++++++++++++++++++++++++++++++++++++
8 files changed, 246 insertions(+), 0 deletions(-)
create mode 100644 Documentation/prctl/network.txt
create mode 100644 include/linux/prctl_network.h
create mode 100644 security/prctl_network.c
^ permalink raw reply [flat|nested] 35+ messages in thread* [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v3)
2009-12-24 1:42 ` [PATCH 0/3] Discarding networking privilege via LSM Michael Stone
@ 2009-12-24 1:44 ` Michael Stone
2009-12-24 4:38 ` Samir Bellabes
2009-12-24 1:45 ` [PATCH 2/3] Security: Implement prctl(PR_SET_NETWORK, PR_NETWORK_OFF) semantics. (v3) Michael Stone
2009-12-24 1:45 ` [PATCH 3/3] Security: Document prctl(PR_{GET,SET}_NETWORK). (v3) Michael Stone
2 siblings, 1 reply; 35+ messages in thread
From: Michael Stone @ 2009-12-24 1:44 UTC (permalink / raw)
To: Alan Cox
Cc: Michael Stone, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang
Daniel Bernstein has observed [1] that security-conscious userland processes
may benefit from the ability to irrevocably remove their ability to create,
bind, connect to, or send messages except in the case of previously connected
sockets or AF_UNIX filesystem sockets. We provide this facility via a new
prctl option-pair (PR_SET_NETWORK, PR_GET_NETWORK) and a new
prctl(PR_SET_NETWORK) flag named PR_NETWORK_OFF.
This facility is particularly attractive to security platforms like OLPC
Bitfrost [2] and to isolation programs like Rainbow [3] and Plash [4].
[1]: http://cr.yp.to/unix/disablenetwork.html
[2]: http://wiki.laptop.org/go/OLPC_Bitfrost
[3]: http://wiki.laptop.org/go/Rainbow
[4]: http://plash.beasts.org/
Signed-off-by: Michael Stone <michael@laptop.org>
---
include/linux/prctl.h | 7 +++++++
include/linux/prctl_network.h | 7 +++++++
include/linux/sched.h | 2 ++
kernel/sys.c | 32 ++++++++++++++++++++++++++++++++
4 files changed, 48 insertions(+), 0 deletions(-)
create mode 100644 include/linux/prctl_network.h
diff --git a/include/linux/prctl.h b/include/linux/prctl.h
index a3baeb2..4eb4110 100644
--- a/include/linux/prctl.h
+++ b/include/linux/prctl.h
@@ -102,4 +102,11 @@
#define PR_MCE_KILL_GET 34
+/* Get/set process disable-network flags */
+#define PR_SET_NETWORK 35
+#define PR_GET_NETWORK 36
+# define PR_NETWORK_ON 0
+# define PR_NETWORK_OFF 1
+# define PR_NETWORK_ALL_FLAGS 1
+
#endif /* _LINUX_PRCTL_H */
diff --git a/include/linux/prctl_network.h b/include/linux/prctl_network.h
new file mode 100644
index 0000000..2db83eb
--- /dev/null
+++ b/include/linux/prctl_network.h
@@ -0,0 +1,7 @@
+#ifndef _LINUX_PRCTL_NETWORK_H
+#define _LINUX_PRCTL_NETWORK_H
+
+extern long prctl_get_network(void);
+extern long prctl_set_network(unsigned long);
+
+#endif /* _LINUX_PRCTL_NETWORK_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index f2f842d..0c65c55 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1402,6 +1402,8 @@ struct task_struct {
unsigned int sessionid;
#endif
seccomp_t seccomp;
+/* Flags for limiting networking via prctl(PR_SET_NETWORK). */
+ unsigned long network;
/* Thread group tracking */
u32 parent_exec_id;
diff --git a/kernel/sys.c b/kernel/sys.c
index 26a6b73..e7d345c 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -35,6 +35,7 @@
#include <linux/cpu.h>
#include <linux/ptrace.h>
#include <linux/fs_struct.h>
+#include <linux/prctl_network.h>
#include <linux/compat.h>
#include <linux/syscalls.h>
@@ -1578,6 +1579,12 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
else
error = PR_MCE_KILL_DEFAULT;
break;
+ case PR_SET_NETWORK:
+ error = prctl_set_network(arg2);
+ break;
+ case PR_GET_NETWORK:
+ error = prctl_get_network();
+ break;
default:
error = -EINVAL;
break;
@@ -1585,6 +1592,31 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
return error;
}
+long prctl_get_network(void)
+{
+ return current->network;
+}
+
+long prctl_set_network(unsigned long network_flags)
+{
+ long ret;
+
+ /* only dropping access is permitted */
+ ret = -EPERM;
+ if (current->network & ~network_flags)
+ goto out;
+
+ ret = -EINVAL;
+ if (network_flags & ~PR_NETWORK_ALL_FLAGS)
+ goto out;
+
+ current->network = network_flags;
+ ret = 0;
+
+out:
+ return ret;
+}
+
SYSCALL_DEFINE3(getcpu, unsigned __user *, cpup, unsigned __user *, nodep,
struct getcpu_cache __user *, unused)
{
--
1.6.6.rc1
^ permalink raw reply related [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v3)
2009-12-24 1:44 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v3) Michael Stone
@ 2009-12-24 4:38 ` Samir Bellabes
2009-12-24 5:44 ` Michael Stone
2009-12-24 5:51 ` Tetsuo Handa
0 siblings, 2 replies; 35+ messages in thread
From: Samir Bellabes @ 2009-12-24 4:38 UTC (permalink / raw)
To: Michael Stone
Cc: Alan Cox, linux-kernel, netdev, linux-security-module, Andi Kleen,
David Lang, Oliver Hartkopp, Herbert Xu, Valdis Kletnieks,
Bryan Donlan, Evgeniy Polyakov, C. Scott Ananian, James Morris,
Eric W. Biederman, Bernie Innocenti, Mark Seaborn, Randy Dunlap,
Américo Wang
Michael Stone <michael@laptop.org> writes:
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index f2f842d..0c65c55 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -1402,6 +1402,8 @@ struct task_struct {
> unsigned int sessionid;
> #endif
> seccomp_t seccomp;
> +/* Flags for limiting networking via prctl(PR_SET_NETWORK). */
> + unsigned long network;
>
> /* Thread group tracking */
> u32 parent_exec_id;
I think this is unnecessary, as LSM module, you should use the
void* security member of the structure cred.
this member allows you to mark task_struct as you which, it's a kind of
abstraction provided to all security modules.
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v3)
2009-12-24 4:38 ` Samir Bellabes
@ 2009-12-24 5:44 ` Michael Stone
2009-12-24 5:51 ` Tetsuo Handa
1 sibling, 0 replies; 35+ messages in thread
From: Michael Stone @ 2009-12-24 5:44 UTC (permalink / raw)
To: Samir Bellabes
Cc: Michael Stone, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang
> I think this is unnecessary, as LSM module, you should use the
> void* security member of the structure cred.
The change you propose is easily made but I'm having trouble seeing how making
it would help my purpose: the field you name is already in use by other parts
of the kernel which my functionality is intended to complement.
That being said, I'd be very happy to prepare a version of the patch using the
strategy you suggest if it would be directly useful to you or if you can show
me how it would contribute to my goals.
Regards, and thanks for your comment,
Michael
P.S. - Perhaps a reasonable alternative would be to the definition of the field
conditional on CONFIGURE_SECURITY_PRCTL_NETWORK?
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v3)
2009-12-24 4:38 ` Samir Bellabes
2009-12-24 5:44 ` Michael Stone
@ 2009-12-24 5:51 ` Tetsuo Handa
1 sibling, 0 replies; 35+ messages in thread
From: Tetsuo Handa @ 2009-12-24 5:51 UTC (permalink / raw)
To: sam
Cc: alan, linux-kernel, netdev, linux-security-module, andi, david,
socketcan, herbert, Valdis.Kletnieks, bdonlan, zbr, cscott,
jmorris, ebiederm, bernie, mrs, randy.dunlap, xiyou.wangcong,
michael
Samir Bellabes wrote:
> > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > index f2f842d..0c65c55 100644
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -1402,6 +1402,8 @@ struct task_struct {
> > unsigned int sessionid;
> > #endif
> > seccomp_t seccomp;
> > +/* Flags for limiting networking via prctl(PR_SET_NETWORK). */
> > + unsigned long network;
> >
> > /* Thread group tracking */
> > u32 parent_exec_id;
>
> I think this is unnecessary, as LSM module, you should use the
> void* security member of the structure cred.
>
> this member allows you to mark task_struct as you which, it's a kind of
> abstraction provided to all security modules.
I want to use per task_struct variable. Since cred is copy-on-write, we have to
use kmalloc()/kfree() whenever we modify variable in cred. That introduces
unnwanted error paths (i.e. memory allocation failure) and overhead.
Old version of TOMOYO had similar mechanism that allows userland programs to
disable specific operations (disable chroot(), disable execve(), disable
mount() etc. ; which is different from POSIX capabilities).
I added "unsigned int dropped_capability;" to task_struct for implementing it.
Adding variables to task_struct makes it possible to error-path-free.
I prefer adding "void *security;" to task_struct which is duplicated upon fork() and
released upon exit().
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 2/3] Security: Implement prctl(PR_SET_NETWORK, PR_NETWORK_OFF) semantics. (v3)
2009-12-24 1:42 ` [PATCH 0/3] Discarding networking privilege via LSM Michael Stone
2009-12-24 1:44 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v3) Michael Stone
@ 2009-12-24 1:45 ` Michael Stone
2009-12-24 1:45 ` [PATCH 3/3] Security: Document prctl(PR_{GET,SET}_NETWORK). (v3) Michael Stone
2 siblings, 0 replies; 35+ messages in thread
From: Michael Stone @ 2009-12-24 1:45 UTC (permalink / raw)
To: Alan Cox
Cc: Michael Stone, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang
Implement security_* hooks for socket_create, socket_bind, socket_connect,
socket_sendmsg, and ptrace_access_check which return -EPERM when called from a
process with networking restrictions. Exempt AF_UNIX sockets.
Signed-off-by: Michael Stone <michael@laptop.org>
---
security/Kconfig | 13 +++++
security/Makefile | 1 +
security/prctl_network.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 124 insertions(+), 0 deletions(-)
create mode 100644 security/prctl_network.c
diff --git a/security/Kconfig b/security/Kconfig
index 226b955..740a7fe 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -137,6 +137,19 @@ config LSM_MMAP_MIN_ADDR
this low address space will need the permission specific to the
systems running LSM.
+config SECURITY_PRCTL_NETWORK
+ tristate "prctl(PR_{GET,SET}_NETWORK) support"
+ depends on SECURITY_NETWORK
+ help
+ This enables processes to drop networking privileges via
+ prctl(PR_SET_NETWORK, PR_NETWORK_OFF), which is used by OLPC's isolation
+ shell, <http://wiki.laptop.org/go/Rainbow> to implement discretionary
+ network isolation.
+
+ See Documentation/prctl/network.txt for more information about this LSM.
+
+ If you are unsure how to answer this question, answer N.
+
source security/selinux/Kconfig
source security/smack/Kconfig
source security/tomoyo/Kconfig
diff --git a/security/Makefile b/security/Makefile
index da20a19..92ce65d 100644
--- a/security/Makefile
+++ b/security/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o
obj-$(CONFIG_AUDIT) += lsm_audit.o
obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/built-in.o
obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o
+obj-$(CONFIG_SECURITY_PRCTL_NETWORK) += prctl_network.o
# Object integrity file lists
subdir-$(CONFIG_IMA) += integrity/ima
diff --git a/security/prctl_network.c b/security/prctl_network.c
new file mode 100644
index 0000000..2da6051
--- /dev/null
+++ b/security/prctl_network.c
@@ -0,0 +1,110 @@
+/*
+ * prctl_network LSM.
+ *
+ * Copyright (C) 2008-2009 Michael Stone <michael@laptop.org>
+ * Based on sample code from security/root_plug.c, (C) 2002 Greg Kroah-Hartman.
+ *
+ * Implements the prctl(PR_SET_NETWORK, PR_NETWORK_OFF) syscall.
+ *
+ * See Documentation/prctl/network.txt for more information about this code.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2 of the
+ * License.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <net/sock.h>
+#include <linux/socket.h>
+#include <linux/security.h>
+
+static inline int maybe_allow(void)
+{
+ if (current->network)
+ return -EPERM;
+ return 0;
+}
+
+static inline int prctl_network_socket_create_hook (int family, int type,
+ int protocol, int kern)
+{
+ if (family == AF_UNIX)
+ return 0;
+ return maybe_allow();
+}
+
+static inline int prctl_network_socket_bind_hook(struct socket * sock,
+ struct sockaddr * address,
+ int addrlen)
+{
+ if (address->sa_family == AF_UNIX)
+ return 0;
+ return maybe_allow();
+}
+
+static inline int prctl_network_socket_connect_hook(struct socket * sock,
+ struct sockaddr * address,
+ int addrlen)
+{
+ if (address->sa_family == AF_UNIX)
+ return 0;
+ return maybe_allow();
+}
+
+static inline int prctl_network_socket_sendmsg_hook(struct socket * sock,
+ struct msghdr * msg, int size)
+{
+ if (sock->sk->sk_family != PF_UNIX &&
+ current->network &&
+ (msg->msg_name != NULL || msg->msg_namelen != 0))
+ return -EPERM;
+ return 0;
+}
+
+static inline int prctl_network_ptrace_access_check_hook(struct task_struct *child, unsigned int mode)
+{
+ /* does current have networking restrictions not shared by child? */
+ if (current->network & ~child->network)
+ return -EPERM;
+ return 0;
+}
+
+/* static inline int prctl_network_ptrace_traceme(struct task_struct *parent) ? */
+
+static struct security_operations prctl_network_security_ops = {
+ .name = "prctl_net",
+ .socket_create = prctl_network_socket_create_hook,
+ .socket_bind = prctl_network_socket_bind_hook,
+ .socket_connect = prctl_network_socket_connect_hook,
+ .socket_sendmsg = prctl_network_socket_sendmsg_hook,
+ .ptrace_access_check = prctl_network_ptrace_access_check_hook,
+};
+
+static int __init prctl_network_security_init (void)
+{
+ if (!security_module_enable(&prctl_network_security_ops)) {
+ printk (KERN_INFO
+ "Failure enabling prctl_network_lsm.\n");
+ return 0;
+ }
+
+ /* register ourselves with the security framework */
+ if (register_security (&prctl_network_security_ops)) {
+ printk (KERN_INFO
+ "Failure registering prctl_network_lsm with the kernel\n");
+ return 0;
+ }
+
+ printk (KERN_INFO "prctl_network_lsm initialized\n");
+
+ return 0;
+}
+
+security_initcall (prctl_network_security_init);
+
+MODULE_DESCRIPTION("prctl_network LSM; implementing prctl(PR_SET_NETWORK, PR_NETWORK_OFF).");
+MODULE_LICENSE("GPL");
--
1.6.6.rc1
^ permalink raw reply related [flat|nested] 35+ messages in thread* [PATCH 3/3] Security: Document prctl(PR_{GET,SET}_NETWORK). (v3)
2009-12-24 1:42 ` [PATCH 0/3] Discarding networking privilege via LSM Michael Stone
2009-12-24 1:44 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v3) Michael Stone
2009-12-24 1:45 ` [PATCH 2/3] Security: Implement prctl(PR_SET_NETWORK, PR_NETWORK_OFF) semantics. (v3) Michael Stone
@ 2009-12-24 1:45 ` Michael Stone
2 siblings, 0 replies; 35+ messages in thread
From: Michael Stone @ 2009-12-24 1:45 UTC (permalink / raw)
To: Alan Cox
Cc: Michael Stone, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang
Explain the purpose, interface, and semantics of the
prctl(PR_{GET,SET}_network) facility and LSM.
Also reference some example userland clients.
Signed-off-by: Michael Stone <michael@laptop.org>
---
Documentation/prctl/network.txt | 74 +++++++++++++++++++++++++++++++++++++++
1 files changed, 74 insertions(+), 0 deletions(-)
create mode 100644 Documentation/prctl/network.txt
diff --git a/Documentation/prctl/network.txt b/Documentation/prctl/network.txt
new file mode 100644
index 0000000..8b45d23
--- /dev/null
+++ b/Documentation/prctl/network.txt
@@ -0,0 +1,74 @@
+Purpose
+-------
+
+Daniel Bernstein has observed [1] that security-conscious userland processes
+may benefit from the ability to irrevocably remove their ability to create,
+bind, connect to, or send messages except in the case of previously connected
+sockets or AF_UNIX filesystem sockets.
+
+This facility is particularly attractive to security platforms like OLPC
+Bitfrost [2] and to isolation programs like Rainbow [3] and Plash [4] because:
+
+ * it integrates well with standard techniques for writing privilege-separated
+ Unix programs
+
+ * it integrates well with the need to perform limited socket I/O, e.g., when
+ running X clients
+
+ * it's available to unprivileged programs
+
+ * it's a discretionary feature available to all of distributors,
+ administrators, authors, and users
+
+ * its effect is entirely local, rather than global (like netfilter)
+
+ * it's simple enough to have some hope of being used correctly
+
+Implementation
+--------------
+
+After considering implementations based on the Linux Security Module (LSM)
+framework, on SELinux, on network namespaces (CLONE_NEWNET), on direct
+modification of the kernel syscall and task_struct APIs and after seeking
+advice from members of LKML, we came to the conclusion that the best way to
+implement this feature was to extend the prctl() framework with a new pair of
+options named PR_{GET,SET}_NETWORK and to write an LSM to implement the
+resulting PR_NETWORK_OFF semantics. These options cause prctl() to read or
+modify "current->network".
+
+Semantics
+---------
+
+current->network is a flags field which is preserved across all variants of
+fork() and exec().
+
+Writes which attempt to clear bits in current->network return -EPERM.
+
+The default value for current->network is named PR_NETWORK_ON and is defined
+to be 0.
+
+Presently, only one flag is defined: PR_NETWORK_OFF.
+
+More flags may be defined in the future if they become needed.
+
+Attempts to set undefined flags result in -EINVAL.
+
+When PR_NETWORK_OFF is set, implementations of syscalls which may be used by
+the current process to perform autonomous networking will return -EPERM. For
+example, calls to socket(), bind(), connect(), sendmsg(), and ptrace() will
+return -EPERM except for cases we are manipulating an AF_UNIX socket or, in the
+case of sendmsg(), unless we are manipulating a previously connected socket,
+i.e. one with
+
+ msg.msg_name == NULL && msg.msg_namelen == 0
+
+or, in the case of ptrace(), unless we are ptracing() a process which has all
+of our own networking restriction flags set.
+
+References
+----------
+
+[1]: http://cr.yp.to/unix/disablenetwork.html
+[2]: http://wiki.laptop.org/go/OLPC_Bitfrost
+[3]: http://wiki.laptop.org/go/Rainbow
+[4]: http://plash.beasts.org/
--
1.6.6.rc1
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK)
2009-12-18 16:33 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) Michael Stone
2009-12-18 17:20 ` Alan Cox
2009-12-24 1:42 ` [PATCH 0/3] Discarding networking privilege via LSM Michael Stone
@ 2009-12-25 17:09 ` Pavel Machek
2 siblings, 0 replies; 35+ messages in thread
From: Pavel Machek @ 2009-12-25 17:09 UTC (permalink / raw)
To: Michael Stone
Cc: Alan Cox, linux-kernel, netdev, linux-security-module, Andi Kleen,
David Lang, Oliver Hartkopp, Herbert Xu, Valdis Kletnieks,
Bryan Donlan, Evgeniy Polyakov, C. Scott Ananian, James Morris,
Eric W. Biederman, Bernie Innocenti, Mark Seaborn, Randy Dunlap,
Am?rico Wang
On Fri 2009-12-18 11:33:48, Michael Stone wrote:
> Alan Cox wrote:
>
>> This is a security model, it belongs as a security model using LSM.
>
> I'll see what I can cook up for you.
>
> However, please don't be surprised when the resulting cover letter states that
> the LSM-based version *does not* resolve the situation to my satisfaction as a
> userland hacker due to the well-known and long-standing adoption and
> compositionality problems facing small LSMs. ;)
Maybe it is time to fix the LSM? This excuse is much too common...
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 2/3] Security: Implement prctl(PR_SET_NETWORK, PR_NETWORK_OFF) semantics. (v2)
2009-12-18 3:00 ` Michael Stone
2009-12-18 3:29 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v2) Michael Stone
@ 2009-12-18 3:31 ` Michael Stone
2009-12-18 3:57 ` Eric W. Biederman
2009-12-18 3:32 ` [PATCH 3/3] Security: Document prctl(PR_{GET,SET}_NETWORK). (v2) Michael Stone
` (2 subsequent siblings)
4 siblings, 1 reply; 35+ messages in thread
From: Michael Stone @ 2009-12-18 3:31 UTC (permalink / raw)
To: Mark Seaborn
Cc: linux-kernel, netdev, linux-security-module, Andi Kleen,
David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang,
Michael Stone
Return -EPERM any time we try to __sock_create(), sys_connect(), sys_bind(),
sys_sendmsg(), or __ptrace_may_access() from a process with PR_NETWORK_OFF set
in current->network unless we're working on a socket which is already connected
or on a non-abstract AF_UNIX socket.
Signed-off-by: Michael Stone <michael@laptop.org>
---
kernel/fork.c | 2 ++
kernel/ptrace.c | 3 +++
kernel/sys.c | 2 +-
net/socket.c | 51 ++++++++++++++++++++++++++++++++++++++-------------
net/unix/af_unix.c | 19 +++++++++++++++++++
5 files changed, 63 insertions(+), 14 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 9bd9144..01a7644 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1130,6 +1130,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
p->bts = NULL;
+ p->network = current->network;
+
p->stack_start = stack_start;
/* Perform scheduler related setup. Assign this task to a CPU. */
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 23bd09c..bcf87ba 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -151,6 +151,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
dumpable = get_dumpable(task->mm);
if (!dumpable && !capable(CAP_SYS_PTRACE))
return -EPERM;
+ /* does current have networking restrictions not shared by task? */
+ if (current->network & ~task->network)
+ return -EPERM;
return security_ptrace_access_check(task, mode);
}
diff --git a/kernel/sys.c b/kernel/sys.c
index 411a2ff..481fa9c 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1601,7 +1601,7 @@ long prctl_set_network(unsigned long network_flags)
/* only dropping access is permitted */
ret = -EPERM;
- if (current->network & ~network_flags)
+ if (current->network & ~network_flags)
goto out;
ret = -EINVAL;
diff --git a/net/socket.c b/net/socket.c
index b94c3dd..e59f906 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -87,6 +87,7 @@
#include <linux/wireless.h>
#include <linux/nsproxy.h>
#include <linux/magic.h>
+#include <linux/sched.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
@@ -576,6 +577,12 @@ static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
if (err)
return err;
+ err = -EPERM;
+ if (sock->sk->sk_family != AF_UNIX &&
+ current->network &&
+ (msg->msg_name != NULL || msg->msg_namelen != 0))
+ return err;
+
return sock->ops->sendmsg(iocb, sock, msg, size);
}
@@ -1227,6 +1234,9 @@ static int __sock_create(struct net *net, int family, int type, int protocol,
if (err)
return err;
+ if (family != AF_UNIX && current->network)
+ return -EPERM;
+
/*
* Allocate the socket and allow the family to set things up. if
* the protocol is 0, the family is instructed to select an appropriate
@@ -1465,19 +1475,29 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
int err, fput_needed;
sock = sockfd_lookup_light(fd, &err, &fput_needed);
- if (sock) {
- err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
- if (err >= 0) {
- err = security_socket_bind(sock,
- (struct sockaddr *)&address,
- addrlen);
- if (!err)
- err = sock->ops->bind(sock,
- (struct sockaddr *)
- &address, addrlen);
- }
- fput_light(sock->file, fput_needed);
- }
+ if (!sock)
+ goto out;
+
+ err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
+ if (err < 0)
+ goto out_fput;
+
+ err = security_socket_bind(sock,
+ (struct sockaddr *)&address,
+ addrlen);
+ if (err)
+ goto out_fput;
+
+ err = (((struct sockaddr *)&address)->sa_family != AF_UNIX &&
+ current->network) ? -EPERM : 0;
+ if (err)
+ goto out_fput;
+
+ err = sock->ops->bind(sock, (struct sockaddr *) &address, addrlen);
+
+out_fput:
+ fput_light(sock->file, fput_needed);
+out:
return err;
}
@@ -1639,6 +1659,11 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
if (err)
goto out_put;
+ err = (((struct sockaddr *)&address)->sa_family != AF_UNIX &&
+ current->network) ? -EPERM : 0;
+ if (err)
+ goto out_put;
+
err = sock->ops->connect(sock, (struct sockaddr *)&address, addrlen,
sock->file->f_flags);
out_put:
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index f255119..5087ae3 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -797,6 +797,10 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
goto out;
addr_len = err;
+ err = (current->network && !sunaddr->sun_path[0]) ? -EPERM : 0;
+ if (err)
+ goto out;
+
mutex_lock(&u->readlock);
err = -EINVAL;
@@ -934,6 +938,10 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
goto out;
alen = err;
+ err = (current->network && !sunaddr->sun_path[0]) ? -EPERM : 0;
+ if (err)
+ goto out;
+
if (test_bit(SOCK_PASSCRED, &sock->flags) &&
!unix_sk(sk)->addr && (err = unix_autobind(sock)) != 0)
goto out;
@@ -1033,6 +1041,10 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
goto out;
addr_len = err;
+ err = (current->network && !sunaddr->sun_path[0]) ? -EPERM : 0;
+ if (err)
+ goto out;
+
if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr &&
(err = unix_autobind(sock)) != 0)
goto out;
@@ -1370,6 +1382,10 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
if (err < 0)
goto out;
namelen = err;
+
+ err = -EPERM;
+ if (current->network && !sunaddr->sun_path[0])
+ goto out;
} else {
sunaddr = NULL;
err = -ENOTCONN;
@@ -1520,6 +1536,9 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
if (msg->msg_namelen) {
err = sk->sk_state == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP;
goto out_err;
+ /* prctl(PR_SET_NETWORK) requires no change here since
+ * connection-less unix stream sockets are not supported.
+ * See Documentation/prctl/network.txt for details. */
} else {
sunaddr = NULL;
err = -ENOTCONN;
--
1.6.6.rc1
^ permalink raw reply related [flat|nested] 35+ messages in thread* Re: [PATCH 2/3] Security: Implement prctl(PR_SET_NETWORK, PR_NETWORK_OFF) semantics. (v2)
2009-12-18 3:31 ` [PATCH 2/3] Security: Implement prctl(PR_SET_NETWORK, PR_NETWORK_OFF) semantics. (v2) Michael Stone
@ 2009-12-18 3:57 ` Eric W. Biederman
0 siblings, 0 replies; 35+ messages in thread
From: Eric W. Biederman @ 2009-12-18 3:57 UTC (permalink / raw)
To: Michael Stone
Cc: Mark Seaborn, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Bernie Innocenti, Randy Dunlap,
Américo Wang
Michael Stone <michael@laptop.org> writes:
> Return -EPERM any time we try to __sock_create(), sys_connect(), sys_bind(),
> sys_sendmsg(), or __ptrace_may_access() from a process with PR_NETWORK_OFF set
> in current->network unless we're working on a socket which is already connected
> or on a non-abstract AF_UNIX socket.
It appears to me that the current security hooks are sufficient for what
you are doing.
The one true security module business prevents you from actually using the
security hooks, but could you create wrappers for the network security
hooks so the logic of the network stack does not need to change.
At the very least the huge separation of the test for AF_UNIX and
the test to see if it is a an anonymous AF_UNIX socket is pretty
large. Structuring the code in such a way as to keep that together would
be nice.
Eric
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH 3/3] Security: Document prctl(PR_{GET,SET}_NETWORK). (v2)
2009-12-18 3:00 ` Michael Stone
2009-12-18 3:29 ` [PATCH 1/3] Security: Add prctl(PR_{GET,SET}_NETWORK) interface. (v2) Michael Stone
2009-12-18 3:31 ` [PATCH 2/3] Security: Implement prctl(PR_SET_NETWORK, PR_NETWORK_OFF) semantics. (v2) Michael Stone
@ 2009-12-18 3:32 ` Michael Stone
2009-12-18 17:49 ` [PATCH] Security: Add prctl(PR_{GET,SET}_NETWORK) interface Stephen Hemminger
2009-12-20 17:53 ` Mark Seaborn
4 siblings, 0 replies; 35+ messages in thread
From: Michael Stone @ 2009-12-18 3:32 UTC (permalink / raw)
To: Mark Seaborn
Cc: linux-kernel, netdev, linux-security-module, Andi Kleen,
David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Mark Seaborn, Randy Dunlap, Américo Wang,
Michael Stone
Explain the purpose, interface, and semantics of the
prctl(PR_{GET,SET}_network) facility.
Also reference some example userland clients.
Signed-off-by: Michael Stone <michael@laptop.org>
---
Documentation/prctl/network.txt | 72 +++++++++++++++++++++++++++++++++++++++
1 files changed, 72 insertions(+), 0 deletions(-)
create mode 100644 Documentation/prctl/network.txt
diff --git a/Documentation/prctl/network.txt b/Documentation/prctl/network.txt
new file mode 100644
index 0000000..b337722
--- /dev/null
+++ b/Documentation/prctl/network.txt
@@ -0,0 +1,72 @@
+Purpose
+-------
+
+Daniel Bernstein has observed [1] that security-conscious userland processes
+may benefit from the ability to irrevocably remove their ability to create,
+bind, connect to, or send messages except in the case of previously connected
+sockets or AF_UNIX filesystem sockets.
+
+This facility is particularly attractive to security platforms like OLPC
+Bitfrost [2] and to isolation programs like Rainbow [3] and Plash [4] because:
+
+ * it integrates well with standard techniques for writing privilege-separated
+ Unix programs
+
+ * it integrates well with the need to perform limited socket I/O, e.g., when
+ running X clients
+
+ * it's available to unprivileged programs
+
+ * it's a discretionary feature available to all of distributors,
+ administrators, authors, and users
+
+ * its effect is entirely local, rather than global (like netfilter)
+
+ * it's simple enough to have some hope of being used correctly
+
+Implementation
+--------------
+
+After considering implementations based on the Linux Security Module (LSM)
+framework, on SELinux in particular, on network namespaces (CLONE_NEWNET), and
+on direct modification of the kernel syscall and task_struct APIs, we came to
+the conclusion that the best way to implement this feature was to extend the
+prctl() framework with a new pair of options named PR_{GET,SET}_NETWORK. These
+options cause prctl() to read or modify "current->network".
+
+Semantics
+---------
+
+current->network is a flags field which is preserved across all variants of
+fork() and exec().
+
+Writes which attempt to clear bits in current->network return -EPERM.
+
+The default value for current->network is named PR_NETWORK_OFF and is defined
+to be 0.
+
+Presently, only one flag is defined: PR_NETWORK_OFF.
+
+More flags may be defined in the future if they become needed.
+
+Attempts to set undefined flags result in -EINVAL.
+
+When PR_NETWORK_OFF is set, implementations of syscalls which may be used by
+the current process to perform autonomous networking will return -EPERM. For
+example, calls to socket(), bind(), connect(), sendmsg(), and ptrace() will
+return -EPERM except for cases we are manipulating an AF_UNIX socket whose name
+does not begin with \0 or, in the case of sendmsg(), unless we are manipulating
+a previously connected socket, i.e. one with
+
+ msg.msg_name == NULL && msg.msg_namelen == 0
+
+or, in the case of ptrace(), we are ptracing() a process which has all of our
+own networking restriction flags set.
+
+References
+----------
+
+[1]: http://cr.yp.to/unix/disablenetwork.html
+[2]: http://wiki.laptop.org/go/OLPC_Bitfrost
+[3]: http://wiki.laptop.org/go/Rainbow
+[4]: http://plash.beasts.org/
--
1.6.6.rc1
^ permalink raw reply related [flat|nested] 35+ messages in thread* Re: [PATCH] Security: Add prctl(PR_{GET,SET}_NETWORK) interface.
2009-12-18 3:00 ` Michael Stone
` (2 preceding siblings ...)
2009-12-18 3:32 ` [PATCH 3/3] Security: Document prctl(PR_{GET,SET}_NETWORK). (v2) Michael Stone
@ 2009-12-18 17:49 ` Stephen Hemminger
2009-12-20 17:53 ` Mark Seaborn
4 siblings, 0 replies; 35+ messages in thread
From: Stephen Hemminger @ 2009-12-18 17:49 UTC (permalink / raw)
To: Michael Stone
Cc: Mark Seaborn, linux-kernel, netdev, linux-security-module,
Andi Kleen, David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Randy Dunlap, Américo Wang, Michael Stone
On Thu, 17 Dec 2009 22:00:57 -0500
Michael Stone <michael@laptop.org> wrote:
> 5. Linux today has pretty good support for controlling the creation of
> channels involving the filesystem and involving shared daemons. It has
> mediocre support for access control involving sysv-ipc mechanisms. It has
> terrible support for access control involving non-local principals like
> "the collection of people and programs receiving packets sent to
> destination 18.0.0.1:80 from source 192.168.0.3:34661".
The policy control for this is done today on linux via the firewalling infrastructure.
It is not clear to me that moving over to the security infrastructure is an overall
gain from the security or user interface perspective.
^ permalink raw reply [flat|nested] 35+ messages in thread* Re: [PATCH] Security: Add prctl(PR_{GET,SET}_NETWORK) interface.
2009-12-18 3:00 ` Michael Stone
` (3 preceding siblings ...)
2009-12-18 17:49 ` [PATCH] Security: Add prctl(PR_{GET,SET}_NETWORK) interface Stephen Hemminger
@ 2009-12-20 17:53 ` Mark Seaborn
4 siblings, 0 replies; 35+ messages in thread
From: Mark Seaborn @ 2009-12-20 17:53 UTC (permalink / raw)
To: Michael Stone
Cc: linux-kernel, netdev, linux-security-module, Andi Kleen,
David Lang, Oliver Hartkopp, Alan Cox, Herbert Xu,
Valdis Kletnieks, Bryan Donlan, Evgeniy Polyakov,
C. Scott Ananian, James Morris, Eric W. Biederman,
Bernie Innocenti, Randy Dunlap, Américo Wang
On Fri, Dec 18, 2009 at 3:00 AM, Michael Stone <michael@laptop.org> wrote:
> @Eric, Mark: regarding ptrace()-ing from network-disabled processes: I agree
> that this functionality is critical and I have altered the
> __ptrace_may_access() check to support it.
> The new rule I propose is equivalent to the rule I used in ptrace_set_network()
> and is similar to the rule that Eric proposed earlier this afternoon. I now
> propose:
>
> "You may ptrace() any process that has all the network restrictions you do."
>
> This should take care of your use of strace without bending anything else into
> an unnatural shape.
I am in two minds about this. On the one hand, it adds the
flexibility that I asked for. On the other hand, it is a more
complicated rule to have fixed in the kernel.
It still seems wrong to me that the disable-networking flag should
affect ptrace() at all.
The reason is that the disable-networking flag is not useful on its
own. Anyone who uses it will use it in combination with some other
authority-limiting mechanism. They will already have a story for how
to prevent sandboxed processes with interfering with other processes
via ptrace(), kill(), writing to ~/.bashrc, etc. There's no point in
disabling network access for a process if it has full access to your
home directory and can cause programs to be run with your full
authority as a user.
So if there is already a way to control access to ptrace(), we
shouldn't add another check to the kernel's access control rules.
They are complicated enough already.
On ad-hocness: I am very much in favour of providing unprivileged
mechanisms for switching off sources of ambient authority. But it
does not seem very useful to provide an unprivileged mechanism to
switch off network access if there is no unprivileged mechanism for
switching off access to the filesystem namespace, which is usually a
more important source of authority. Maybe we should solve both
problems?
Cheers,
Mark
^ permalink raw reply [flat|nested] 35+ messages in thread