17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/module.h>
21 #include <linux/netfilter/x_tables.h>
22 #include <linux/netfilter_bridge/ebtables.h>
25 #include <linux/slab.h>
26 #include <asm/uaccess.h>
31 #include "../br_private.h"
33 #define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
34 "report to author: "format, ## args)
45 #define SMP_ALIGN(x) (((x) + SMP_CACHE_BYTES-1) & ~(SMP_CACHE_BYTES-1))
46 #define COUNTER_OFFSET(n) (SMP_ALIGN(n * sizeof(struct ebt_counter)))
47 #define COUNTER_BASE(c, n, cpu) ((struct ebt_counter *)(((char *)c) + \
48 COUNTER_OFFSET(n) * cpu))
55 static void ebt_standard_compat_from_user(
void *
dst,
const void *
src)
61 memcpy(dst, &v,
sizeof(v));
64 static int ebt_standard_compat_to_user(
void __user *dst,
const void *src)
79 .targetsize =
sizeof(
int),
82 .compat_from_user = ebt_standard_compat_from_user,
83 .compat_to_user = ebt_standard_compat_to_user,
117 devname = device->
name;
119 while (entry[i] !=
'\0' && entry[i] != 1 && entry[i] == devname[i])
121 return (devname[i] != entry[i] && entry[i] != 1);
124 #define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg))
130 const struct ethhdr *
h = eth_hdr(skb);
152 if (in && (p = br_port_get_rcu(in)) !=
NULL &&
155 if (out && (p = br_port_get_rcu(out)) !=
NULL &&
161 for (i = 0; i < 6; i++)
169 for (i = 0; i < 6; i++)
208 cb_base =
COUNTER_BASE(private->counters, private->nentries,
210 if (private->chainstack)
214 chaininfo =
private->hook_entry[
hook];
216 point = (
struct ebt_entry *)(private->hook_entry[hook]->data);
217 counter_base = cb_base +
private->hook_entry[
hook]->counter_offset;
219 base =
private->entries;
221 while (i < nentries) {
222 if (ebt_basic_match(point, skb, in, out))
233 (*(counter_base +
i)).pcnt++;
234 (*(counter_base +
i)).bcnt += skb->
len;
244 verdict = ((
struct ebt_standard_target *)t)->verdict;
248 verdict = t->
u.
target->target(skb, &acpar);
260 #ifdef CONFIG_NETFILTER_DEBUG
273 counter_base = cb_base +
279 #ifdef CONFIG_NETFILTER_DEBUG
281 BUGPRINT(
"bogus standard verdict\n");
289 cs[
sp].
e = ebt_next_entry(point);
291 chaininfo = (
struct ebt_entries *) (base + verdict);
292 #ifdef CONFIG_NETFILTER_DEBUG
300 point = (
struct ebt_entry *)chaininfo->data;
305 point = ebt_next_entry(point);
335 if (
strcmp(
e->name, name) == 0)
344 find_inlist_lock(
struct list_head *head,
const char *name,
const char *
prefix,
345 int *error,
struct mutex *mutex)
348 find_inlist_lock_noload(head, name, error, mutex),
349 "%s%s", prefix, name);
353 find_table_lock(
struct net *
net,
const char *name,
int *error,
357 "ebtable_", error, mutex);
375 return PTR_ERR(match);
383 module_put(match->me);
406 return PTR_ERR(watcher);
414 module_put(watcher->me);
422 static int ebt_verify_pointers(
const struct ebt_replace *repl,
436 while (offset < limit) {
437 size_t left = limit -
offset;
440 if (left <
sizeof(
unsigned int))
444 if ((valid_hooks & (1 << i)) == 0)
455 BUGPRINT(
"EBT_ENTRY_OR_ENTRIES shouldn't be set "
456 "in distinguisher\n");
459 if (i != NF_BR_NUMHOOKS)
467 if (left < e->next_offset)
474 if (offset != limit) {
475 BUGPRINT(
"entries_size too small\n");
482 (valid_hooks & (1 << i))) {
483 BUGPRINT(
"Valid hook without chain\n");
495 ebt_check_entry_size_and_hooks(
const struct ebt_entry *e,
497 unsigned int *
n,
unsigned int *cnt,
498 unsigned int *totalcnt,
unsigned int *udc_cnt)
503 if ((
void *)e == (
void *)newinfo->
hook_entry[i])
508 if (i != NF_BR_NUMHOOKS || !e->
bitmask) {
512 BUGPRINT(
"nentries does not equal the nr of entries "
519 if (i != NF_BR_NUMHOOKS ||
525 if (i == NF_BR_NUMHOOKS)
528 BUGPRINT(
"counter_offset != totalcnt");
539 BUGPRINT(
"entry offsets not in right order\n");
544 BUGPRINT(
"target size too small\n");
577 if (i != NF_BR_NUMHOOKS)
594 if (i && (*i)-- == 0)
599 par.matchinfo = m->data;
601 if (par.match->destroy !=
NULL)
602 par.match->destroy(&par);
603 module_put(par.match->me);
608 ebt_cleanup_watcher(
struct ebt_entry_watcher *w,
struct net *net,
unsigned int *i)
612 if (i && (*i)-- == 0)
620 par.
target->destroy(&par);
621 module_put(par.
target->me);
626 ebt_cleanup_entry(
struct ebt_entry *e,
struct net *net,
unsigned int *cnt)
634 if (cnt && (*cnt)-- == 0)
645 par.
target->destroy(&par);
646 module_put(par.
target->me);
651 ebt_check_entry(
struct ebt_entry *e,
struct net *net,
653 const char *name,
unsigned int *cnt,
658 unsigned int i,
j,
hook = 0, hookmask = 0;
669 BUGPRINT(
"Unknown flag for bitmask\n");
673 BUGPRINT(
"Unknown flag for inv bitmask\n");
677 BUGPRINT(
"NOPROTO & 802_3 not allowed\n");
684 if ((
char *)newinfo->
hook_entry[i] < (
char *)e)
691 if (i < NF_BR_NUMHOOKS)
692 hookmask = (1 <<
hook) | (1 << NF_BR_NUMHOOKS);
694 for (i = 0; i < udc_cnt; i++)
695 if ((
char *)(cl_s[
i].
cs.chaininfo) > (
char *)
e)
698 hookmask = (1 <<
hook) | (1 << NF_BR_NUMHOOKS);
704 mtpar.net = tgpar.net =
net;
705 mtpar.table = tgpar.table =
name;
706 mtpar.entryinfo = tgpar.entryinfo =
e;
707 mtpar.hook_mask = tgpar.hook_mask = hookmask;
711 goto cleanup_matches;
715 goto cleanup_watchers;
720 if (IS_ERR(target)) {
721 ret = PTR_ERR(target);
722 goto cleanup_watchers;
726 if (t->
u.
target == &ebt_standard_target) {
727 if (gap <
sizeof(
struct ebt_standard_target)) {
728 BUGPRINT(
"Standard target size too big\n");
730 goto cleanup_watchers;
732 if (((
struct ebt_standard_target *)t)->verdict <
734 BUGPRINT(
"Invalid standard target\n");
736 goto cleanup_watchers;
741 goto cleanup_watchers;
745 tgpar.targinfo = t->data;
749 module_put(target->
me);
750 goto cleanup_watchers;
767 unsigned int udc_cnt,
unsigned int hooknr,
char *base)
769 int i, chain_nr = -1,
pos = 0, nentries = chain->
nentries, verdict;
773 while (
pos < nentries || chain_nr != -1) {
775 if (
pos == nentries) {
777 e = cl_s[chain_nr].
cs.e;
778 if (cl_s[chain_nr].
from != -1)
780 cl_s[cl_s[chain_nr].
from].
cs.chaininfo->nentries;
783 pos = cl_s[chain_nr].
cs.n;
785 cl_s[chain_nr].
cs.n = 0;
786 chain_nr = cl_s[chain_nr].
from;
796 BUGPRINT(
"Standard target size too big\n");
799 verdict = ((
struct ebt_standard_target *)t)->verdict;
803 for (i = 0; i < udc_cnt; i++)
804 if (hlp2 == cl_s[i].
cs.chaininfo)
815 if (cl_s[i].hookmask & (1 << hooknr))
820 cl_s[
i].
cs.e = ebt_next_entry(e);
823 cl_s[
i].
from = chain_nr;
830 e = ebt_next_entry(e);
837 static int translate_table(
struct net *net,
const char *name,
840 unsigned int i,
j,
k, udc_cnt;
845 while (i < NF_BR_NUMHOOKS && !newinfo->hook_entry[i])
847 if (i == NF_BR_NUMHOOKS) {
848 BUGPRINT(
"No valid hooks specified\n");
852 BUGPRINT(
"Chains don't start at beginning\n");
861 BUGPRINT(
"Hook order must be followed\n");
874 ebt_check_entry_size_and_hooks, newinfo,
875 &i, &j, &k, &udc_cnt);
881 BUGPRINT(
"nentries does not equal the nr of entries in the "
886 BUGPRINT(
"Total nentries is wrong\n");
911 cl_s =
vmalloc(udc_cnt *
sizeof(*cl_s));
916 ebt_get_udc_positions, newinfo, &i, cl_s);
929 cl_s, udc_cnt, i, newinfo->
entries)) {
947 ebt_check_entry, net, newinfo, name, &i, cl_s, udc_cnt);
950 ebt_cleanup_entry, net, &i);
958 struct ebt_counter *counters,
unsigned int nentries)
964 memcpy(counters, oldcounters,
971 counter_base =
COUNTER_BASE(oldcounters, nentries, cpu);
972 for (i = 0; i < nentries; i++) {
979 static int do_replace_finish(
struct net *net,
struct ebt_replace *repl,
998 ret = ebt_verify_pointers(repl, newinfo);
1000 goto free_counterstmp;
1002 ret = translate_table(net, repl->
name, newinfo);
1005 goto free_counterstmp;
1007 t = find_table_lock(net, repl->
name, &ret, &ebt_mutex);
1018 BUGPRINT(
"Wrong nr. of counters requested\n");
1054 ebt_cleanup_entry, net,
NULL);
1059 vfree(table->chainstack[i]);
1060 vfree(table->chainstack);
1071 ebt_cleanup_entry, net,
NULL);
1075 if (newinfo->chainstack) {
1077 vfree(newinfo->chainstack[i]);
1078 vfree(newinfo->chainstack);
1087 int ret, countersize;
1094 if (len !=
sizeof(
tmp) +
tmp.entries_size) {
1099 if (
tmp.entries_size == 0) {
1100 BUGPRINT(
"Entries_size never zero\n");
1113 newinfo =
vmalloc(
sizeof(*newinfo) + countersize);
1118 memset(newinfo->counters, 0, countersize);
1127 BUGPRINT(
"Couldn't copy entries from userspace\n");
1132 ret = do_replace_finish(net, &
tmp, newinfo);
1148 int ret,
i, countersize;
1151 if (input_table == NULL || (repl = input_table->
table) == NULL ||
1154 BUGPRINT(
"Bad table data for ebt_register_table!!!\n");
1166 newinfo =
vmalloc(
sizeof(*newinfo) + countersize);
1182 memset(newinfo->counters, 0, countersize);
1193 ret = translate_table(net, repl->
name, newinfo);
1195 BUGPRINT(
"Translate_table failed\n");
1196 goto free_chainstack;
1200 BUGPRINT(
"The table doesn't like its own initial data, lol\n");
1202 goto free_chainstack;
1209 goto free_chainstack;
1214 BUGPRINT(
"Table name already exists\n");
1220 if (newinfo->
nentries && !try_module_get(table->
me)) {
1241 return ERR_PTR(ret);
1249 BUGPRINT(
"Request to unregister NULL table!!!\n");
1256 ebt_cleanup_entry, net, NULL);
1258 module_put(table->
me);
1260 if (table->
private->chainstack) {
1270 static int do_update_counters(
struct net *net,
const char *name,
1273 const void __user *user,
unsigned int len)
1279 if (num_counters == 0)
1282 tmp =
vmalloc(num_counters *
sizeof(*tmp));
1286 t = find_table_lock(net, name, &ret, &ebt_mutex);
1290 if (num_counters != t->
private->nentries) {
1291 BUGPRINT(
"Wrong nr of counters\n");
1296 if (
copy_from_user(tmp, counters, num_counters *
sizeof(*counters))) {
1305 for (i = 0; i < num_counters; i++) {
1319 static int update_counters(
struct net *net,
const void __user *user,
1327 if (len !=
sizeof(hlp) + hlp.num_counters *
sizeof(
struct ebt_counter))
1330 return do_update_counters(net, hlp.name, hlp.counters,
1331 hlp.num_counters, user, len);
1335 const char *base,
char __user *ubase)
1337 char __user *hlp = ubase + ((
char *)m - base);
1349 const char *base,
char __user *ubase)
1351 char __user *hlp = ubase + ((
char *)w - base);
1361 ebt_make_names(
struct ebt_entry *e,
const char *base,
char __user *ubase)
1380 strncpy(name, t->u.target->name,
sizeof(name));
1386 static int copy_counters_to_user(
struct ebt_table *t,
1388 void __user *user,
unsigned int num_counters,
1389 unsigned int nentries)
1395 if (num_counters == 0)
1398 if (num_counters != nentries) {
1403 counterstmp =
vmalloc(nentries *
sizeof(*counterstmp));
1419 static int copy_everything_to_user(
struct ebt_table *t,
void __user *user,
1420 const int *len,
int cmd)
1424 unsigned int entries_size, nentries;
1429 entries_size = t->
private->entries_size;
1430 nentries = t->
private->nentries;
1431 entries = t->
private->entries;
1432 oldcounters = t->
private->counters;
1434 entries_size = t->
table->entries_size;
1435 nentries = t->
table->nentries;
1436 entries = t->
table->entries;
1437 oldcounters = t->
table->counters;
1443 if (*len !=
sizeof(
struct ebt_replace) + entries_size +
1444 (tmp.num_counters? nentries *
sizeof(
struct ebt_counter): 0))
1447 if (tmp.nentries != nentries) {
1452 if (tmp.entries_size != entries_size) {
1457 ret = copy_counters_to_user(t, oldcounters, tmp.counters,
1458 tmp.num_counters, nentries);
1462 if (
copy_to_user(tmp.entries, entries, entries_size)) {
1463 BUGPRINT(
"Couldn't copy entries to userspace\n");
1468 ebt_make_names, entries, tmp.entries);
1471 static int do_ebt_set_ctl(
struct sock *
sk,
1472 int cmd,
void __user *user,
unsigned int len)
1481 ret = do_replace(sock_net(sk), user, len);
1484 ret = update_counters(sock_net(sk), user, len);
1492 static int do_ebt_get_ctl(
struct sock *sk,
int cmd,
void __user *user,
int *len)
1504 t = find_table_lock(sock_net(sk), tmp.name, &ret, &ebt_mutex);
1517 tmp.nentries = t->
private->nentries;
1518 tmp.entries_size = t->
private->entries_size;
1521 tmp.nentries = t->
table->nentries;
1522 tmp.entries_size = t->
table->entries_size;
1523 tmp.valid_hooks = t->
table->valid_hooks;
1536 ret = copy_everything_to_user(t, user, len, cmd);
1548 #ifdef CONFIG_COMPAT
1550 struct compat_ebt_replace {
1565 struct compat_ebt_entry_mwt {
1575 static int ebt_compat_entry_padsize(
void)
1578 COMPAT_XT_ALIGN(
sizeof(
struct compat_ebt_entry_mwt)));
1580 COMPAT_XT_ALIGN(
sizeof(
struct compat_ebt_entry_mwt));
1583 static int ebt_compat_match_offset(
const struct xt_match *match,
1584 unsigned int userlen)
1593 return XT_ALIGN(userlen) - COMPAT_XT_ALIGN(userlen);
1594 return xt_compat_match_offset(match);
1597 static int compat_match_to_user(
struct ebt_entry_match *m,
void __user **dstptr,
1601 struct compat_ebt_entry_mwt
__user *cm = *dstptr;
1602 int off = ebt_compat_match_offset(match, m->
match_size);
1611 if (match->compat_to_user) {
1612 if (match->compat_to_user(cm->data, m->data))
1617 *size -= ebt_compat_entry_padsize() + off;
1624 void __user **dstptr,
1628 struct compat_ebt_entry_mwt
__user *cm = *dstptr;
1629 int off = xt_compat_target_offset(target);
1638 if (target->compat_to_user) {
1639 if (target->compat_to_user(cm->data, t->data))
1644 *size -= ebt_compat_entry_padsize() + off;
1651 void __user **dstptr,
1658 static int compat_copy_entry_to_user(
struct ebt_entry *e,
void __user **dstptr,
1678 if (*size <
sizeof(*ce))
1686 *dstptr +=
sizeof(*ce);
1700 ret = compat_target_to_user(t, dstptr, size);
1710 *size -=
sizeof(*ce);
1717 *off += ebt_compat_entry_padsize();
1723 *off += xt_compat_target_offset(w->
u.
watcher);
1724 *off += ebt_compat_entry_padsize();
1728 static int compat_calc_entry(
const struct ebt_entry *e,
1731 struct compat_ebt_replace *newinfo)
1734 unsigned int entry_offset;
1741 entry_offset = (
void *)e - base;
1748 off += xt_compat_target_offset(t->
u.
target);
1749 off += ebt_compat_entry_padsize();
1751 newinfo->entries_size -= off;
1760 (e < (
struct ebt_entry *)(base - hookptr))) {
1761 newinfo->hook_entry[
i] -= off;
1763 newinfo->hook_entry[i] + off,
1764 newinfo->hook_entry[i]);
1773 struct compat_ebt_replace *newinfo)
1776 const void *entries = info->
entries;
1778 newinfo->entries_size =
size;
1785 static int compat_copy_everything_to_user(
struct ebt_table *t,
1786 void __user *user,
int *len,
int cmd)
1788 struct compat_ebt_replace repl, tmp;
1800 oldcounters = t->
private->counters;
1805 oldcounters = t->
table->counters;
1811 if (tmp.nentries !=
tinfo.nentries ||
1812 (tmp.num_counters && tmp.num_counters !=
tinfo.nentries))
1815 memcpy(&repl, &tmp,
sizeof(repl));
1817 ret = compat_table_info(t->
private, &repl);
1819 ret = compat_table_info(&
tinfo, &repl);
1825 pr_err(
"wrong size: *len %d, entries_size %u, replsz %d\n",
1831 ret = copy_counters_to_user(t, oldcounters, compat_ptr(tmp.counters),
1832 tmp.num_counters,
tinfo.nentries);
1836 pos = compat_ptr(tmp.entries);
1838 compat_copy_entry_to_user, &pos, &tmp.entries_size);
1841 struct ebt_entries_buf_state {
1842 char *buf_kern_start;
1844 u32 buf_kern_offset;
1845 u32 buf_user_offset;
1848 static int ebt_buf_count(
struct ebt_entries_buf_state *
state,
unsigned int sz)
1850 state->buf_kern_offset += sz;
1851 return state->buf_kern_offset >= sz ? 0 : -
EINVAL;
1854 static int ebt_buf_add(
struct ebt_entries_buf_state *
state,
1855 void *
data,
unsigned int sz)
1857 if (state->buf_kern_start == NULL)
1860 BUG_ON(state->buf_kern_offset + sz > state->buf_kern_len);
1862 memcpy(state->buf_kern_start + state->buf_kern_offset, data, sz);
1865 state->buf_user_offset += sz;
1866 return ebt_buf_count(state, sz);
1869 static int ebt_buf_add_pad(
struct ebt_entries_buf_state *state,
unsigned int sz)
1871 char *
b = state->buf_kern_start;
1873 BUG_ON(b && state->buf_kern_offset > state->buf_kern_len);
1875 if (b != NULL && sz > 0)
1876 memset(b + state->buf_kern_offset, 0, sz);
1878 return ebt_buf_count(state, sz);
1887 static int compat_mtw_from_user(
struct compat_ebt_entry_mwt *mwt,
1888 enum compat_mwt compat_mwt,
1889 struct ebt_entries_buf_state *state,
1890 const unsigned char *base)
1897 unsigned int size_kern, match_size = mwt->match_size;
1899 strlcpy(name, mwt->u.name,
sizeof(name));
1901 if (state->buf_kern_start)
1902 dst = state->buf_kern_start + state->buf_kern_offset;
1904 switch (compat_mwt) {
1905 case EBT_COMPAT_MATCH:
1908 return PTR_ERR(match);
1910 off = ebt_compat_match_offset(match, match_size);
1912 if (match->compat_from_user)
1913 match->compat_from_user(dst, mwt->data);
1915 memcpy(dst, mwt->data, match_size);
1920 size_kern = match_size;
1921 module_put(match->
me);
1923 case EBT_COMPAT_WATCHER:
1924 case EBT_COMPAT_TARGET:
1928 off = xt_compat_target_offset(wt);
1931 if (wt->compat_from_user)
1932 wt->compat_from_user(dst, mwt->data);
1934 memcpy(dst, mwt->data, match_size);
1945 state->buf_kern_offset += match_size + off;
1946 state->buf_user_offset += match_size;
1947 pad =
XT_ALIGN(size_kern) - size_kern;
1949 if (pad > 0 && dst) {
1950 BUG_ON(state->buf_kern_len <= pad);
1951 BUG_ON(state->buf_kern_offset - (match_size + off) + size_kern > state->buf_kern_len - pad);
1952 memset(dst + size_kern, 0, pad);
1954 return off + match_size;
1961 static int ebt_size_mwt(
struct compat_ebt_entry_mwt *match32,
1962 unsigned int size_left,
enum compat_mwt
type,
1963 struct ebt_entries_buf_state *state,
const void *base)
1971 buf = (
char *) match32;
1973 while (size_left >=
sizeof(*match32)) {
1980 tmp = state->buf_kern_start + state->buf_kern_offset;
1983 ret = ebt_buf_add(state, buf,
sizeof(*match32));
1986 size_left -=
sizeof(*match32);
1989 ret = ebt_buf_add_pad(state, ebt_compat_entry_padsize());
1993 if (match32->match_size > size_left)
1996 size_left -= match32->match_size;
1998 ret = compat_mtw_from_user(match32, type, state, base);
2002 BUG_ON(ret < match32->match_size);
2003 growth += ret - match32->match_size;
2004 growth += ebt_compat_entry_padsize();
2006 buf +=
sizeof(*match32);
2007 buf += match32->match_size;
2012 WARN_ON(type == EBT_COMPAT_TARGET && size_left);
2013 match32 = (
struct compat_ebt_entry_mwt *) buf;
2020 static int size_entry_mwt(
struct ebt_entry *entry,
const unsigned char *base,
2021 unsigned int *total,
2022 struct ebt_entries_buf_state *state)
2024 unsigned int i,
j, startoff, new_offset = 0;
2027 unsigned int *offsets_update =
NULL;
2036 return ebt_buf_add(state, entry,
sizeof(
struct ebt_entries));
2038 if (*total <
sizeof(*entry) || entry->
next_offset <
sizeof(*entry))
2041 startoff = state->buf_user_offset;
2043 ret = ebt_buf_add(state, entry,
2050 sizeof(offsets) -
sizeof(offsets[0]));
2052 if (state->buf_kern_start) {
2053 buf_start = state->buf_kern_start + state->buf_kern_offset;
2054 offsets_update = (
unsigned int *) buf_start;
2056 ret = ebt_buf_add(state, &offsets[1],
2057 sizeof(offsets) -
sizeof(offsets[0]));
2060 buf_start = (
char *) entry;
2069 for (i = 0, j = 1 ; j < 4 ; j++, i++) {
2070 struct compat_ebt_entry_mwt *match32;
2072 char *buf = buf_start;
2074 buf = buf_start + offsets[
i];
2075 if (offsets[i] > offsets[j])
2078 match32 = (
struct compat_ebt_entry_mwt *) buf;
2079 size = offsets[
j] - offsets[
i];
2080 ret = ebt_size_mwt(match32, size, i, state, base);
2084 if (offsets_update && new_offset) {
2085 pr_debug(
"change offset %d to %d\n",
2086 offsets_update[i], offsets[j] + new_offset);
2087 offsets_update[
i] = offsets[
j] + new_offset;
2091 if (state->buf_kern_start == NULL) {
2092 unsigned int offset = buf_start - (
char *) base;
2099 startoff = state->buf_user_offset - startoff;
2101 BUG_ON(*total < startoff);
2113 static int compat_copy_entries(
unsigned char *data,
unsigned int size_user,
2114 struct ebt_entries_buf_state *state)
2116 unsigned int size_remaining = size_user;
2120 &size_remaining, state);
2125 return state->buf_kern_offset;
2129 static int compat_copy_ebt_replace_from_user(
struct ebt_replace *repl,
2130 void __user *user,
unsigned int len)
2132 struct compat_ebt_replace tmp;
2135 if (len <
sizeof(tmp))
2141 if (len !=
sizeof(tmp) + tmp.entries_size)
2144 if (tmp.entries_size == 0)
2157 repl->
hook_entry[i] = compat_ptr(tmp.hook_entry[i]);
2160 repl->
counters = compat_ptr(tmp.counters);
2161 repl->
entries = compat_ptr(tmp.entries);
2165 static int compat_do_replace(
struct net *net,
void __user *user,
2168 int ret,
i, countersize, size64;
2171 struct ebt_entries_buf_state state;
2174 ret = compat_copy_ebt_replace_from_user(&tmp, user, len);
2177 if (ret == -
EINVAL && do_replace(net, user, len) == 0)
2183 newinfo =
vmalloc(
sizeof(*newinfo) + countersize);
2188 memset(newinfo->counters, 0, countersize);
2190 memset(&state, 0,
sizeof(state));
2198 newinfo->
entries, tmp.entries, tmp.entries_size) != 0) {
2203 entries_tmp = newinfo->
entries;
2208 ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state);
2212 pr_debug(
"tmp.entries_size %d, kern off %d, user off %d delta %d\n",
2213 tmp.entries_size, state.buf_kern_offset, state.buf_user_offset,
2224 memset(&state, 0,
sizeof(state));
2225 state.buf_kern_start = newinfo->
entries;
2226 state.buf_kern_len = size64;
2228 ret = compat_copy_entries(entries_tmp, tmp.entries_size, &state);
2232 tmp.entries_size = size64;
2236 if (tmp.hook_entry[i]) {
2238 usrptr = (
char __user *) tmp.hook_entry[i];
2239 delta = usrptr - tmp.entries;
2248 ret = do_replace_finish(net, &tmp, newinfo);
2262 static int compat_update_counters(
struct net *net,
void __user *user,
2265 struct compat_ebt_replace hlp;
2271 if (len !=
sizeof(hlp) + hlp.num_counters *
sizeof(
struct ebt_counter))
2272 return update_counters(net, user, len);
2274 return do_update_counters(net, hlp.name, compat_ptr(hlp.counters),
2275 hlp.num_counters, user, len);
2278 static int compat_do_ebt_set_ctl(
struct sock *sk,
2279 int cmd,
void __user *user,
unsigned int len)
2288 ret = compat_do_replace(sock_net(sk), user, len);
2291 ret = compat_update_counters(sock_net(sk), user, len);
2299 static int compat_do_ebt_get_ctl(
struct sock *sk,
int cmd,
2300 void __user *user,
int *len)
2303 struct compat_ebt_replace tmp;
2312 return do_ebt_get_ctl(sk, cmd, user, len);
2317 t = find_table_lock(sock_net(sk), tmp.name, &ret, &ebt_mutex);
2324 tmp.nentries = t->
private->nentries;
2325 ret = compat_table_info(t->
private, &tmp);
2337 tmp.nentries = t->
table->nentries;
2338 tmp.entries_size = t->
table->entries_size;
2339 tmp.valid_hooks = t->
table->valid_hooks;
2358 if (copy_everything_to_user(t, user, len, cmd) == 0)
2361 ret = compat_copy_everything_to_user(t, user, len, cmd);
2374 static struct nf_sockopt_ops ebt_sockopts =
2379 .set = do_ebt_set_ctl,
2380 #ifdef CONFIG_COMPAT
2381 .compat_set = compat_do_ebt_set_ctl,
2385 .get = do_ebt_get_ctl,
2386 #ifdef CONFIG_COMPAT
2387 .compat_get = compat_do_ebt_get_ctl,
2392 static int __init ebtables_init(
void)
2409 static void __exit ebtables_fini(
void)