aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/networking
diff options
context:
space:
mode:
authorVincent Bernat <bernat@luffy.cx>2013-01-16 16:55:49 -0500
committerDavid S. Miller <davem@davemloft.net>2013-01-17 03:21:25 -0500
commitd59577b6ffd313d0ab3be39cb1ab47e29bdc9182 (patch)
tree8e3e40ac4fd723778af191af78e8f40519338709 /Documentation/networking
parent5bd30d398792eb6351da2087fe81bbf755900991 (diff)
sk-filter: Add ability to lock a socket filter program
While a privileged program can open a raw socket, attach some restrictive filter and drop its privileges (or send the socket to an unprivileged program through some Unix socket), the filter can still be removed or modified by the unprivileged program. This commit adds a socket option to lock the filter (SO_LOCK_FILTER) preventing any modification of a socket filter program. This is similar to OpenBSD BIOCLOCK ioctl on bpf sockets, except even root is not allowed change/drop the filter. The state of the lock can be read with getsockopt(). No error is triggered if the state is not changed. -EPERM is returned when a user tries to remove the lock or to change/remove the filter while the lock is active. The check is done directly in sk_attach_filter() and sk_detach_filter() and does not affect only setsockopt() syscall. Signed-off-by: Vincent Bernat <bernat@luffy.cx> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'Documentation/networking')
-rw-r--r--Documentation/networking/filter.txt11
1 files changed, 9 insertions, 2 deletions
diff --git a/Documentation/networking/filter.txt b/Documentation/networking/filter.txt
index bbf2005270b5..cdb3e40b9d14 100644
--- a/Documentation/networking/filter.txt
+++ b/Documentation/networking/filter.txt
@@ -17,12 +17,12 @@ creating filters.
17 17
18LSF is much simpler than BPF. One does not have to worry about 18LSF is much simpler than BPF. One does not have to worry about
19devices or anything like that. You simply create your filter 19devices or anything like that. You simply create your filter
20code, send it to the kernel via the SO_ATTACH_FILTER ioctl and 20code, send it to the kernel via the SO_ATTACH_FILTER option and
21if your filter code passes the kernel check on it, you then 21if your filter code passes the kernel check on it, you then
22immediately begin filtering data on that socket. 22immediately begin filtering data on that socket.
23 23
24You can also detach filters from your socket via the 24You can also detach filters from your socket via the
25SO_DETACH_FILTER ioctl. This will probably not be used much 25SO_DETACH_FILTER option. This will probably not be used much
26since when you close a socket that has a filter on it the 26since when you close a socket that has a filter on it the
27filter is automagically removed. The other less common case 27filter is automagically removed. The other less common case
28may be adding a different filter on the same socket where you had another 28may be adding a different filter on the same socket where you had another
@@ -31,12 +31,19 @@ the old one and placing your new one in its place, assuming your
31filter has passed the checks, otherwise if it fails the old filter 31filter has passed the checks, otherwise if it fails the old filter
32will remain on that socket. 32will remain on that socket.
33 33
34SO_LOCK_FILTER option allows to lock the filter attached to a
35socket. Once set, a filter cannot be removed or changed. This allows
36one process to setup a socket, attach a filter, lock it then drop
37privileges and be assured that the filter will be kept until the
38socket is closed.
39
34Examples 40Examples
35======== 41========
36 42
37Ioctls- 43Ioctls-
38setsockopt(sockfd, SOL_SOCKET, SO_ATTACH_FILTER, &Filter, sizeof(Filter)); 44setsockopt(sockfd, SOL_SOCKET, SO_ATTACH_FILTER, &Filter, sizeof(Filter));
39setsockopt(sockfd, SOL_SOCKET, SO_DETACH_FILTER, &value, sizeof(value)); 45setsockopt(sockfd, SOL_SOCKET, SO_DETACH_FILTER, &value, sizeof(value));
46setsockopt(sockfd, SOL_SOCKET, SO_LOCK_FILTER, &value, sizeof(value));
40 47
41See the BSD bpf.4 manpage and the BSD Packet Filter paper written by 48See the BSD bpf.4 manpage and the BSD Packet Filter paper written by
42Steven McCanne and Van Jacobson of Lawrence Berkeley Laboratory. 49Steven McCanne and Van Jacobson of Lawrence Berkeley Laboratory.