* [PATCHv3 net] net: sched: set xt_tgchk_param par.net properly in ipt_init_target
@ 2017-08-08 7:25 Xin Long
2017-08-08 8:24 ` Jiri Pirko
2017-08-09 3:38 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Xin Long @ 2017-08-08 7:25 UTC (permalink / raw)
To: network dev; +Cc: davem, Jiri Pirko, Cong Wang
Now xt_tgchk_param par in ipt_init_target is a local varibale,
par.net is not initialized there. Later when xt_check_target
calls target's checkentry in which it may access par.net, it
would cause kernel panic.
Jaroslav found this panic when running:
# ip link add TestIface type dummy
# tc qd add dev TestIface ingress handle ffff:
# tc filter add dev TestIface parent ffff: u32 match u32 0 0 \
action xt -j CONNMARK --set-mark 4
This patch is to pass net param into ipt_init_target and set
par.net with it properly in there.
v1->v2:
As Wang Cong pointed, I missed ipt_net_id != xt_net_id, so fix
it by also passing net_id to __tcf_ipt_init.
v2->v3:
Missed the fixes tag, so add it.
Fixes: ecb2421b5ddf ("netfilter: add and use nf_ct_netns_get/put")
Reported-by: Jaroslav Aster <jaster@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/sched/act_ipt.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c
index 36f0ced..94ba5cf 100644
--- a/net/sched/act_ipt.c
+++ b/net/sched/act_ipt.c
@@ -36,8 +36,8 @@ static struct tc_action_ops act_ipt_ops;
static unsigned int xt_net_id;
static struct tc_action_ops act_xt_ops;
-static int ipt_init_target(struct xt_entry_target *t, char *table,
- unsigned int hook)
+static int ipt_init_target(struct net *net, struct xt_entry_target *t,
+ char *table, unsigned int hook)
{
struct xt_tgchk_param par;
struct xt_target *target;
@@ -49,6 +49,7 @@ static int ipt_init_target(struct xt_entry_target *t, char *table,
return PTR_ERR(target);
t->u.kernel.target = target;
+ par.net = net;
par.table = table;
par.entryinfo = NULL;
par.target = target;
@@ -91,10 +92,11 @@ static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = {
[TCA_IPT_TARG] = { .len = sizeof(struct xt_entry_target) },
};
-static int __tcf_ipt_init(struct tc_action_net *tn, struct nlattr *nla,
+static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla,
struct nlattr *est, struct tc_action **a,
const struct tc_action_ops *ops, int ovr, int bind)
{
+ struct tc_action_net *tn = net_generic(net, id);
struct nlattr *tb[TCA_IPT_MAX + 1];
struct tcf_ipt *ipt;
struct xt_entry_target *td, *t;
@@ -159,7 +161,7 @@ static int __tcf_ipt_init(struct tc_action_net *tn, struct nlattr *nla,
if (unlikely(!t))
goto err2;
- err = ipt_init_target(t, tname, hook);
+ err = ipt_init_target(net, t, tname, hook);
if (err < 0)
goto err3;
@@ -193,18 +195,16 @@ static int tcf_ipt_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, int ovr,
int bind)
{
- struct tc_action_net *tn = net_generic(net, ipt_net_id);
-
- return __tcf_ipt_init(tn, nla, est, a, &act_ipt_ops, ovr, bind);
+ return __tcf_ipt_init(net, ipt_net_id, nla, est, a, &act_ipt_ops, ovr,
+ bind);
}
static int tcf_xt_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, int ovr,
int bind)
{
- struct tc_action_net *tn = net_generic(net, xt_net_id);
-
- return __tcf_ipt_init(tn, nla, est, a, &act_xt_ops, ovr, bind);
+ return __tcf_ipt_init(net, xt_net_id, nla, est, a, &act_xt_ops, ovr,
+ bind);
}
static int tcf_ipt(struct sk_buff *skb, const struct tc_action *a,
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCHv3 net] net: sched: set xt_tgchk_param par.net properly in ipt_init_target
2017-08-08 7:25 [PATCHv3 net] net: sched: set xt_tgchk_param par.net properly in ipt_init_target Xin Long
@ 2017-08-08 8:24 ` Jiri Pirko
2017-08-09 3:38 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Pirko @ 2017-08-08 8:24 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, davem, Cong Wang
Tue, Aug 08, 2017 at 09:25:25AM CEST, lucien.xin@gmail.com wrote:
>Now xt_tgchk_param par in ipt_init_target is a local varibale,
>par.net is not initialized there. Later when xt_check_target
>calls target's checkentry in which it may access par.net, it
>would cause kernel panic.
>
>Jaroslav found this panic when running:
>
> # ip link add TestIface type dummy
> # tc qd add dev TestIface ingress handle ffff:
> # tc filter add dev TestIface parent ffff: u32 match u32 0 0 \
> action xt -j CONNMARK --set-mark 4
>
>This patch is to pass net param into ipt_init_target and set
>par.net with it properly in there.
>
>v1->v2:
> As Wang Cong pointed, I missed ipt_net_id != xt_net_id, so fix
> it by also passing net_id to __tcf_ipt_init.
>v2->v3:
> Missed the fixes tag, so add it.
>
>Fixes: ecb2421b5ddf ("netfilter: add and use nf_ct_netns_get/put")
>Reported-by: Jaroslav Aster <jaster@redhat.com>
>Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCHv3 net] net: sched: set xt_tgchk_param par.net properly in ipt_init_target
2017-08-08 7:25 [PATCHv3 net] net: sched: set xt_tgchk_param par.net properly in ipt_init_target Xin Long
2017-08-08 8:24 ` Jiri Pirko
@ 2017-08-09 3:38 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-08-09 3:38 UTC (permalink / raw)
To: lucien.xin; +Cc: netdev, jiri, xiyou.wangcong
From: Xin Long <lucien.xin@gmail.com>
Date: Tue, 8 Aug 2017 15:25:25 +0800
> Now xt_tgchk_param par in ipt_init_target is a local varibale,
> par.net is not initialized there. Later when xt_check_target
> calls target's checkentry in which it may access par.net, it
> would cause kernel panic.
>
> Jaroslav found this panic when running:
>
> # ip link add TestIface type dummy
> # tc qd add dev TestIface ingress handle ffff:
> # tc filter add dev TestIface parent ffff: u32 match u32 0 0 \
> action xt -j CONNMARK --set-mark 4
>
> This patch is to pass net param into ipt_init_target and set
> par.net with it properly in there.
>
> v1->v2:
> As Wang Cong pointed, I missed ipt_net_id != xt_net_id, so fix
> it by also passing net_id to __tcf_ipt_init.
> v2->v3:
> Missed the fixes tag, so add it.
>
> Fixes: ecb2421b5ddf ("netfilter: add and use nf_ct_netns_get/put")
> Reported-by: Jaroslav Aster <jaster@redhat.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-08-09 3:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-08 7:25 [PATCHv3 net] net: sched: set xt_tgchk_param par.net properly in ipt_init_target Xin Long
2017-08-08 8:24 ` Jiri Pirko
2017-08-09 3:38 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).