blob: fbe3a8d12570b9604825043e9f68764af15b0aa0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Linux Socket Filter - Kernel level socket filtering
3 *
4 * Author:
5 * Jay Schulist <jschlst@samba.org>
6 *
7 * Based on the design of:
8 * - The Berkeley Packet Filter
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 *
15 * Andi Kleen - Fix a few bad bugs and races.
Kris Katterjohn93699862006-01-04 13:58:36 -080016 * Kris Katterjohn - Added many additional checks in sk_chk_filter()
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
19#include <linux/module.h>
20#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/mm.h>
22#include <linux/fcntl.h>
23#include <linux/socket.h>
24#include <linux/in.h>
25#include <linux/inet.h>
26#include <linux/netdevice.h>
27#include <linux/if_packet.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <net/ip.h>
30#include <net/protocol.h>
Patrick McHardy4738c1d2008-04-10 02:02:28 -070031#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/skbuff.h>
33#include <net/sock.h>
34#include <linux/errno.h>
35#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/uaccess.h>
Dmitry Mishin40daafc2006-04-18 14:50:10 -070037#include <asm/unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/filter.h>
Eric Dumazetc26aed42010-11-18 22:04:46 +000039#include <linux/reciprocal_div.h>
David S. Miller86e4ca62011-05-26 15:00:31 -040040#include <linux/ratelimit.h>
Will Drewry46b325c2012-04-12 16:47:52 -050041#include <linux/seccomp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Jan Seiffertf03fb3f2012-03-30 05:08:19 +000043/* No hurry in this branch
44 *
45 * Exported for the bpf jit load helper.
46 */
47void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
49 u8 *ptr = NULL;
50
51 if (k >= SKF_NET_OFF)
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -070052 ptr = skb_network_header(skb) + k - SKF_NET_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 else if (k >= SKF_LL_OFF)
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -070054 ptr = skb_mac_header(skb) + k - SKF_LL_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Eric Dumazet4bc65dd2010-12-07 22:26:15 +000056 if (ptr >= skb->head && ptr + size <= skb_tail_pointer(skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 return ptr;
58 return NULL;
59}
60
Eric Dumazet62ab0812010-12-06 20:50:09 +000061static inline void *load_pointer(const struct sk_buff *skb, int k,
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090062 unsigned int size, void *buffer)
Patrick McHardy0b05b2a2005-07-05 14:10:21 -070063{
64 if (k >= 0)
65 return skb_header_pointer(skb, k, size, buffer);
Jan Seiffertf03fb3f2012-03-30 05:08:19 +000066 return bpf_internal_load_pointer_neg_helper(skb, k, size);
Patrick McHardy0b05b2a2005-07-05 14:10:21 -070067}
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/**
Stephen Hemminger43db6d62008-04-10 01:43:09 -070070 * sk_filter - run a packet through a socket filter
71 * @sk: sock associated with &sk_buff
72 * @skb: buffer to filter
Stephen Hemminger43db6d62008-04-10 01:43:09 -070073 *
74 * Run the filter code and then cut skb->data to correct size returned by
75 * sk_run_filter. If pkt_len is 0 we toss packet. If skb->len is smaller
76 * than pkt_len we keep whole skb->data. This is the socket level
77 * wrapper to sk_run_filter. It returns 0 if the packet should
78 * be accepted or -EPERM if the packet should be tossed.
79 *
80 */
81int sk_filter(struct sock *sk, struct sk_buff *skb)
82{
83 int err;
84 struct sk_filter *filter;
85
Mel Gormanc93bdd02012-07-31 16:44:19 -070086 /*
87 * If the skb was allocated from pfmemalloc reserves, only
88 * allow SOCK_MEMALLOC sockets to use it as this socket is
89 * helping free memory
90 */
91 if (skb_pfmemalloc(skb) && !sock_flag(sk, SOCK_MEMALLOC))
92 return -ENOMEM;
93
Stephen Hemminger43db6d62008-04-10 01:43:09 -070094 err = security_sock_rcv_skb(sk, skb);
95 if (err)
96 return err;
97
Eric Dumazet80f8f102011-01-18 07:46:52 +000098 rcu_read_lock();
99 filter = rcu_dereference(sk->sk_filter);
Stephen Hemminger43db6d62008-04-10 01:43:09 -0700100 if (filter) {
Eric Dumazet0a148422011-04-20 09:27:32 +0000101 unsigned int pkt_len = SK_RUN_FILTER(filter, skb);
Eric Dumazet0d7da9d2010-10-25 03:47:05 +0000102
Stephen Hemminger43db6d62008-04-10 01:43:09 -0700103 err = pkt_len ? pskb_trim(skb, pkt_len) : -EPERM;
104 }
Eric Dumazet80f8f102011-01-18 07:46:52 +0000105 rcu_read_unlock();
Stephen Hemminger43db6d62008-04-10 01:43:09 -0700106
107 return err;
108}
109EXPORT_SYMBOL(sk_filter);
110
111/**
Kris Katterjohn2966b662006-01-23 16:26:16 -0800112 * sk_run_filter - run a filter on a socket
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 * @skb: buffer to run the filter on
Randy Dunlap697d0e32011-01-08 17:41:42 +0000114 * @fentry: filter to apply
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 * Decode and apply filter instructions to the skb->data.
Eric Dumazet93aaae22010-11-19 09:49:59 -0800117 * Return length to keep, 0 for none. @skb is the data we are
118 * filtering, @filter is the array of filter instructions.
119 * Because all jumps are guaranteed to be before last instruction,
120 * and last instruction guaranteed to be a RET, we dont need to check
121 * flen. (We used to pass to this function the length of filter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 */
Eric Dumazet62ab0812010-12-06 20:50:09 +0000123unsigned int sk_run_filter(const struct sk_buff *skb,
124 const struct sock_filter *fentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Patrick McHardy0b05b2a2005-07-05 14:10:21 -0700126 void *ptr;
Kris Katterjohn2966b662006-01-23 16:26:16 -0800127 u32 A = 0; /* Accumulator */
128 u32 X = 0; /* Index Register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
Patrick McHardy0b05b2a2005-07-05 14:10:21 -0700130 u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 int k;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 /*
134 * Process array of filter instructions.
135 */
Eric Dumazet93aaae22010-11-19 09:49:59 -0800136 for (;; fentry++) {
137#if defined(CONFIG_X86_32)
138#define K (fentry->k)
139#else
140 const u32 K = fentry->k;
141#endif
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +0900142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 switch (fentry->code) {
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000144 case BPF_S_ALU_ADD_X:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 A += X;
146 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000147 case BPF_S_ALU_ADD_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800148 A += K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000150 case BPF_S_ALU_SUB_X:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 A -= X;
152 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000153 case BPF_S_ALU_SUB_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800154 A -= K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000156 case BPF_S_ALU_MUL_X:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 A *= X;
158 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000159 case BPF_S_ALU_MUL_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800160 A *= K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000162 case BPF_S_ALU_DIV_X:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 if (X == 0)
164 return 0;
165 A /= X;
166 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000167 case BPF_S_ALU_DIV_K:
Eric Dumazetc26aed42010-11-18 22:04:46 +0000168 A = reciprocal_divide(A, K);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 continue;
Eric Dumazetb6069a92012-09-07 22:03:35 +0000170 case BPF_S_ALU_MOD_X:
171 if (X == 0)
172 return 0;
173 A %= X;
174 continue;
175 case BPF_S_ALU_MOD_K:
176 A %= K;
177 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000178 case BPF_S_ALU_AND_X:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 A &= X;
180 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000181 case BPF_S_ALU_AND_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800182 A &= K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000184 case BPF_S_ALU_OR_X:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 A |= X;
186 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000187 case BPF_S_ALU_OR_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800188 A |= K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000190 case BPF_S_ALU_LSH_X:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 A <<= X;
192 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000193 case BPF_S_ALU_LSH_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800194 A <<= K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000196 case BPF_S_ALU_RSH_X:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 A >>= X;
198 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000199 case BPF_S_ALU_RSH_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800200 A >>= K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000202 case BPF_S_ALU_NEG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 A = -A;
204 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000205 case BPF_S_JMP_JA:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800206 fentry += K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000208 case BPF_S_JMP_JGT_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800209 fentry += (A > K) ? fentry->jt : fentry->jf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000211 case BPF_S_JMP_JGE_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800212 fentry += (A >= K) ? fentry->jt : fentry->jf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000214 case BPF_S_JMP_JEQ_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800215 fentry += (A == K) ? fentry->jt : fentry->jf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000217 case BPF_S_JMP_JSET_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800218 fentry += (A & K) ? fentry->jt : fentry->jf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000220 case BPF_S_JMP_JGT_X:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800221 fentry += (A > X) ? fentry->jt : fentry->jf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000223 case BPF_S_JMP_JGE_X:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800224 fentry += (A >= X) ? fentry->jt : fentry->jf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000226 case BPF_S_JMP_JEQ_X:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800227 fentry += (A == X) ? fentry->jt : fentry->jf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000229 case BPF_S_JMP_JSET_X:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800230 fentry += (A & X) ? fentry->jt : fentry->jf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000232 case BPF_S_LD_W_ABS:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800233 k = K;
Kris Katterjohne35bedf2006-01-17 02:25:52 -0800234load_w:
Patrick McHardy0b05b2a2005-07-05 14:10:21 -0700235 ptr = load_pointer(skb, k, 4, &tmp);
236 if (ptr != NULL) {
Harvey Harrisond3e2ce32008-05-02 16:26:16 -0700237 A = get_unaligned_be32(ptr);
Patrick McHardy0b05b2a2005-07-05 14:10:21 -0700238 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
Eric Dumazet12b16da2010-12-15 19:45:28 +0000240 return 0;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000241 case BPF_S_LD_H_ABS:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800242 k = K;
Kris Katterjohne35bedf2006-01-17 02:25:52 -0800243load_h:
Patrick McHardy0b05b2a2005-07-05 14:10:21 -0700244 ptr = load_pointer(skb, k, 2, &tmp);
245 if (ptr != NULL) {
Harvey Harrisond3e2ce32008-05-02 16:26:16 -0700246 A = get_unaligned_be16(ptr);
Patrick McHardy0b05b2a2005-07-05 14:10:21 -0700247 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
Eric Dumazet12b16da2010-12-15 19:45:28 +0000249 return 0;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000250 case BPF_S_LD_B_ABS:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800251 k = K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252load_b:
Patrick McHardy0b05b2a2005-07-05 14:10:21 -0700253 ptr = load_pointer(skb, k, 1, &tmp);
254 if (ptr != NULL) {
255 A = *(u8 *)ptr;
256 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
Eric Dumazet12b16da2010-12-15 19:45:28 +0000258 return 0;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000259 case BPF_S_LD_W_LEN:
Patrick McHardy3154e542005-07-05 14:10:40 -0700260 A = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000262 case BPF_S_LDX_W_LEN:
Patrick McHardy3154e542005-07-05 14:10:40 -0700263 X = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000265 case BPF_S_LD_W_IND:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800266 k = X + K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 goto load_w;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000268 case BPF_S_LD_H_IND:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800269 k = X + K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 goto load_h;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000271 case BPF_S_LD_B_IND:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800272 k = X + K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 goto load_b;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000274 case BPF_S_LDX_B_MSH:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800275 ptr = load_pointer(skb, K, 1, &tmp);
Patrick McHardy0b05b2a2005-07-05 14:10:21 -0700276 if (ptr != NULL) {
277 X = (*(u8 *)ptr & 0xf) << 2;
278 continue;
279 }
280 return 0;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000281 case BPF_S_LD_IMM:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800282 A = K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000284 case BPF_S_LDX_IMM:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800285 X = K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000287 case BPF_S_LD_MEM:
Eric Dumazet2d5311e2010-12-01 20:46:24 +0000288 A = mem[K];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000290 case BPF_S_LDX_MEM:
Eric Dumazet2d5311e2010-12-01 20:46:24 +0000291 X = mem[K];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000293 case BPF_S_MISC_TAX:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 X = A;
295 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000296 case BPF_S_MISC_TXA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 A = X;
298 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000299 case BPF_S_RET_K:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800300 return K;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000301 case BPF_S_RET_A:
Kris Katterjohn4bad4dc2006-01-06 13:08:20 -0800302 return A;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000303 case BPF_S_ST:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800304 mem[K] = A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 continue;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000306 case BPF_S_STX:
Eric Dumazet93aaae22010-11-19 09:49:59 -0800307 mem[K] = X;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 continue;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000309 case BPF_S_ANC_PROTOCOL:
Al Viro252e3342006-11-14 20:48:11 -0800310 A = ntohs(skb->protocol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 continue;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000312 case BPF_S_ANC_PKTTYPE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 A = skb->pkt_type;
314 continue;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000315 case BPF_S_ANC_IFINDEX:
Paul LeoNerd Evans40eaf962010-04-22 03:32:22 +0000316 if (!skb->dev)
317 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 A = skb->dev->ifindex;
319 continue;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000320 case BPF_S_ANC_MARK:
jamal7e75f932009-10-19 02:17:56 +0000321 A = skb->mark;
322 continue;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000323 case BPF_S_ANC_QUEUE:
Eric Dumazetd19742f2009-10-20 01:06:22 -0700324 A = skb->queue_mapping;
325 continue;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000326 case BPF_S_ANC_HATYPE:
Paul LeoNerd Evans40eaf962010-04-22 03:32:22 +0000327 if (!skb->dev)
328 return 0;
329 A = skb->dev->type;
330 continue;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000331 case BPF_S_ANC_RXHASH:
Eric Dumazetda2033c2010-11-30 21:45:56 +0000332 A = skb->rxhash;
333 continue;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000334 case BPF_S_ANC_CPU:
Eric Dumazetda2033c2010-11-30 21:45:56 +0000335 A = raw_smp_processor_id();
336 continue;
Jiri Pirkoffe06c12012-03-31 11:01:20 +0000337 case BPF_S_ANC_ALU_XOR_X:
338 A ^= X;
339 continue;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000340 case BPF_S_ANC_NLATTR: {
Patrick McHardy4738c1d2008-04-10 02:02:28 -0700341 struct nlattr *nla;
342
343 if (skb_is_nonlinear(skb))
344 return 0;
345 if (A > skb->len - sizeof(struct nlattr))
346 return 0;
347
348 nla = nla_find((struct nlattr *)&skb->data[A],
349 skb->len - A, X);
350 if (nla)
351 A = (void *)nla - (void *)skb->data;
352 else
353 A = 0;
354 continue;
355 }
Eric Dumazet12b16da2010-12-15 19:45:28 +0000356 case BPF_S_ANC_NLATTR_NEST: {
Pablo Neira Ayusod214c752008-11-20 00:49:27 -0800357 struct nlattr *nla;
358
359 if (skb_is_nonlinear(skb))
360 return 0;
361 if (A > skb->len - sizeof(struct nlattr))
362 return 0;
363
364 nla = (struct nlattr *)&skb->data[A];
365 if (nla->nla_len > A - skb->len)
366 return 0;
367
368 nla = nla_find_nested(nla, X);
369 if (nla)
370 A = (void *)nla - (void *)skb->data;
371 else
372 A = 0;
373 continue;
374 }
Will Drewry46b325c2012-04-12 16:47:52 -0500375#ifdef CONFIG_SECCOMP_FILTER
376 case BPF_S_ANC_SECCOMP_LD_W:
377 A = seccomp_bpf_load(fentry->k);
378 continue;
379#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 default:
Joe Perches6c4a5cb2011-05-21 07:48:40 +0000381 WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
382 fentry->code, fentry->jt,
383 fentry->jf, fentry->k);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return 0;
385 }
386 }
387
388 return 0;
389}
Stephen Hemmingerb7156312008-04-10 01:33:47 -0700390EXPORT_SYMBOL(sk_run_filter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Eric Dumazet2d5311e2010-12-01 20:46:24 +0000392/*
393 * Security :
394 * A BPF program is able to use 16 cells of memory to store intermediate
395 * values (check u32 mem[BPF_MEMWORDS] in sk_run_filter())
396 * As we dont want to clear mem[] array for each packet going through
397 * sk_run_filter(), we check that filter loaded by user never try to read
398 * a cell if not previously written, and we check all branches to be sure
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300399 * a malicious user doesn't try to abuse us.
Eric Dumazet2d5311e2010-12-01 20:46:24 +0000400 */
401static int check_load_and_stores(struct sock_filter *filter, int flen)
402{
403 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
404 int pc, ret = 0;
405
406 BUILD_BUG_ON(BPF_MEMWORDS > 16);
407 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
408 if (!masks)
409 return -ENOMEM;
410 memset(masks, 0xff, flen * sizeof(*masks));
411
412 for (pc = 0; pc < flen; pc++) {
413 memvalid &= masks[pc];
414
415 switch (filter[pc].code) {
416 case BPF_S_ST:
417 case BPF_S_STX:
418 memvalid |= (1 << filter[pc].k);
419 break;
420 case BPF_S_LD_MEM:
421 case BPF_S_LDX_MEM:
422 if (!(memvalid & (1 << filter[pc].k))) {
423 ret = -EINVAL;
424 goto error;
425 }
426 break;
427 case BPF_S_JMP_JA:
428 /* a jump must set masks on target */
429 masks[pc + 1 + filter[pc].k] &= memvalid;
430 memvalid = ~0;
431 break;
432 case BPF_S_JMP_JEQ_K:
433 case BPF_S_JMP_JEQ_X:
434 case BPF_S_JMP_JGE_K:
435 case BPF_S_JMP_JGE_X:
436 case BPF_S_JMP_JGT_K:
437 case BPF_S_JMP_JGT_X:
438 case BPF_S_JMP_JSET_X:
439 case BPF_S_JMP_JSET_K:
440 /* a jump must set masks on targets */
441 masks[pc + 1 + filter[pc].jt] &= memvalid;
442 masks[pc + 1 + filter[pc].jf] &= memvalid;
443 memvalid = ~0;
444 break;
445 }
446 }
447error:
448 kfree(masks);
449 return ret;
450}
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452/**
453 * sk_chk_filter - verify socket filter code
454 * @filter: filter to verify
455 * @flen: length of filter
456 *
457 * Check the user's filter code. If we let some ugly
458 * filter code slip through kaboom! The filter must contain
Kris Katterjohn93699862006-01-04 13:58:36 -0800459 * no references or jumps that are out of range, no illegal
460 * instructions, and must end with a RET instruction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 *
Kris Katterjohn7b11f692006-01-13 14:33:06 -0800462 * All jumps are forward as they are not signed.
463 *
464 * Returns 0 if the rule set is legal or -EINVAL if not.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 */
Dan Carpenter4f25af22011-10-17 21:04:20 +0000466int sk_chk_filter(struct sock_filter *filter, unsigned int flen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Tetsuo Handacba328f2010-11-16 15:19:51 +0000468 /*
469 * Valid instructions are initialized to non-0.
470 * Invalid instructions are initialized to 0.
471 */
472 static const u8 codes[] = {
Eric Dumazet8c1592d2010-11-18 21:56:38 +0000473 [BPF_ALU|BPF_ADD|BPF_K] = BPF_S_ALU_ADD_K,
474 [BPF_ALU|BPF_ADD|BPF_X] = BPF_S_ALU_ADD_X,
475 [BPF_ALU|BPF_SUB|BPF_K] = BPF_S_ALU_SUB_K,
476 [BPF_ALU|BPF_SUB|BPF_X] = BPF_S_ALU_SUB_X,
477 [BPF_ALU|BPF_MUL|BPF_K] = BPF_S_ALU_MUL_K,
478 [BPF_ALU|BPF_MUL|BPF_X] = BPF_S_ALU_MUL_X,
479 [BPF_ALU|BPF_DIV|BPF_X] = BPF_S_ALU_DIV_X,
Eric Dumazetb6069a92012-09-07 22:03:35 +0000480 [BPF_ALU|BPF_MOD|BPF_K] = BPF_S_ALU_MOD_K,
481 [BPF_ALU|BPF_MOD|BPF_X] = BPF_S_ALU_MOD_X,
Eric Dumazet8c1592d2010-11-18 21:56:38 +0000482 [BPF_ALU|BPF_AND|BPF_K] = BPF_S_ALU_AND_K,
483 [BPF_ALU|BPF_AND|BPF_X] = BPF_S_ALU_AND_X,
484 [BPF_ALU|BPF_OR|BPF_K] = BPF_S_ALU_OR_K,
485 [BPF_ALU|BPF_OR|BPF_X] = BPF_S_ALU_OR_X,
486 [BPF_ALU|BPF_LSH|BPF_K] = BPF_S_ALU_LSH_K,
487 [BPF_ALU|BPF_LSH|BPF_X] = BPF_S_ALU_LSH_X,
488 [BPF_ALU|BPF_RSH|BPF_K] = BPF_S_ALU_RSH_K,
489 [BPF_ALU|BPF_RSH|BPF_X] = BPF_S_ALU_RSH_X,
490 [BPF_ALU|BPF_NEG] = BPF_S_ALU_NEG,
491 [BPF_LD|BPF_W|BPF_ABS] = BPF_S_LD_W_ABS,
492 [BPF_LD|BPF_H|BPF_ABS] = BPF_S_LD_H_ABS,
493 [BPF_LD|BPF_B|BPF_ABS] = BPF_S_LD_B_ABS,
494 [BPF_LD|BPF_W|BPF_LEN] = BPF_S_LD_W_LEN,
495 [BPF_LD|BPF_W|BPF_IND] = BPF_S_LD_W_IND,
496 [BPF_LD|BPF_H|BPF_IND] = BPF_S_LD_H_IND,
497 [BPF_LD|BPF_B|BPF_IND] = BPF_S_LD_B_IND,
498 [BPF_LD|BPF_IMM] = BPF_S_LD_IMM,
499 [BPF_LDX|BPF_W|BPF_LEN] = BPF_S_LDX_W_LEN,
500 [BPF_LDX|BPF_B|BPF_MSH] = BPF_S_LDX_B_MSH,
501 [BPF_LDX|BPF_IMM] = BPF_S_LDX_IMM,
502 [BPF_MISC|BPF_TAX] = BPF_S_MISC_TAX,
503 [BPF_MISC|BPF_TXA] = BPF_S_MISC_TXA,
504 [BPF_RET|BPF_K] = BPF_S_RET_K,
505 [BPF_RET|BPF_A] = BPF_S_RET_A,
506 [BPF_ALU|BPF_DIV|BPF_K] = BPF_S_ALU_DIV_K,
507 [BPF_LD|BPF_MEM] = BPF_S_LD_MEM,
508 [BPF_LDX|BPF_MEM] = BPF_S_LDX_MEM,
509 [BPF_ST] = BPF_S_ST,
510 [BPF_STX] = BPF_S_STX,
511 [BPF_JMP|BPF_JA] = BPF_S_JMP_JA,
512 [BPF_JMP|BPF_JEQ|BPF_K] = BPF_S_JMP_JEQ_K,
513 [BPF_JMP|BPF_JEQ|BPF_X] = BPF_S_JMP_JEQ_X,
514 [BPF_JMP|BPF_JGE|BPF_K] = BPF_S_JMP_JGE_K,
515 [BPF_JMP|BPF_JGE|BPF_X] = BPF_S_JMP_JGE_X,
516 [BPF_JMP|BPF_JGT|BPF_K] = BPF_S_JMP_JGT_K,
517 [BPF_JMP|BPF_JGT|BPF_X] = BPF_S_JMP_JGT_X,
518 [BPF_JMP|BPF_JSET|BPF_K] = BPF_S_JMP_JSET_K,
519 [BPF_JMP|BPF_JSET|BPF_X] = BPF_S_JMP_JSET_X,
Tetsuo Handacba328f2010-11-16 15:19:51 +0000520 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 int pc;
522
David S. Miller1b93ae642005-12-27 13:57:59 -0800523 if (flen == 0 || flen > BPF_MAXINSNS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 return -EINVAL;
525
526 /* check the filter code now */
527 for (pc = 0; pc < flen; pc++) {
Tetsuo Handacba328f2010-11-16 15:19:51 +0000528 struct sock_filter *ftest = &filter[pc];
529 u16 code = ftest->code;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Tetsuo Handacba328f2010-11-16 15:19:51 +0000531 if (code >= ARRAY_SIZE(codes))
532 return -EINVAL;
533 code = codes[code];
Eric Dumazet8c1592d2010-11-18 21:56:38 +0000534 if (!code)
Tetsuo Handacba328f2010-11-16 15:19:51 +0000535 return -EINVAL;
Kris Katterjohn93699862006-01-04 13:58:36 -0800536 /* Some instructions need special checks */
Tetsuo Handacba328f2010-11-16 15:19:51 +0000537 switch (code) {
538 case BPF_S_ALU_DIV_K:
Kris Katterjohn93699862006-01-04 13:58:36 -0800539 /* check for division by zero */
540 if (ftest->k == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 return -EINVAL;
Eric Dumazetc26aed42010-11-18 22:04:46 +0000542 ftest->k = reciprocal_value(ftest->k);
Kris Katterjohn93699862006-01-04 13:58:36 -0800543 break;
Eric Dumazetb6069a92012-09-07 22:03:35 +0000544 case BPF_S_ALU_MOD_K:
545 /* check for division by zero */
546 if (ftest->k == 0)
547 return -EINVAL;
548 break;
Tetsuo Handacba328f2010-11-16 15:19:51 +0000549 case BPF_S_LD_MEM:
550 case BPF_S_LDX_MEM:
551 case BPF_S_ST:
552 case BPF_S_STX:
553 /* check for invalid memory addresses */
Kris Katterjohn93699862006-01-04 13:58:36 -0800554 if (ftest->k >= BPF_MEMWORDS)
555 return -EINVAL;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000556 break;
Tetsuo Handacba328f2010-11-16 15:19:51 +0000557 case BPF_S_JMP_JA:
Kris Katterjohn93699862006-01-04 13:58:36 -0800558 /*
559 * Note, the large ftest->k might cause loops.
560 * Compare this with conditional jumps below,
561 * where offsets are limited. --ANK (981016)
562 */
Eric Dumazet95c96172012-04-15 05:58:06 +0000563 if (ftest->k >= (unsigned int)(flen-pc-1))
Kris Katterjohn93699862006-01-04 13:58:36 -0800564 return -EINVAL;
565 break;
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000566 case BPF_S_JMP_JEQ_K:
567 case BPF_S_JMP_JEQ_X:
568 case BPF_S_JMP_JGE_K:
569 case BPF_S_JMP_JGE_X:
570 case BPF_S_JMP_JGT_K:
571 case BPF_S_JMP_JGT_X:
572 case BPF_S_JMP_JSET_X:
573 case BPF_S_JMP_JSET_K:
Tetsuo Handacba328f2010-11-16 15:19:51 +0000574 /* for conditionals both must be safe */
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000575 if (pc + ftest->jt + 1 >= flen ||
576 pc + ftest->jf + 1 >= flen)
577 return -EINVAL;
Tetsuo Handacba328f2010-11-16 15:19:51 +0000578 break;
Eric Dumazet12b16da2010-12-15 19:45:28 +0000579 case BPF_S_LD_W_ABS:
580 case BPF_S_LD_H_ABS:
581 case BPF_S_LD_B_ABS:
582#define ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
583 code = BPF_S_ANC_##CODE; \
584 break
585 switch (ftest->k) {
586 ANCILLARY(PROTOCOL);
587 ANCILLARY(PKTTYPE);
588 ANCILLARY(IFINDEX);
589 ANCILLARY(NLATTR);
590 ANCILLARY(NLATTR_NEST);
591 ANCILLARY(MARK);
592 ANCILLARY(QUEUE);
593 ANCILLARY(HATYPE);
594 ANCILLARY(RXHASH);
595 ANCILLARY(CPU);
Jiri Pirkoffe06c12012-03-31 11:01:20 +0000596 ANCILLARY(ALU_XOR_X);
Eric Dumazet12b16da2010-12-15 19:45:28 +0000597 }
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000598 }
Tetsuo Handacba328f2010-11-16 15:19:51 +0000599 ftest->code = code;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 }
601
Hagen Paul Pfeifer01f2f3f2010-06-19 17:05:36 +0000602 /* last instruction must be a RET code */
603 switch (filter[flen - 1].code) {
604 case BPF_S_RET_K:
605 case BPF_S_RET_A:
Eric Dumazet2d5311e2010-12-01 20:46:24 +0000606 return check_load_and_stores(filter, flen);
Tetsuo Handacba328f2010-11-16 15:19:51 +0000607 }
608 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
Stephen Hemmingerb7156312008-04-10 01:33:47 -0700610EXPORT_SYMBOL(sk_chk_filter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612/**
Eric Dumazet46bcf142010-12-06 09:29:43 -0800613 * sk_filter_release_rcu - Release a socket filter by rcu_head
Pavel Emelyanov47e958e2007-10-17 21:22:42 -0700614 * @rcu: rcu_head that contains the sk_filter to free
615 */
Eric Dumazet46bcf142010-12-06 09:29:43 -0800616void sk_filter_release_rcu(struct rcu_head *rcu)
Pavel Emelyanov47e958e2007-10-17 21:22:42 -0700617{
618 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu);
619
Eric Dumazet0a148422011-04-20 09:27:32 +0000620 bpf_jit_free(fp);
Eric Dumazet46bcf142010-12-06 09:29:43 -0800621 kfree(fp);
Pavel Emelyanov47e958e2007-10-17 21:22:42 -0700622}
Eric Dumazet46bcf142010-12-06 09:29:43 -0800623EXPORT_SYMBOL(sk_filter_release_rcu);
Pavel Emelyanov47e958e2007-10-17 21:22:42 -0700624
Jiri Pirko302d6632012-03-31 11:01:19 +0000625static int __sk_prepare_filter(struct sk_filter *fp)
626{
627 int err;
628
629 fp->bpf_func = sk_run_filter;
630
631 err = sk_chk_filter(fp->insns, fp->len);
632 if (err)
633 return err;
634
635 bpf_jit_compile(fp);
636 return 0;
637}
638
639/**
640 * sk_unattached_filter_create - create an unattached filter
641 * @fprog: the filter program
Randy Dunlapc6c4b972012-06-08 14:01:44 +0000642 * @pfp: the unattached filter that is created
Jiri Pirko302d6632012-03-31 11:01:19 +0000643 *
Randy Dunlapc6c4b972012-06-08 14:01:44 +0000644 * Create a filter independent of any socket. We first run some
Jiri Pirko302d6632012-03-31 11:01:19 +0000645 * sanity checks on it to make sure it does not explode on us later.
646 * If an error occurs or there is insufficient memory for the filter
647 * a negative errno code is returned. On success the return is zero.
648 */
649int sk_unattached_filter_create(struct sk_filter **pfp,
650 struct sock_fprog *fprog)
651{
652 struct sk_filter *fp;
653 unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
654 int err;
655
656 /* Make sure new filter is there and in the right amounts. */
657 if (fprog->filter == NULL)
658 return -EINVAL;
659
660 fp = kmalloc(fsize + sizeof(*fp), GFP_KERNEL);
661 if (!fp)
662 return -ENOMEM;
663 memcpy(fp->insns, fprog->filter, fsize);
664
665 atomic_set(&fp->refcnt, 1);
666 fp->len = fprog->len;
667
668 err = __sk_prepare_filter(fp);
669 if (err)
670 goto free_mem;
671
672 *pfp = fp;
673 return 0;
674free_mem:
675 kfree(fp);
676 return err;
677}
678EXPORT_SYMBOL_GPL(sk_unattached_filter_create);
679
680void sk_unattached_filter_destroy(struct sk_filter *fp)
681{
682 sk_filter_release(fp);
683}
684EXPORT_SYMBOL_GPL(sk_unattached_filter_destroy);
685
Pavel Emelyanov47e958e2007-10-17 21:22:42 -0700686/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 * sk_attach_filter - attach a socket filter
688 * @fprog: the filter program
689 * @sk: the socket to use
690 *
691 * Attach the user's filter code. We first run some sanity checks on
692 * it to make sure it does not explode on us later. If an error
693 * occurs or there is insufficient memory for the filter a negative
694 * errno code is returned. On success the return is zero.
695 */
696int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
697{
Pavel Emelyanovd3904b72007-10-17 21:22:17 -0700698 struct sk_filter *fp, *old_fp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
700 int err;
701
702 /* Make sure new filter is there and in the right amounts. */
Kris Katterjohne35bedf2006-01-17 02:25:52 -0800703 if (fprog->filter == NULL)
704 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706 fp = sock_kmalloc(sk, fsize+sizeof(*fp), GFP_KERNEL);
707 if (!fp)
708 return -ENOMEM;
709 if (copy_from_user(fp->insns, fprog->filter, fsize)) {
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +0900710 sock_kfree_s(sk, fp, fsize+sizeof(*fp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 return -EFAULT;
712 }
713
714 atomic_set(&fp->refcnt, 1);
715 fp->len = fprog->len;
716
Jiri Pirko302d6632012-03-31 11:01:19 +0000717 err = __sk_prepare_filter(fp);
Pavel Emelyanovd3904b72007-10-17 21:22:17 -0700718 if (err) {
719 sk_filter_uncharge(sk, fp);
720 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722
Eric Dumazetf91ff5b2010-09-27 06:07:30 +0000723 old_fp = rcu_dereference_protected(sk->sk_filter,
724 sock_owned_by_user(sk));
Pavel Emelyanovd3904b72007-10-17 21:22:17 -0700725 rcu_assign_pointer(sk->sk_filter, fp);
Pavel Emelyanovd3904b72007-10-17 21:22:17 -0700726
Olof Johansson9b013e02007-10-18 21:48:39 -0700727 if (old_fp)
Eric Dumazet46bcf142010-12-06 09:29:43 -0800728 sk_filter_uncharge(sk, old_fp);
Pavel Emelyanovd3904b72007-10-17 21:22:17 -0700729 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730}
Michael S. Tsirkin5ff3f072010-02-14 01:01:00 +0000731EXPORT_SYMBOL_GPL(sk_attach_filter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Pavel Emelyanov55b33322007-10-17 21:21:26 -0700733int sk_detach_filter(struct sock *sk)
734{
735 int ret = -ENOENT;
736 struct sk_filter *filter;
737
Eric Dumazetf91ff5b2010-09-27 06:07:30 +0000738 filter = rcu_dereference_protected(sk->sk_filter,
739 sock_owned_by_user(sk));
Pavel Emelyanov55b33322007-10-17 21:21:26 -0700740 if (filter) {
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000741 RCU_INIT_POINTER(sk->sk_filter, NULL);
Eric Dumazet46bcf142010-12-06 09:29:43 -0800742 sk_filter_uncharge(sk, filter);
Pavel Emelyanov55b33322007-10-17 21:21:26 -0700743 ret = 0;
744 }
Pavel Emelyanov55b33322007-10-17 21:21:26 -0700745 return ret;
746}
Michael S. Tsirkin5ff3f072010-02-14 01:01:00 +0000747EXPORT_SYMBOL_GPL(sk_detach_filter);