aboutsummaryrefslogtreecommitdiffstats
path: root/include
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 /include
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 'include')
-rw-r--r--include/net/sock.h1
-rw-r--r--include/uapi/asm-generic/socket.h2
2 files changed, 3 insertions, 0 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index 182ca99405ad..5a34e2f03657 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -664,6 +664,7 @@ enum sock_flags {
664 * Will use last 4 bytes of packet sent from 664 * Will use last 4 bytes of packet sent from
665 * user-space instead. 665 * user-space instead.
666 */ 666 */
667 SOCK_FILTER_LOCKED, /* Filter cannot be changed anymore */
667}; 668};
668 669
669static inline void sock_copy_flags(struct sock *nsk, struct sock *osk) 670static inline void sock_copy_flags(struct sock *nsk, struct sock *osk)
diff --git a/include/uapi/asm-generic/socket.h b/include/uapi/asm-generic/socket.h
index 2d32d073a6f9..3f6a99201410 100644
--- a/include/uapi/asm-generic/socket.h
+++ b/include/uapi/asm-generic/socket.h
@@ -73,4 +73,6 @@
73/* Instruct lower device to use last 4-bytes of skb data as FCS */ 73/* Instruct lower device to use last 4-bytes of skb data as FCS */
74#define SO_NOFCS 43 74#define SO_NOFCS 43
75 75
76#define SO_LOCK_FILTER 44
77
76#endif /* __ASM_GENERIC_SOCKET_H */ 78#endif /* __ASM_GENERIC_SOCKET_H */