Commit 34bd137b authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by David S. Miller

[NETFILTER]: ip_tables: propagate netns from userspace

.. all the way down to table searching functions.
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@sw.ru>
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 44d34e72
...@@ -1092,7 +1092,7 @@ static int compat_table_info(const struct xt_table_info *info, ...@@ -1092,7 +1092,7 @@ static int compat_table_info(const struct xt_table_info *info,
} }
#endif #endif
static int get_info(void __user *user, int *len, int compat) static int get_info(struct net *net, void __user *user, int *len, int compat)
{ {
char name[IPT_TABLE_MAXNAMELEN]; char name[IPT_TABLE_MAXNAMELEN];
struct xt_table *t; struct xt_table *t;
...@@ -1112,7 +1112,7 @@ static int get_info(void __user *user, int *len, int compat) ...@@ -1112,7 +1112,7 @@ static int get_info(void __user *user, int *len, int compat)
if (compat) if (compat)
xt_compat_lock(AF_INET); xt_compat_lock(AF_INET);
#endif #endif
t = try_then_request_module(xt_find_table_lock(&init_net, AF_INET, name), t = try_then_request_module(xt_find_table_lock(net, AF_INET, name),
"iptable_%s", name); "iptable_%s", name);
if (t && !IS_ERR(t)) { if (t && !IS_ERR(t)) {
struct ipt_getinfo info; struct ipt_getinfo info;
...@@ -1152,7 +1152,7 @@ static int get_info(void __user *user, int *len, int compat) ...@@ -1152,7 +1152,7 @@ static int get_info(void __user *user, int *len, int compat)
} }
static int static int
get_entries(struct ipt_get_entries __user *uptr, int *len) get_entries(struct net *net, struct ipt_get_entries __user *uptr, int *len)
{ {
int ret; int ret;
struct ipt_get_entries get; struct ipt_get_entries get;
...@@ -1170,7 +1170,7 @@ get_entries(struct ipt_get_entries __user *uptr, int *len) ...@@ -1170,7 +1170,7 @@ get_entries(struct ipt_get_entries __user *uptr, int *len)
return -EINVAL; return -EINVAL;
} }
t = xt_find_table_lock(&init_net, AF_INET, get.name); t = xt_find_table_lock(net, AF_INET, get.name);
if (t && !IS_ERR(t)) { if (t && !IS_ERR(t)) {
struct xt_table_info *private = t->private; struct xt_table_info *private = t->private;
duprintf("t->private->number = %u\n", private->number); duprintf("t->private->number = %u\n", private->number);
...@@ -1191,7 +1191,7 @@ get_entries(struct ipt_get_entries __user *uptr, int *len) ...@@ -1191,7 +1191,7 @@ get_entries(struct ipt_get_entries __user *uptr, int *len)
} }
static int static int
__do_replace(const char *name, unsigned int valid_hooks, __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
struct xt_table_info *newinfo, unsigned int num_counters, struct xt_table_info *newinfo, unsigned int num_counters,
void __user *counters_ptr) void __user *counters_ptr)
{ {
...@@ -1208,7 +1208,7 @@ __do_replace(const char *name, unsigned int valid_hooks, ...@@ -1208,7 +1208,7 @@ __do_replace(const char *name, unsigned int valid_hooks,
goto out; goto out;
} }
t = try_then_request_module(xt_find_table_lock(&init_net, AF_INET, name), t = try_then_request_module(xt_find_table_lock(net, AF_INET, name),
"iptable_%s", name); "iptable_%s", name);
if (!t || IS_ERR(t)) { if (!t || IS_ERR(t)) {
ret = t ? PTR_ERR(t) : -ENOENT; ret = t ? PTR_ERR(t) : -ENOENT;
...@@ -1261,7 +1261,7 @@ __do_replace(const char *name, unsigned int valid_hooks, ...@@ -1261,7 +1261,7 @@ __do_replace(const char *name, unsigned int valid_hooks,
} }
static int static int
do_replace(void __user *user, unsigned int len) do_replace(struct net *net, void __user *user, unsigned int len)
{ {
int ret; int ret;
struct ipt_replace tmp; struct ipt_replace tmp;
...@@ -1295,7 +1295,7 @@ do_replace(void __user *user, unsigned int len) ...@@ -1295,7 +1295,7 @@ do_replace(void __user *user, unsigned int len)
duprintf("ip_tables: Translated table\n"); duprintf("ip_tables: Translated table\n");
ret = __do_replace(tmp.name, tmp.valid_hooks, newinfo, ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
tmp.num_counters, tmp.counters); tmp.num_counters, tmp.counters);
if (ret) if (ret)
goto free_newinfo_untrans; goto free_newinfo_untrans;
...@@ -1331,7 +1331,7 @@ add_counter_to_entry(struct ipt_entry *e, ...@@ -1331,7 +1331,7 @@ add_counter_to_entry(struct ipt_entry *e,
} }
static int static int
do_add_counters(void __user *user, unsigned int len, int compat) do_add_counters(struct net *net, void __user *user, unsigned int len, int compat)
{ {
unsigned int i; unsigned int i;
struct xt_counters_info tmp; struct xt_counters_info tmp;
...@@ -1383,7 +1383,7 @@ do_add_counters(void __user *user, unsigned int len, int compat) ...@@ -1383,7 +1383,7 @@ do_add_counters(void __user *user, unsigned int len, int compat)
goto free; goto free;
} }
t = xt_find_table_lock(&init_net, AF_INET, name); t = xt_find_table_lock(net, AF_INET, name);
if (!t || IS_ERR(t)) { if (!t || IS_ERR(t)) {
ret = t ? PTR_ERR(t) : -ENOENT; ret = t ? PTR_ERR(t) : -ENOENT;
goto free; goto free;
...@@ -1789,7 +1789,7 @@ translate_compat_table(const char *name, ...@@ -1789,7 +1789,7 @@ translate_compat_table(const char *name,
} }
static int static int
compat_do_replace(void __user *user, unsigned int len) compat_do_replace(struct net *net, void __user *user, unsigned int len)
{ {
int ret; int ret;
struct compat_ipt_replace tmp; struct compat_ipt_replace tmp;
...@@ -1826,7 +1826,7 @@ compat_do_replace(void __user *user, unsigned int len) ...@@ -1826,7 +1826,7 @@ compat_do_replace(void __user *user, unsigned int len)
duprintf("compat_do_replace: Translated table\n"); duprintf("compat_do_replace: Translated table\n");
ret = __do_replace(tmp.name, tmp.valid_hooks, newinfo, ret = __do_replace(net, tmp.name, tmp.valid_hooks, newinfo,
tmp.num_counters, compat_ptr(tmp.counters)); tmp.num_counters, compat_ptr(tmp.counters));
if (ret) if (ret)
goto free_newinfo_untrans; goto free_newinfo_untrans;
...@@ -1850,11 +1850,11 @@ compat_do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user, ...@@ -1850,11 +1850,11 @@ compat_do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user,
switch (cmd) { switch (cmd) {
case IPT_SO_SET_REPLACE: case IPT_SO_SET_REPLACE:
ret = compat_do_replace(user, len); ret = compat_do_replace(sk->sk_net, user, len);
break; break;
case IPT_SO_SET_ADD_COUNTERS: case IPT_SO_SET_ADD_COUNTERS:
ret = do_add_counters(user, len, 1); ret = do_add_counters(sk->sk_net, user, len, 1);
break; break;
default: default:
...@@ -1903,7 +1903,8 @@ compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table, ...@@ -1903,7 +1903,8 @@ compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
} }
static int static int
compat_get_entries(struct compat_ipt_get_entries __user *uptr, int *len) compat_get_entries(struct net *net, struct compat_ipt_get_entries __user *uptr,
int *len)
{ {
int ret; int ret;
struct compat_ipt_get_entries get; struct compat_ipt_get_entries get;
...@@ -1924,7 +1925,7 @@ compat_get_entries(struct compat_ipt_get_entries __user *uptr, int *len) ...@@ -1924,7 +1925,7 @@ compat_get_entries(struct compat_ipt_get_entries __user *uptr, int *len)
} }
xt_compat_lock(AF_INET); xt_compat_lock(AF_INET);
t = xt_find_table_lock(&init_net, AF_INET, get.name); t = xt_find_table_lock(net, AF_INET, get.name);
if (t && !IS_ERR(t)) { if (t && !IS_ERR(t)) {
struct xt_table_info *private = t->private; struct xt_table_info *private = t->private;
struct xt_table_info info; struct xt_table_info info;
...@@ -1960,10 +1961,10 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) ...@@ -1960,10 +1961,10 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
switch (cmd) { switch (cmd) {
case IPT_SO_GET_INFO: case IPT_SO_GET_INFO:
ret = get_info(user, len, 1); ret = get_info(sk->sk_net, user, len, 1);
break; break;
case IPT_SO_GET_ENTRIES: case IPT_SO_GET_ENTRIES:
ret = compat_get_entries(user, len); ret = compat_get_entries(sk->sk_net, user, len);
break; break;
default: default:
ret = do_ipt_get_ctl(sk, cmd, user, len); ret = do_ipt_get_ctl(sk, cmd, user, len);
...@@ -1982,11 +1983,11 @@ do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len) ...@@ -1982,11 +1983,11 @@ do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
switch (cmd) { switch (cmd) {
case IPT_SO_SET_REPLACE: case IPT_SO_SET_REPLACE:
ret = do_replace(user, len); ret = do_replace(sk->sk_net, user, len);
break; break;
case IPT_SO_SET_ADD_COUNTERS: case IPT_SO_SET_ADD_COUNTERS:
ret = do_add_counters(user, len, 0); ret = do_add_counters(sk->sk_net, user, len, 0);
break; break;
default: default:
...@@ -2007,11 +2008,11 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) ...@@ -2007,11 +2008,11 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
switch (cmd) { switch (cmd) {
case IPT_SO_GET_INFO: case IPT_SO_GET_INFO:
ret = get_info(user, len, 0); ret = get_info(sk->sk_net, user, len, 0);
break; break;
case IPT_SO_GET_ENTRIES: case IPT_SO_GET_ENTRIES:
ret = get_entries(user, len); ret = get_entries(sk->sk_net, user, len);
break; break;
case IPT_SO_GET_REVISION_MATCH: case IPT_SO_GET_REVISION_MATCH:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment