Article View: linux.kernel.netdev
Article #26481Re: [PATCH net-next v24 09/14] virtio_net: Implement layer 2 ethtool flow rules
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 15:51
Date: Thu, 03 Dec 2026 15:51
742 lines
30717 bytes
30717 bytes
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 3 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] virtio_net: __counted_by counter set after referencing mask in
setup_eth_hdr_key_mask()
- [Medium] Ethtool flow rules point the device at a fixed RX virtqueue
(insert_rule() programs vq_index = rxq2vq(fs->ring_cookie)).
- [Medium] User-configured ethtool flow rules are thrown away on every
freeze/restore (suspend/resume, hibernation) and never reinstalled.
- [Medium] destroy_ethtool_rule() drops the driver's record of a rule
even when the device fails to destroy it.
- [Low] The comment in build_and_insert() names the type
'virtio_net_ff_obj_ff_classifier', which does not exist anywhere in…
- [Low] The new kernel-doc for struct virtio_net_resource_obj_ff_rule in
include/uapi/linux/virtio_net_ff.h reads: "The key bytes are compared…
--
virtio_net: Implement layer 2 ethtool flow rules
This commit adds ETHTOOL_SRXCLSRLINS and ETHTOOL_SRXCLSRLDEL support to
virtio_net for ethernet header flow rules. Each rule creates a classifier
object and a rule object on the device through admin commands, and both
are tracked in xarrays. It also adds the classifier and rule object
layouts to the virtio_net_ff.h uAPI header.
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index d5ca5a4d4378c..e9caed7f0ef66 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
[ ... ]
> @@ -5812,6 +5792,451 @@ static const struct netdev_stat_ops virtnet_stat_ops = {
[ ... ]
> +static void destroy_classifier(struct virtnet_ff *ff,
> + u32 classifier_id)
> +{
> + struct virtnet_classifier *c;
> + int err;
> +
> + c = xa_load(&ff->classifiers, classifier_id);
> + if (c) {
> + err = virtio_admin_obj_destroy(ff->vdev,
> + VIRTIO_NET_RESOURCE_OBJ_FF_CLASSIFIER,
> + c->id,
> + VIRTIO_ADMIN_GROUP_TYPE_SELF,
> + 0);
> + WARN_ON_ONCE(err);
> +
> + xa_erase(&ff->classifiers, c->id);
> + kfree(c);
> + }
> +}
> +
> +static int destroy_ethtool_rule(struct virtnet_ff *ff,
> + struct virtnet_ethtool_rule *eth_rule)
> +{
> + int err;
> +
> + ff->ethtool.num_rules--;
> +
> + err = virtio_admin_obj_destroy(ff->vdev,
> + VIRTIO_NET_RESOURCE_OBJ_FF_RULE,
> + eth_rule->flow_spec.location,
> + VIRTIO_ADMIN_GROUP_TYPE_SELF,
> + 0);
> +
> + xa_erase(&ff->ethtool.rules, eth_rule->flow_spec.location);
> + destroy_classifier(ff, eth_rule->classifier_id);
> + kfree(eth_rule);
[Severity: Medium]
What happens here if virtio_admin_obj_destroy() fails? The error goes
into err, but the xarray entry, the classifier and eth_rule are released
anyway, even though the device may still hold the rule.
destroy_classifier() then tries to destroy a classifier that the
surviving device rule may still reference. If that fails it only warns,
then erases the ID and frees the classifier.
virtnet_ethtool_flow_remove() returns the error to userspace, but a
retry finds nothing:
eth_rule = xa_load(&ff->ethtool.rules, location);
if (!eth_rule) {
err = -ENOENT;
So the rule is orphaned on the device and keeps steering or dropping
traffic.
Both xa_alloc() calls hand out the lowest free ID: ethtool.rules in
virtnet_ethtool_flow_insert() and ff->classifiers in setup_classifier().
That means the next insert reuses the stale rule and classifier IDs.
If the device rejects duplicate object IDs, could virtio_admin_obj_create()
fail for every later insert until the device is reset?
The destroy can fail with -ENOMEM from the allocation inside
virtio_admin_obj_destroy(), or with an admin queue or device error. The
same logic is still present at the end of the series in
try_destroy_classifier().
> +
> + return err;
> +}
[ ... ]
> + ff_rule->vq_index = fs->ring_cookie != RX_CLS_FLOW_DISC ?
> + cpu_to_le16(rxq2vq(fs->ring_cookie)) : 0;
[ ... ]
> +static int validate_flow_input(struct virtnet_ff *ff,
> + const struct ethtool_rx_flow_spec *fs,
> + u16 curr_queue_pairs)
> +{
[ ... ]
> + if (fs->ring_cookie != RX_CLS_FLOW_DISC &&
> + fs->ring_cookie >= curr_queue_pairs)
> + return -EINVAL;
[Severity: Medium]
Is checking ring_cookie only at insert time enough? insert_rule()
programs a fixed vq_index = rxq2vq(fs->ring_cookie) into the device.
Nothing re-checks the installed rules if the number of queue pairs
shrinks later.
At this commit there is no .get_rxnfc, so ethtool_check_max_channel()
gets -EOPNOTSUPP from ethtool_get_max_rxnfc_channel() and treats the
highest ring in use as 0. That allows ethtool -L combined 1 after a
rule with action 30. The later "virtio_net: Add get ethtool flow rules
ops" commit adds get_rxnfc, which closes this path.
The XDP path is still open at the end of the series. While XDP is
attached, curr_queue_pairs is curr_qp + xdp_qp, so a rule that targets
one of the extra XDP rings passes this check. On XDP detach,
virtnet_xdp_set() does:
err = virtnet_set_queues(vi, curr_qp + xdp_qp);
with xdp_qp == 0 and no check against the installed rules.
For example, take 4 online CPUs and max_queue_pairs >= 8. Attaching XDP
makes curr_queue_pairs 8, so ethtool -U ... action 6 is accepted.
Detaching XDP then drops back to 4 queue pairs.
Would the device keep steering matching flows to an RX vq the driver
has disabled, while ethtool -u still lists the rule?
[ ... ]
> + /*
> + * virtio_net_ff_obj_ff_classifier is already included in the
> + * classifier_size.
> + */
[Severity: Low]
This isn't a bug, but no type named virtio_net_ff_obj_ff_classifier
exists. Should this comment refer to struct
virtio_net_resource_obj_ff_classifier, which is what gets subtracted
below? The wrong name is still there at the end of the series.
> + c = kzalloc(classifier_size +
> + sizeof(struct virtnet_classifier) -
> + sizeof(struct virtio_net_resource_obj_ff_classifier),
> + GFP_KERNEL);
[ ... ]
> @@ -6016,11 +6487,19 @@ static int virtnet_ff_init(struct virtnet_ff *ff, struct virtio_device *vdev)
>
> static void virtnet_ff_cleanup(struct virtnet_ff *ff)
> {
> + struct virtnet_ethtool_rule *eth_rule;
> + unsigned long i;
> int err;
>
> if (!ff->ff_supported)
> return;
>
> + xa_for_each(&ff->ethtool.rules, i, eth_rule)
> + WARN_ON_ONCE(destroy_ethtool_rule(ff, eth_rule));
> +
> + xa_destroy(&ff->ethtool.rules);
> + xa_destroy(&ff->classifiers);
[Severity: Medium]
Does this loop throw away the user's ethtool flow rules on every
suspend/resume or hibernation cycle?
virtnet_freeze_down() calls virtnet_ff_cleanup(). That function now
destroys and frees every rule, then calls xa_destroy() on both xarrays.
On resume, virtnet_restore_up() calls virtnet_ff_init(). That only
re-reads the caps, recreates the group and initializes empty xarrays:
virtnet_freeze()
virtnet_freeze_down()
virtnet_ff_cleanup()
virtnet_restore()
virtnet_restore_up()
virtnet_ff_init()
Nothing replays the saved ethtool_rx_flow_spec entries. After resume,
all steering and drop rules are gone and nothing is logged. Traffic
that should be dropped is accepted, and steered flows fall back to RSS.
This is still the case at the end of the series.
[ ... ]
> diff --git a/include/uapi/linux/virtio_net_ff.h b/include/uapi/linux/virtio_net_ff.h
> index b0780e49df9f0..9152021c99baa 100644
> --- a/include/uapi/linux/virtio_net_ff.h
> +++ b/include/uapi/linux/virtio_net_ff.h
[ ... ]
> @@ -103,4 +105,52 @@ struct virtio_net_resource_obj_ff_group {
[ ... ]
> + * Payload for the VIRTIO_NET_RESOURCE_OBJ_FF_RULE administrative object.
> + * @group_id and @classifier_id refer to previously created objects of types
> + * VIRTIO_NET_RESOURCE_OBJ_FF_GROUP and VIRTIO_NET_RESOURCE_OBJ_FF_CLASSIFIER
> + * respectively. The key bytes are compared against packet headers using the
> + * masks provided by the classifier's selectors. Multi-byte fields are
> + * little-endian.
> + */
[Severity: Low]
This isn't a bug, but "Multi-byte fields are little-endian" comes right
after the sentence about key bytes. It reads as if it also covers
keys[] and the selector masks.
setup_eth_hdr_key_mask() copies ethtool's network-order header images
(for example the __be16 h_proto) into keys[] and selector->mask
unchanged. Only group_id, classifier_id and vq_index are little-endian.
Could the comment say which fields it means? Otherwise a device
implementation written from this header might match EtherTypes
byte-swapped.
[ ... ]
> @@ -5812,6 +5792,451 @@ static const struct netdev_stat_ops virtnet_stat_ops = {
> .get_base_stats = virtnet_get_base_stats,
> };
>
> +struct virtnet_ethtool_rule {
> + struct ethtool_rx_flow_spec flow_spec;
> + u32 classifier_id;
> +};
> +
> +/* The classifier struct must be the last field in this struct */
> +struct virtnet_classifier {
> + size_t size;
> + u32 id;
> + struct virtio_net_resource_obj_ff_classifier classifier;
> +};
> +
> +static_assert(sizeof(struct virtnet_classifier) ==
> + ALIGN(offsetofend(struct virtnet_classifier, classifier),
> + __alignof__(struct virtnet_classifier)),
> + "virtnet_classifier: classifier must be the last member");
> +
> +static bool check_mask_vs_cap(const void *m, const void *c,
> + u16 len, bool partial)
> +{
> + const u8 *mask = m;
> + const u8 *cap = c;
> + int i;
> +
> + for (i = 0; i < len; i++) {
> + if (partial && ((mask[i] & cap[i]) != mask[i]))
> + return false;
> + if (!partial && mask[i] != cap[i])
> + return false;
> + }
> +
> + return true;
> +}
> +
> +static
> +struct virtio_net_ff_selector *get_selector_cap(const struct virtnet_ff *ff,
> + u8 selector_type)
> +{
> + struct virtio_net_ff_selector *sel;
> + void *buf;
> + int i;
> +
> + buf = &ff->ff_mask->selectors;
> + sel = buf;
> +
> + for (i = 0; i < ff->ff_mask->count; i++) {
> + if (sel->type == selector_type)
> + return sel;
> +
> + buf += sizeof(struct virtio_net_ff_selector) + sel->length;
> + sel = buf;
> + }
> +
> + return NULL;
> +}
> +
> +static bool validate_eth_mask(const struct virtnet_ff *ff,
> + const struct virtio_net_ff_selector *sel,
> + const struct virtio_net_ff_selector *sel_cap)
> +{
> + bool partial_mask = !!(sel_cap->flags & VIRTIO_NET_FF_MASK_F_PARTIAL_MASK);
> + struct ethhdr *cap, *mask;
> + struct ethhdr zeros = {};
> +
> + cap = (struct ethhdr *)&sel_cap->mask;
> + mask = (struct ethhdr *)&sel->mask;
> +
> + if (memcmp(&zeros.h_dest, mask->h_dest, sizeof(zeros.h_dest)) &&
> + !check_mask_vs_cap(mask->h_dest, cap->h_dest,
> + sizeof(mask->h_dest), partial_mask))
> + return false;
> +
> + if (memcmp(&zeros.h_source, mask->h_source, sizeof(zeros.h_source)) &&
> + !check_mask_vs_cap(mask->h_source, cap->h_source,
> + sizeof(mask->h_source), partial_mask))
> + return false;
> +
> + if (mask->h_proto &&
> + !check_mask_vs_cap(&mask->h_proto, &cap->h_proto,
> + sizeof(__be16), partial_mask))
> + return false;
> +
> + return true;
> +}
> +
> +static bool validate_mask(const struct virtnet_ff *ff,
> + const struct virtio_net_ff_selector *sel)
> +{
> + struct virtio_net_ff_selector *sel_cap = get_selector_cap(ff, sel->type);
> +
> + if (!sel_cap)
> + return false;
> +
> + switch (sel->type) {
> + case VIRTIO_NET_FF_MASK_TYPE_ETH:
> + return validate_eth_mask(ff, sel, sel_cap);
> + }
> +
> + return false;
> +}
> +
> +static int setup_classifier(struct virtnet_ff *ff, struct virtnet_classifier *c)
> +{
> + int err;
> +
> + err = xa_alloc(&ff->classifiers, &c->id, c,
> + XA_LIMIT(0, le32_to_cpu(ff->ff_caps->classifiers_limit) - 1),
> + GFP_KERNEL);
> + if (err)
> + return err;
> +
> + err = virtio_admin_obj_create(ff->vdev,
> + VIRTIO_NET_RESOURCE_OBJ_FF_CLASSIFIER,
> + c->id,
> + VIRTIO_ADMIN_GROUP_TYPE_SELF,
> + 0,
> + &c->classifier,
> + c->size);
> + if (err)
> + goto err_xarray;
> +
> + return 0;
> +
> +err_xarray:
> + xa_erase(&ff->classifiers, c->id);
> +
> + return err;
> +}
> +
> +static void destroy_classifier(struct virtnet_ff *ff,
> + u32 classifier_id)
> +{
> + struct virtnet_classifier *c;
> + int err;
> +
> + c = xa_load(&ff->classifiers, classifier_id);
> + if (c) {
> + err = virtio_admin_obj_destroy(ff->vdev,
> + VIRTIO_NET_RESOURCE_OBJ_FF_CLASSIFIER,
> + c->id,
> + VIRTIO_ADMIN_GROUP_TYPE_SELF,
> + 0);
> + WARN_ON_ONCE(err);
> +
> + xa_erase(&ff->classifiers, c->id);
> + kfree(c);
> + }
> +}
> +
> +static int destroy_ethtool_rule(struct virtnet_ff *ff,
> + struct virtnet_ethtool_rule *eth_rule)
> +{
> + int err;
> +
> + ff->ethtool.num_rules--;
> +
> + err = virtio_admin_obj_destroy(ff->vdev,
> + VIRTIO_NET_RESOURCE_OBJ_FF_RULE,
> + eth_rule->flow_spec.location,
> + VIRTIO_ADMIN_GROUP_TYPE_SELF,
> + 0);
> +
> + xa_erase(&ff->ethtool.rules, eth_rule->flow_spec.location);
> + destroy_classifier(ff, eth_rule->classifier_id);
> + kfree(eth_rule);
> +
> + return err;
> +}
> +
> +static int insert_rule(struct virtnet_ff *ff,
> + struct virtnet_ethtool_rule *eth_rule,
> + u32 classifier_id,
> + const u8 *key,
> + u8 key_size)
> +{
> + struct ethtool_rx_flow_spec *fs = ð_rule->flow_spec;
> + struct virtio_net_resource_obj_ff_rule *ff_rule;
> + int err;
> +
> + ff_rule = kzalloc(sizeof(*ff_rule) + key_size, GFP_KERNEL);
> + if (!ff_rule)
> + return -ENOMEM;
> +
> + /* Intentionally leave the priority as 0. All rules have the same
> + * priority.
> + */
> + ff_rule->group_id = cpu_to_le32(VIRTNET_FF_ETHTOOL_GROUP_PRIORITY);
> + ff_rule->classifier_id = cpu_to_le32(classifier_id);
> + ff_rule->key_length = key_size;
> + ff_rule->action = fs->ring_cookie == RX_CLS_FLOW_DISC ?
> + VIRTIO_NET_FF_ACTION_DROP :
> + VIRTIO_NET_FF_ACTION_RX_VQ;
> + ff_rule->vq_index = fs->ring_cookie != RX_CLS_FLOW_DISC ?
> + cpu_to_le16(rxq2vq(fs->ring_cookie)) : 0;
> + memcpy(&ff_rule->keys, key, key_size);
> +
> + err = virtio_admin_obj_create(ff->vdev,
> + VIRTIO_NET_RESOURCE_OBJ_FF_RULE,
> + fs->location,
> + VIRTIO_ADMIN_GROUP_TYPE_SELF,
> + 0,
> + ff_rule,
> + sizeof(*ff_rule) + key_size);
> + if (err)
> + goto err_ff_rule;
> +
> + eth_rule->classifier_id = classifier_id;
> + ff->ethtool.num_rules++;
> + kfree(ff_rule);
> + kfree(key);
> +
> + return 0;
> +
> +err_ff_rule:
> + kfree(ff_rule);
> +
> + return err;
> +}
> +
> +static bool supported_flow_type(const struct ethtool_rx_flow_spec *fs)
> +{
> + switch (fs->flow_type) {
> + case ETHER_FLOW:
> + return true;
> + }
> +
> + return false;
> +}
> +
> +static int validate_flow_input(struct virtnet_ff *ff,
> + const struct ethtool_rx_flow_spec *fs,
> + u16 curr_queue_pairs)
> +{
> + u8 required_action = fs->ring_cookie == RX_CLS_FLOW_DISC ?
> + VIRTIO_NET_FF_ACTION_DROP :
> + VIRTIO_NET_FF_ACTION_RX_VQ;
> + int i;
> +
> + /* Force users to use RX_CLS_LOC_ANY - don't allow specific locations */
> + if (fs->location != RX_CLS_LOC_ANY)
> + return -EOPNOTSUPP;
> +
> + if (fs->ring_cookie != RX_CLS_FLOW_DISC &&
> + fs->ring_cookie >= curr_queue_pairs)
> + return -EINVAL;
> +
> + for (i = 0; i < ff->ff_actions->count; i++)
> + if (ff->ff_actions->actions[i] == required_action)
> + goto action_ok;
> + return -EOPNOTSUPP;
> +
> +action_ok:
> + if (fs->flow_type != ethtool_flow_type_mask(fs->flow_type))
> + return -EOPNOTSUPP;
> +
> + if (!supported_flow_type(fs))
> + return -EOPNOTSUPP;
> +
> + return 0;
> +}
> +
> +static void calculate_flow_sizes(struct ethtool_rx_flow_spec *fs,
> + u8 *key_size, size_t *classifier_size,
> + int *num_hdrs)
> +{
> + *num_hdrs = 1;
> + *key_size = sizeof(struct ethhdr);
> + /*
> + * The classifier size is the size of the classifier header, a selector
> + * header for each type of header in the match criteria, and each header
> + * providing the mask for matching against.
> + */
> + *classifier_size = *key_size +
> + sizeof(struct virtio_net_resource_obj_ff_classifier) +
> + sizeof(struct virtio_net_ff_selector) * (*num_hdrs);
> +}
> +
> +static void setup_eth_hdr_key_mask(struct virtio_net_ff_selector *selector,
> + u8 *key,
> + const struct ethtool_rx_flow_spec *fs)
> +{
> + struct ethhdr *eth_m = (struct ethhdr *)&selector->mask;
> + struct ethhdr *eth_k = (struct ethhdr *)key;
> +
> + selector->type = VIRTIO_NET_FF_MASK_TYPE_ETH;
> + selector->length = sizeof(struct ethhdr);
> +
> + memcpy(eth_m, &fs->m_u.ether_spec, sizeof(*eth_m));
> + memcpy(eth_k, &fs->h_u.ether_spec, sizeof(*eth_k));
> +}
> +
> +static int
> +validate_classifier_selectors(struct virtnet_ff *ff,
> + struct virtio_net_resource_obj_ff_classifier *classifier,
> + int num_hdrs)
> +{
> + struct virtio_net_ff_selector *selector = (void *)classifier->selectors;
> + int i;
> +
> + if (num_hdrs > ff->ff_caps->selectors_per_classifier_limit)
> + return -EINVAL;
> +
> + for (i = 0; i < num_hdrs; i++) {
> + if (!validate_mask(ff, selector))
> + return -EINVAL;
> +
> + selector = (((void *)selector) + sizeof(*selector) +
> + selector->length);
> + }
> +
> + return 0;
> +}
> +
> +static int build_and_insert(struct virtnet_ff *ff,
> + struct virtnet_ethtool_rule *eth_rule)
> +{
> + struct virtio_net_resource_obj_ff_classifier *classifier;
> + struct ethtool_rx_flow_spec *fs = ð_rule->flow_spec;
> + struct virtio_net_ff_selector *selector;
> + struct virtnet_classifier *c;
> + size_t classifier_size;
> + int num_hdrs;
> + u8 key_size;
> + u8 *key;
> + int err;
> +
> + calculate_flow_sizes(fs, &key_size, &classifier_size, &num_hdrs);
> +
> + key = kzalloc(key_size, GFP_KERNEL);
> + if (!key)
> + return -ENOMEM;
> +
> + /*
> + * virtio_net_ff_obj_ff_classifier is already included in the
> + * classifier_size.
> + */
> + c = kzalloc(classifier_size +
> + sizeof(struct virtnet_classifier) -
> + sizeof(struct virtio_net_resource_obj_ff_classifier),
> + GFP_KERNEL);
> + if (!c) {
> + kfree(key);
> + return -ENOMEM;
> + }
> +
> + c->size = classifier_size;
> + classifier = &c->classifier;
> + classifier->count = num_hdrs;
> + selector = (void *)&classifier->selectors[0];
> +
> + setup_eth_hdr_key_mask(selector, key, fs);
> +
> + err = validate_classifier_selectors(ff, classifier, num_hdrs);
> + if (err)
> + goto err_classifier;
> +
> + err = setup_classifier(ff, c);
> + if (err)
> + goto err_classifier;
> +
> + err = insert_rule(ff, eth_rule, c->id, key, key_size);
> + if (err) {
> + /* destroy_classifier will free the classifier */
> + destroy_classifier(ff, c->id);
> + goto err_key;
> + }
> +
> + return 0;
> +
> +err_classifier:
> + kfree(c);
> +err_key:
> + kfree(key);
> +
> + return err;
> +}
> +
> +static u32 virtnet_ff_rules_limit(const struct virtnet_ff *ff)
> +{
> + return min(le32_to_cpu(ff->ff_caps->rules_limit),
> + le32_to_cpu(ff->ff_caps->rules_per_group_limit));
> +}
> +
> +static int virtnet_ethtool_flow_insert(struct virtnet_ff *ff,
> + struct ethtool_rx_flow_spec *fs,
> + u16 curr_queue_pairs)
> +{
> + struct virtnet_ethtool_rule *eth_rule;
> + int err;
> +
> + if (!ff->ff_supported)
> + return -EOPNOTSUPP;
> +
> + err = validate_flow_input(ff, fs, curr_queue_pairs);
> + if (err)
> + return err;
> +
> + eth_rule = kzalloc(sizeof(*eth_rule), GFP_KERNEL);
> + if (!eth_rule)
> + return -ENOMEM;
> +
> + err = xa_alloc(&ff->ethtool.rules, &fs->location, eth_rule,
> + XA_LIMIT(0, virtnet_ff_rules_limit(ff) - 1),
> + GFP_KERNEL);
> + if (err)
> + goto err_rule;
> +
> + eth_rule->flow_spec = *fs;
> +
> + err = build_and_insert(ff, eth_rule);
> + if (err)
> + goto err_xa;
> +
> + return err;
> +
> +err_xa:
> + xa_erase(&ff->ethtool.rules, eth_rule->flow_spec.location);
> +
> +err_rule:
> + fs->location = RX_CLS_LOC_ANY;
> + kfree(eth_rule);
> +
> + return err;
> +}
> +
> +static int virtnet_ethtool_flow_remove(struct virtnet_ff *ff, int location)
> +{
> + struct virtnet_ethtool_rule *eth_rule;
> + int err = 0;
> +
> + if (!ff->ff_supported)
> + return -EOPNOTSUPP;
> +
> + eth_rule = xa_load(&ff->ethtool.rules, location);
> + if (!eth_rule) {
> + err = -ENOENT;
> + goto out;
> + }
> +
> + err = destroy_ethtool_rule(ff, eth_rule);
> +
> +out:
> + return err;
> +}
> +
> static size_t get_mask_size(u16 type)
> {
> switch (type) {
[Severity: High]
Is this ordering safe given the __counted_by(length) annotation on
mask in struct virtio_net_ff_selector?
eth_m is taken from &selector->mask while selector->length is still 0.
The zero comes from the kzalloc() of the classifier in
build_and_insert(). length is only assigned two lines later.
GCC 15+ and recent Clang support counted_by. With such a compiler and
CONFIG_FORTIFY_SOURCE=y, the object size of eth_m can be derived from
the value of length at the point where the pointer is formed. The
fortified memcpy(eth_m, &fs->m_u.ether_spec, sizeof(*eth_m)) would
then see a 0 byte destination for a 14 byte copy, and hit
fortify_panic().
On those builds, every ETHTOOL_SRXCLSRLINS with flow-type ether would
turn into a BUG() instead of adding a rule.
Could selector->type and selector->length be set before the mask
pointer is derived, for example by assigning eth_m after the length
store?
setup_transport_key_mask() later in the series has the same pattern.
It initializes tcp_m and udp_m from &selector->mask in their
declarations, before selector->length is set. Does it need the same
reordering?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202150502.3350030-1-shshitrit%40nvidia.com
Technical Details
Message-ID:
<179631311134.3146.14591842194936641074@kernel.org>Path:
mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376736-linux-kernel-netdev=dewy.ruReferences:
<20261202150502.3350030-10-shshitrit@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376736-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v24 09/14] virtio_net: Implement layer 2 ethtool flow rules Date: Thu, 03 Dec 2026 15:51:51 +0000 Organization: Usenet Network Message-ID: <179631311134.3146.14591842194936641074@kernel.org> References: <20261202150502.3350030-10-shshitrit@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2534007"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:DkhILLsSrWvgbQN6HT5OLzEi128= sha256:mX1Uj+lPzAMN708EDX/ByxjuwLTHITCoH48PgucEP7k= sha1:wHPVGiQw68H8AlnvDZ4p7267Cao= sha256:zXiBrzfJUVKyM3heS9rmSSenMy7+QaH7urkIHzDsuE8= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 6DCEF1179C2; Thu, 3 Dec 2026 18:52:12 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.74 X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id We3FobzN3cc1; Thu, 3 Dec 2026 18:52:08 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376736-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id E5CC61179BE; Thu, 3 Dec 2026 18:51:57 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id E41EF24255; Thu, 3 Dec 2026 15:51:53 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796313113; b=1r8G9NLmqUzWUmxk0g99GMz+SJTdXMrgg4N1zyjUOPA6dsNlRNVDIQ4aspbeaWJwDlZH 3E2T6i84zUYiTKaw4dV9f3gLKCbzt9sIV7JepzT1NkZYtlYNM6CR3qZooptv4T75/DQn3 8T1MzodasVisJVhIqqubmTsmMKPuJngtCh0p9fIA+lDkTV/GeaqY55fBF2Lp/+8V8ndCl //GYe2BuFSPD/XBiaskpmS52ERoPiYWSiyetl5VPNGtCh2U9Np6car8vJQ+sM0xQ21glf T/xye1SGrN0f2bbB/5C9jBxthzTc1LQurXObbH0q+BbePp/dgpZFJTzJdqTeU+a7+Mw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313113; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=Xk8oEEpm7aTUbHTg1SQYDTvGMtvOpG0YVhBXwduyK5E=; b=TIPrZLK8giU2em6gyQLEfgYfsE18O6HOvO1YzexN4x7sGJW1yCYvWvN7JBjOct2NntgM 4uHOmz4HEuyWkSf3jX3KhugHZWq+BFF/fn4Cn4pNSgHwspE/FPcu1RaBSAe/btxcXMaxA YUX1/7rhaR+Ox8REcydXrIguywUDeBCp+Nuro42SgKMZ15HNGFqOKPUQ70c8MNINyKR/A j7VvCtvB0+uEFCsY2tSKswdF+Cquh9s5fQR7N2JeKkwcg5cJSrwkboBSgooLCaEM8whhn H9qFn6aEt2YAbDnvtOmFnC441IAWhBB81w83rdIHH1sKI+MIGCqGONW/gvZLl8NNzfg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JBQuDj4x; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7919606A333; Thu, 3 Dec 2026 15:51:53 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JBQuDj4x X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796313112; b=4DQqOLhX3yxhvidMupib7R9iarXsq5MSNQPAEYGl66Fu+NMbhnRgs2t3A4fa4i+ng1Mg SSkBwYSQbLFX+gy1GeZ6u0iCsdcodpy3fUjouxjFdh+xMqBtXLLYI3bWLXARplxg2BfZh 95ip9GOfFRuPSGND8pRvYkLHtWLOgDMtL4j4sb4x6CCw5zPVl9aBKfJTVZgvOEXDww+yA qsdd4lJg8AYbNkTk3wuIoThd4wSGt5r9As3nF7cxHQr/XVpGTfkv/j4pBHAlBdmYv5Rnj t7WRqwNl0cHJUEYNQ74Ab5b4Qp0nr6FcoKaKFhGj4TlCRyl5fKUu/lr8ZEHIHld0MRw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313112; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=Xk8oEEpm7aTUbHTg1SQYDTvGMtvOpG0YVhBXwduyK5E=; b=cmkgSsCybeXLRY7e1r4gWaEdAN5OVurF9/FSGtMI4QVJAsdFVmeVHoDQZDPEptp8zuwW 99lbsJTWEVqDQZYNKlCGv8oOCS1TPqrhJ7slHoLuHLFH2Y6OBJptgQuRhe9Hs20fNFyLp KLLZsWI+wDlUu7J9MFtdDFFZ9SnvxVRS9vUmw12WCBCftk2WK+44LqQmZHf5LtMIwi8eq IWGiRaw+1xzgZPQTg6QysMahRIfpfHMkXKjq8XX/VfyFfTbe+woyi20DldmKAkkPf8YYr rnP/Z+E2qMEcraBIh9NZ4MOaOdvXCTNlll4CtFrHzzOD9mTe6qzCOF9KjfigSTyQYwQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JBQuDj4x; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C800D606A322; Thu, 3 Dec 2026 15:51:52 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF8E01F00896; Thu, 3 Dec 2026 15:51:51 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796313112; bh=Xk8oEEpm7aTUbHTg1SQYDTvGMtvOpG0YVhBXwduyK5E=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=JBQuDj4xFZvobRgQkPR1jKbQ320y8KXUiJ+ew02LHA0RmYlzqeSxOr+q2auH0CG1q ysmX+o1Oea5JWwlAcbuvbYWDNDGX+vVPRlqd8YoMa/HhmHln7MM2DSIFP9Q8JVndCx sBnKHEdjqnF6KOVPapdDaO4P5uNFjq9fP+KKr632yeadHKENpWCZ6trR1jTJabB8gY /Hg6DzKm8haCGszZ7Ty68HTadkun4wJXT5D59/27+XCXKgKpNVTWW6wlr5kuxyQPVf 88EUk6S05PNRYVTmC+sowUr+CUne/k8puvFQOYgdLe7cVPFbo3o4ZgvTxKX/A4dLPV SVG6anDAM5q5Q== X-Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, pabeni@redhat.com, virtualization@lists.linux.dev, parav@nvidia.com, yohadt@nvidia.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, jgg@ziepe.ca, kevin.tian@intel.com, kuba@kernel.org, andrew+netdev@lunn.ch, edumazet@google.com, danielj@nvidia.com X-In-Reply-To: <20261202150502.3350030-10-shshitrit@nvidia.com> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list