* [PATCH net v2] net/sched: act_ct: fix restore the qdisc_skb_cb after defrag
@ 2020-07-19 1:32 wenxu
2020-07-19 9:14 ` kernel test robot
0 siblings, 1 reply; 2+ messages in thread
From: wenxu @ 2020-07-19 1:32 UTC (permalink / raw)
To: fw, xiyou.wangcong; +Cc: netdev
From: wenxu <wenxu@ucloud.cn>
The fragment packets do defrag in tcf_ct_handle_fragments
will clear the skb->cb which make the qdisc_skb_cb clear
too. So the qdsic_skb_cb should be store before defrag and
restore after that.
It also update the pkt_len after all the
fragments finish the defrag to one packet and make the
following actions counter correct.
Fixes: b57dc7c13ea9 ("net/sched: Introduce action ct")
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
v2: update qdisc_skb_cb(skb)->pkt_len only for reassembled skbs
net/sched/act_ct.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index 67504ae..42bc231 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -673,13 +673,15 @@ static int tcf_ct_ipv6_is_fragment(struct sk_buff *skb, bool *frag)
}
static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
- u8 family, u16 zone)
+ u8 family, u16 zone, bool *defrag)
{
enum ip_conntrack_info ctinfo;
+ struct qdisc_skb_cb cb;
struct nf_conn *ct;
int err = 0;
bool frag;
+ *defrag = false;
/* Previously seen (loopback)? Ignore. */
ct = nf_ct_get(skb, &ctinfo);
if ((ct && !nf_ct_is_template(ct)) || ctinfo == IP_CT_UNTRACKED)
@@ -693,6 +695,7 @@ static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
return err;
skb_get(skb);
+ cb = *qdisc_skb_cb(skb);
if (family == NFPROTO_IPV4) {
enum ip_defrag_users user = IP_DEFRAG_CONNTRACK_IN + zone;
@@ -703,6 +706,8 @@ static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
local_bh_enable();
if (err && err != -EINPROGRESS)
goto out_free;
+ if (!err)
+ *defrag = true;
} else { /* NFPROTO_IPV6 */
#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
enum ip6_defrag_users user = IP6_DEFRAG_CONNTRACK_IN + zone;
@@ -711,12 +716,15 @@ static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
err = nf_ct_frag6_gather(net, skb, user);
if (err && err != -EINPROGRESS)
goto out_free;
+ if (!err)
+ *defrag = true;
#else
err = -EOPNOTSUPP;
goto out_free;
#endif
}
+ *qdisc_skb_cb(skb) = cb;
skb_clear_hash(skb);
skb->ignore_df = 1;
return err;
@@ -915,6 +923,7 @@ static int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
struct tcf_ct_params *p;
bool skip_add = false;
struct nf_conn *ct;
+ bool defrag;
u8 family;
p = rcu_dereference_bh(c->params);
@@ -946,7 +955,7 @@ static int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
*/
nh_ofs = skb_network_offset(skb);
skb_pull_rcsum(skb, nh_ofs);
- err = tcf_ct_handle_fragments(net, skb, family, p->zone);
+ err = tcf_ct_handle_fragments(net, skb, family, p->zone, &defrag);
if (err == -EINPROGRESS) {
retval = TC_ACT_STOLEN;
goto out;
@@ -1014,6 +1023,8 @@ static int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
out:
tcf_action_update_bstats(&c->common, skb);
+ if (defrag)
+ qdisc_skb_cb(skb)->pkt_len = skb->len;
return retval;
drop:
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net v2] net/sched: act_ct: fix restore the qdisc_skb_cb after defrag
2020-07-19 1:32 [PATCH net v2] net/sched: act_ct: fix restore the qdisc_skb_cb after defrag wenxu
@ 2020-07-19 9:14 ` kernel test robot
0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2020-07-19 9:14 UTC (permalink / raw)
To: wenxu, fw, xiyou.wangcong; +Cc: kbuild-all, clang-built-linux, netdev
[-- Attachment #1: Type: text/plain, Size: 10289 bytes --]
Hi,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on net/master]
url: https://github.com/0day-ci/linux/commits/wenxu-ucloud-cn/net-sched-act_ct-fix-restore-the-qdisc_skb_cb-after-defrag/20200719-093537
base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git 2ccb0161a0e9eb06f538557d38987e436fc39b8d
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project ed6b578040a85977026c93bf4188f996148f3218)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
>> net/sched/act_ct.c:939:6: warning: variable 'defrag' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (clear) {
^~~~~
net/sched/act_ct.c:1026:6: note: uninitialized use occurs here
if (defrag)
^~~~~~
net/sched/act_ct.c:939:2: note: remove the 'if' if its condition is always false
if (clear) {
^~~~~~~~~~~~
net/sched/act_ct.c:926:13: note: initialize the variable 'defrag' to silence this warning
bool defrag;
^
= 0
1 warning generated.
vim +939 net/sched/act_ct.c
b57dc7c13ea90e Paul Blakey 2019-07-09 912
b57dc7c13ea90e Paul Blakey 2019-07-09 913 static int tcf_ct_act(struct sk_buff *skb, const struct tc_action *a,
b57dc7c13ea90e Paul Blakey 2019-07-09 914 struct tcf_result *res)
b57dc7c13ea90e Paul Blakey 2019-07-09 915 {
b57dc7c13ea90e Paul Blakey 2019-07-09 916 struct net *net = dev_net(skb->dev);
b57dc7c13ea90e Paul Blakey 2019-07-09 917 bool cached, commit, clear, force;
b57dc7c13ea90e Paul Blakey 2019-07-09 918 enum ip_conntrack_info ctinfo;
b57dc7c13ea90e Paul Blakey 2019-07-09 919 struct tcf_ct *c = to_ct(a);
b57dc7c13ea90e Paul Blakey 2019-07-09 920 struct nf_conn *tmpl = NULL;
b57dc7c13ea90e Paul Blakey 2019-07-09 921 struct nf_hook_state state;
b57dc7c13ea90e Paul Blakey 2019-07-09 922 int nh_ofs, err, retval;
b57dc7c13ea90e Paul Blakey 2019-07-09 923 struct tcf_ct_params *p;
46475bb20f4ba0 Paul Blakey 2020-03-03 924 bool skip_add = false;
b57dc7c13ea90e Paul Blakey 2019-07-09 925 struct nf_conn *ct;
7e9055f6e78f92 wenxu 2020-07-19 926 bool defrag;
b57dc7c13ea90e Paul Blakey 2019-07-09 927 u8 family;
b57dc7c13ea90e Paul Blakey 2019-07-09 928
b57dc7c13ea90e Paul Blakey 2019-07-09 929 p = rcu_dereference_bh(c->params);
b57dc7c13ea90e Paul Blakey 2019-07-09 930
b57dc7c13ea90e Paul Blakey 2019-07-09 931 retval = READ_ONCE(c->tcf_action);
b57dc7c13ea90e Paul Blakey 2019-07-09 932 commit = p->ct_action & TCA_CT_ACT_COMMIT;
b57dc7c13ea90e Paul Blakey 2019-07-09 933 clear = p->ct_action & TCA_CT_ACT_CLEAR;
b57dc7c13ea90e Paul Blakey 2019-07-09 934 force = p->ct_action & TCA_CT_ACT_FORCE;
b57dc7c13ea90e Paul Blakey 2019-07-09 935 tmpl = p->tmpl;
b57dc7c13ea90e Paul Blakey 2019-07-09 936
8367b3ab6e9a26 wenxu 2020-07-04 937 tcf_lastuse_update(&c->tcf_tm);
8367b3ab6e9a26 wenxu 2020-07-04 938
b57dc7c13ea90e Paul Blakey 2019-07-09 @939 if (clear) {
b57dc7c13ea90e Paul Blakey 2019-07-09 940 ct = nf_ct_get(skb, &ctinfo);
b57dc7c13ea90e Paul Blakey 2019-07-09 941 if (ct) {
b57dc7c13ea90e Paul Blakey 2019-07-09 942 nf_conntrack_put(&ct->ct_general);
b57dc7c13ea90e Paul Blakey 2019-07-09 943 nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
b57dc7c13ea90e Paul Blakey 2019-07-09 944 }
b57dc7c13ea90e Paul Blakey 2019-07-09 945
b57dc7c13ea90e Paul Blakey 2019-07-09 946 goto out;
b57dc7c13ea90e Paul Blakey 2019-07-09 947 }
b57dc7c13ea90e Paul Blakey 2019-07-09 948
b57dc7c13ea90e Paul Blakey 2019-07-09 949 family = tcf_ct_skb_nf_family(skb);
b57dc7c13ea90e Paul Blakey 2019-07-09 950 if (family == NFPROTO_UNSPEC)
b57dc7c13ea90e Paul Blakey 2019-07-09 951 goto drop;
b57dc7c13ea90e Paul Blakey 2019-07-09 952
b57dc7c13ea90e Paul Blakey 2019-07-09 953 /* The conntrack module expects to be working at L3.
b57dc7c13ea90e Paul Blakey 2019-07-09 954 * We also try to pull the IPv4/6 header to linear area
b57dc7c13ea90e Paul Blakey 2019-07-09 955 */
b57dc7c13ea90e Paul Blakey 2019-07-09 956 nh_ofs = skb_network_offset(skb);
b57dc7c13ea90e Paul Blakey 2019-07-09 957 skb_pull_rcsum(skb, nh_ofs);
7e9055f6e78f92 wenxu 2020-07-19 958 err = tcf_ct_handle_fragments(net, skb, family, p->zone, &defrag);
b57dc7c13ea90e Paul Blakey 2019-07-09 959 if (err == -EINPROGRESS) {
b57dc7c13ea90e Paul Blakey 2019-07-09 960 retval = TC_ACT_STOLEN;
b57dc7c13ea90e Paul Blakey 2019-07-09 961 goto out;
b57dc7c13ea90e Paul Blakey 2019-07-09 962 }
b57dc7c13ea90e Paul Blakey 2019-07-09 963 if (err)
b57dc7c13ea90e Paul Blakey 2019-07-09 964 goto drop;
b57dc7c13ea90e Paul Blakey 2019-07-09 965
b57dc7c13ea90e Paul Blakey 2019-07-09 966 err = tcf_ct_skb_network_trim(skb, family);
b57dc7c13ea90e Paul Blakey 2019-07-09 967 if (err)
b57dc7c13ea90e Paul Blakey 2019-07-09 968 goto drop;
b57dc7c13ea90e Paul Blakey 2019-07-09 969
b57dc7c13ea90e Paul Blakey 2019-07-09 970 /* If we are recirculating packets to match on ct fields and
b57dc7c13ea90e Paul Blakey 2019-07-09 971 * committing with a separate ct action, then we don't need to
b57dc7c13ea90e Paul Blakey 2019-07-09 972 * actually run the packet through conntrack twice unless it's for a
b57dc7c13ea90e Paul Blakey 2019-07-09 973 * different zone.
b57dc7c13ea90e Paul Blakey 2019-07-09 974 */
b57dc7c13ea90e Paul Blakey 2019-07-09 975 cached = tcf_ct_skb_nfct_cached(net, skb, p->zone, force);
b57dc7c13ea90e Paul Blakey 2019-07-09 976 if (!cached) {
46475bb20f4ba0 Paul Blakey 2020-03-03 977 if (!commit && tcf_ct_flow_table_lookup(p, skb, family)) {
46475bb20f4ba0 Paul Blakey 2020-03-03 978 skip_add = true;
46475bb20f4ba0 Paul Blakey 2020-03-03 979 goto do_nat;
46475bb20f4ba0 Paul Blakey 2020-03-03 980 }
46475bb20f4ba0 Paul Blakey 2020-03-03 981
b57dc7c13ea90e Paul Blakey 2019-07-09 982 /* Associate skb with specified zone. */
b57dc7c13ea90e Paul Blakey 2019-07-09 983 if (tmpl) {
b57dc7c13ea90e Paul Blakey 2019-07-09 984 ct = nf_ct_get(skb, &ctinfo);
b57dc7c13ea90e Paul Blakey 2019-07-09 985 if (skb_nfct(skb))
b57dc7c13ea90e Paul Blakey 2019-07-09 986 nf_conntrack_put(skb_nfct(skb));
b57dc7c13ea90e Paul Blakey 2019-07-09 987 nf_conntrack_get(&tmpl->ct_general);
b57dc7c13ea90e Paul Blakey 2019-07-09 988 nf_ct_set(skb, tmpl, IP_CT_NEW);
b57dc7c13ea90e Paul Blakey 2019-07-09 989 }
b57dc7c13ea90e Paul Blakey 2019-07-09 990
b57dc7c13ea90e Paul Blakey 2019-07-09 991 state.hook = NF_INET_PRE_ROUTING;
b57dc7c13ea90e Paul Blakey 2019-07-09 992 state.net = net;
b57dc7c13ea90e Paul Blakey 2019-07-09 993 state.pf = family;
b57dc7c13ea90e Paul Blakey 2019-07-09 994 err = nf_conntrack_in(skb, &state);
b57dc7c13ea90e Paul Blakey 2019-07-09 995 if (err != NF_ACCEPT)
b57dc7c13ea90e Paul Blakey 2019-07-09 996 goto out_push;
b57dc7c13ea90e Paul Blakey 2019-07-09 997 }
b57dc7c13ea90e Paul Blakey 2019-07-09 998
46475bb20f4ba0 Paul Blakey 2020-03-03 999 do_nat:
b57dc7c13ea90e Paul Blakey 2019-07-09 1000 ct = nf_ct_get(skb, &ctinfo);
b57dc7c13ea90e Paul Blakey 2019-07-09 1001 if (!ct)
b57dc7c13ea90e Paul Blakey 2019-07-09 1002 goto out_push;
b57dc7c13ea90e Paul Blakey 2019-07-09 1003 nf_ct_deliver_cached_events(ct);
b57dc7c13ea90e Paul Blakey 2019-07-09 1004
b57dc7c13ea90e Paul Blakey 2019-07-09 1005 err = tcf_ct_act_nat(skb, ct, ctinfo, p->ct_action, &p->range, commit);
b57dc7c13ea90e Paul Blakey 2019-07-09 1006 if (err != NF_ACCEPT)
b57dc7c13ea90e Paul Blakey 2019-07-09 1007 goto drop;
b57dc7c13ea90e Paul Blakey 2019-07-09 1008
b57dc7c13ea90e Paul Blakey 2019-07-09 1009 if (commit) {
b57dc7c13ea90e Paul Blakey 2019-07-09 1010 tcf_ct_act_set_mark(ct, p->mark, p->mark_mask);
b57dc7c13ea90e Paul Blakey 2019-07-09 1011 tcf_ct_act_set_labels(ct, p->labels, p->labels_mask);
b57dc7c13ea90e Paul Blakey 2019-07-09 1012
b57dc7c13ea90e Paul Blakey 2019-07-09 1013 /* This will take care of sending queued events
b57dc7c13ea90e Paul Blakey 2019-07-09 1014 * even if the connection is already confirmed.
b57dc7c13ea90e Paul Blakey 2019-07-09 1015 */
b57dc7c13ea90e Paul Blakey 2019-07-09 1016 nf_conntrack_confirm(skb);
46475bb20f4ba0 Paul Blakey 2020-03-03 1017 } else if (!skip_add) {
64ff70b80fd403 Paul Blakey 2020-03-03 1018 tcf_ct_flow_table_process_conn(p->ct_ft, ct, ctinfo);
46475bb20f4ba0 Paul Blakey 2020-03-03 1019 }
64ff70b80fd403 Paul Blakey 2020-03-03 1020
b57dc7c13ea90e Paul Blakey 2019-07-09 1021 out_push:
b57dc7c13ea90e Paul Blakey 2019-07-09 1022 skb_push_rcsum(skb, nh_ofs);
b57dc7c13ea90e Paul Blakey 2019-07-09 1023
b57dc7c13ea90e Paul Blakey 2019-07-09 1024 out:
5e1ad95b630e65 Vlad Buslov 2019-10-30 1025 tcf_action_update_bstats(&c->common, skb);
7e9055f6e78f92 wenxu 2020-07-19 1026 if (defrag)
7e9055f6e78f92 wenxu 2020-07-19 1027 qdisc_skb_cb(skb)->pkt_len = skb->len;
b57dc7c13ea90e Paul Blakey 2019-07-09 1028 return retval;
b57dc7c13ea90e Paul Blakey 2019-07-09 1029
b57dc7c13ea90e Paul Blakey 2019-07-09 1030 drop:
26b537a88ca5b7 Vlad Buslov 2019-10-30 1031 tcf_action_inc_drop_qstats(&c->common);
b57dc7c13ea90e Paul Blakey 2019-07-09 1032 return TC_ACT_SHOT;
b57dc7c13ea90e Paul Blakey 2019-07-09 1033 }
b57dc7c13ea90e Paul Blakey 2019-07-09 1034
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 75355 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-19 10:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-19 1:32 [PATCH net v2] net/sched: act_ct: fix restore the qdisc_skb_cb after defrag wenxu
2020-07-19 9:14 ` kernel test robot
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).