Skip to content

Commit e754ec6

Browse files
joestringerdavem330
authored andcommitted
openvswitch: Serialize nested ct actions if provided
If userspace provides a ct action with no nested mark or label, then the storage for these fields is zeroed. Later when actions are requested, such zeroed fields are serialized even though userspace didn't originally specify them. Fix the behaviour by ensuring that no action is serialized in this case, and reject actions where userspace attempts to set these fields with mask=0. This should make netlink marshalling consistent across deserialization/reserialization. Reported-by: Jarno Rajahalme <[email protected]> Signed-off-by: Joe Stringer <[email protected]> Acked-by: Pravin B Shelar <[email protected]> Acked-by: Thomas Graf <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4f0909e commit e754ec6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

net/openvswitch/conntrack.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,6 @@ static int ovs_ct_set_labels(struct sk_buff *skb, struct sw_flow_key *key,
224224
struct nf_conn *ct;
225225
int err;
226226

227-
if (!IS_ENABLED(CONFIG_NF_CONNTRACK_LABELS))
228-
return -ENOTSUPP;
229-
230227
/* The connection could be invalid, in which case set_label is no-op.*/
231228
ct = nf_ct_get(skb, &ctinfo);
232229
if (!ct)
@@ -587,6 +584,10 @@ static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
587584
case OVS_CT_ATTR_MARK: {
588585
struct md_mark *mark = nla_data(a);
589586

587+
if (!mark->mask) {
588+
OVS_NLERR(log, "ct_mark mask cannot be 0");
589+
return -EINVAL;
590+
}
590591
info->mark = *mark;
591592
break;
592593
}
@@ -595,6 +596,10 @@ static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
595596
case OVS_CT_ATTR_LABELS: {
596597
struct md_labels *labels = nla_data(a);
597598

599+
if (!labels_nonzero(&labels->mask)) {
600+
OVS_NLERR(log, "ct_labels mask cannot be 0");
601+
return -EINVAL;
602+
}
598603
info->labels = *labels;
599604
break;
600605
}
@@ -705,11 +710,12 @@ int ovs_ct_action_to_attr(const struct ovs_conntrack_info *ct_info,
705710
if (IS_ENABLED(CONFIG_NF_CONNTRACK_ZONES) &&
706711
nla_put_u16(skb, OVS_CT_ATTR_ZONE, ct_info->zone.id))
707712
return -EMSGSIZE;
708-
if (IS_ENABLED(CONFIG_NF_CONNTRACK_MARK) &&
713+
if (IS_ENABLED(CONFIG_NF_CONNTRACK_MARK) && ct_info->mark.mask &&
709714
nla_put(skb, OVS_CT_ATTR_MARK, sizeof(ct_info->mark),
710715
&ct_info->mark))
711716
return -EMSGSIZE;
712717
if (IS_ENABLED(CONFIG_NF_CONNTRACK_LABELS) &&
718+
labels_nonzero(&ct_info->labels.mask) &&
713719
nla_put(skb, OVS_CT_ATTR_LABELS, sizeof(ct_info->labels),
714720
&ct_info->labels))
715721
return -EMSGSIZE;

0 commit comments

Comments
 (0)