Skip to content

Commit

Permalink
bridge: Fix null dereference on ct_timeout_policy record
Browse files Browse the repository at this point in the history
Accoridng to vswitch.ovsschema, each CT_Zone record may have
zero or one associcated CT_Timeout_policy.  Thus, this patch
checks if ovsrec_ct_timeout_policy exist before accesses the
record.

VMWare-BZ: 2585825
Fixes: 4533953 ("ovs-vsctl: Add conntrack zone commands.")
Fixes: 993cae6 ("ofproto-dpif: Consume CT_Zone, and CT_Timeout_Policy tables")
Reported-by: Yang Song <[email protected]>
Signed-off-by: Yi-Hung Wei <[email protected]>
Signed-off-by: William Tu <[email protected]>
  • Loading branch information
YiHungWei authored and williamtu committed Jun 27, 2020
1 parent 5111937 commit 98670b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions tests/ovs-vsctl.at
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,14 @@ AT_CHECK([RUN_OVS_VSCTL([--if-exists del-zone-tp netdev zone=1])])
AT_CHECK([RUN_OVS_VSCTL([list-zone-tp netdev])], [0], [Zone:2, Timeout Policies: icmp_first=2 icmp_reply=3
])

AT_CHECK(
[RUN_OVS_VSCTL_TOGETHER([--id=@n create CT_Zone external_ids:"test"="123"],
[--id=@m create Datapath datapath_version=0 ct_zones:"10"=@n],
[set Open_vSwitch . datapaths:"netdev"=@m])],
[0], [stdout])
AT_CHECK([RUN_OVS_VSCTL([list-zone-tp netdev])], [0], [Zone:10, Timeout Policies: system default
])

AT_CHECK([RUN_OVS_VSCTL([-- --id=@m create Datapath datapath_version=0 'capabilities={recirc=true}' -- set Open_vSwitch . datapaths:"system"=@m])], [0], [stdout])
AT_CHECK([RUN_OVS_VSCTL([list-dp-cap system])], [0], [recirc=true
])
Expand Down
10 changes: 7 additions & 3 deletions utilities/ovs-vsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,9 +1344,13 @@ cmd_list_zone_tp(struct ctl_context *ctx)

struct ovsrec_ct_timeout_policy *tp = zone->timeout_policy;

for (int j = 0; j < tp->n_timeouts; j++) {
ds_put_format(&ctx->output, "%s=%"PRIu64" ",
tp->key_timeouts[j], tp->value_timeouts[j]);
if (tp) {
for (int j = 0; j < tp->n_timeouts; j++) {
ds_put_format(&ctx->output, "%s=%"PRIu64" ",
tp->key_timeouts[j], tp->value_timeouts[j]);
}
} else {
ds_put_cstr(&ctx->output, "system default");
}
ds_chomp(&ctx->output, ' ');
ds_put_char(&ctx->output, '\n');
Expand Down
6 changes: 4 additions & 2 deletions vswitchd/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,10 @@ static void
get_timeout_policy_from_ovsrec(struct simap *tp,
const struct ovsrec_ct_timeout_policy *tp_cfg)
{
for (size_t i = 0; i < tp_cfg->n_timeouts; i++) {
simap_put(tp, tp_cfg->key_timeouts[i], tp_cfg->value_timeouts[i]);
if (tp_cfg) {
for (size_t i = 0; i < tp_cfg->n_timeouts; i++) {
simap_put(tp, tp_cfg->key_timeouts[i], tp_cfg->value_timeouts[i]);
}
}
}

Expand Down

0 comments on commit 98670b7

Please sign in to comment.