diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-08-30 09:22:00 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-08-30 09:22:00 -0700 |
| commit | 034dd340b08be1f2f0477ad16131d609f9dbd53c (patch) | |
| tree | 2536f4b2d7893ccd916b5abdf3c454ad6edc03c2 /drivers/net/ipvlan/ipvtap.c | |
| download | linux-stable-034dd340b08be1f2f0477ad16131d609f9dbd53c.tar.gz linux-stable-034dd340b08be1f2f0477ad16131d609f9dbd53c.zip | |
Merge tag 'trace-v7.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-tracegrafted
Pull tracing fixes from Steven Rostedt:
- Fix error output of boot instance creation failure
Currently if a boot instance creation fails, instead of printing out
the name of the instance that failed, it prints "(null)". That is
because it prints "cur_str" that had already been processed by
strsep(). Print the saved name instead.
While at it, print the error code of the failure.
- Fix use-after-free for same named historgrams
Histograms can be named so that they can be used in multiple events.
But if the named histogram has a variable attached, the second event
that uses the named histogram which duplicates it and needs to free
the original after duplication leaves the old variable in place and
still visible. If another histogram uses than variable, it will use
the stale one which will try to reference the freed duplicate
histogram and crash the kernel.
Free the duplicate variables along with the duplicated histogram
data.
- Check return value of kthread_run() in event self test
The events self tests uses a kthread for testing but does not check
if it succeeded in creating a kthread. If the kthread creation were
to fail, the code will still try to call kthread_stop() on the error
returned.
- Fix race between reading trace_pipe and updating subbuffer size
If a user is reading the trace_pipe file at the same time they update
the ring buffer sub-buffer size, can cause the trace_pipe read to
read stale data. Add trace_access_lock() around updating the ring
buffer sub-buffer size.
- Fix eventfs_inode on failure path in creation of the events directory
In the creation of the "events" directory, if after allocating the
eventfs_inode a failure is detected, it calls cleanup_ei() which
calls free_ei(). The free_ei() will test if eventfs_inode being freed
has no children. It is a bug if it does. But on the failure case of
the creation of the "events" directory, the children lists have not
yet been initialized and the free will trigger a warning because
list_empty() on an uninitialized list returns false.
Move the initialization into init_ei() where it makes more sense and
makes sure that a created eventfs_inode has its lists initialized
upon creation.
- Check return value of kthread_run() in ftrace direct sample code
The sample code that shows how to use the ftrace direct calls does
not test the return of kthread_run() to see if it succeeds. Return a
failure if the kthread_run() doesn't succeed.
- Clear user events state on fork in case of alloc failure
On fork, the child gets a pointer to the parent's user events state.
It makes a copy of it then updates the child's pointer to it. But if
the allocation fails, the duplication function leaves the child with
a pointer to its parent's descriptor. When the child cleans up its
data, it will free the parent's descriptor while the parent is still
using it.
In the duplication function, set the child's user_event_mm to NULL
before testing if the allocation succeeded, and when it exits it will
not free the parent's descriptor.
- Fix retry exhaustion in simple ring buffer reader swap
simple_ring_buffer_swap_reader_page() starts with retry set to 8 and
post-decrements it only after a failed link replacement. On the final
attempt, a successful replacement leaves retry at zero, while a
failed replacement leaves it at -1.
But the check for success expects the retry value to be non-zero and
exits with an error on zero. This is the opposite result. Fix it.
- Fail nicely when the remote swap_reader_page() returns an error
Currently, if the swap_reader_page() of a remote buffer fails, it
triggers a WARN_ON_ONCE() and continues normally. Instead, have it
exit with an error and a pr_warn() print instead of a full WARNING.
* tag 'trace-v7.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
ring-buffer: Stop remote reader update when page swap fails
tracing: Fix retry exhaustion in simple ring buffer reader swap
tracing/user_events: Clear copied tracing state before fork duplication
samples/ftrace: Fix kthread_stop() on ERR_PTR in ftrace-direct-multi-modify
samples/ftrace: Fix kthread_stop() on ERR_PTR in ftrace-direct-modify
eventfs: Initialize ei->children and ei->list in init_ei()
tracing: Fix use-after-free in trace_pipe read on sub-buffer order change
tracing: Fix crash passing ERR_PTR to kthread_stop()
tracing: Fix use-after-free with same-name named triggers
tracing: Fix logged instance name on creation failure
Diffstat (limited to 'drivers/net/ipvlan/ipvtap.c')
| -rw-r--r-- | drivers/net/ipvlan/ipvtap.c | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/drivers/net/ipvlan/ipvtap.c b/drivers/net/ipvlan/ipvtap.c new file mode 100644 index 000000000..66c949d94 --- /dev/null +++ b/drivers/net/ipvlan/ipvtap.c @@ -0,0 +1,259 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <linux/etherdevice.h> +#include "ipvlan.h" +#include <linux/if_vlan.h> +#include <linux/if_tap.h> +#include <linux/interrupt.h> +#include <linux/nsproxy.h> +#include <linux/compat.h> +#include <linux/if_tun.h> +#include <linux/module.h> +#include <linux/skbuff.h> +#include <linux/cache.h> +#include <linux/sched.h> +#include <linux/types.h> +#include <linux/slab.h> +#include <linux/wait.h> +#include <linux/cdev.h> +#include <linux/idr.h> +#include <linux/fs.h> +#include <linux/uio.h> + +#include <net/net_namespace.h> +#include <net/rtnetlink.h> +#include <net/sock.h> +#include <linux/virtio_net.h> + +#define TUN_OFFLOADS (NETIF_F_HW_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ + NETIF_F_TSO6) + +static dev_t ipvtap_major; +static struct cdev ipvtap_cdev; + +static const struct ns_common *ipvtap_net_namespace(const struct device *d) +{ + const struct net_device *dev = to_net_dev(d->parent); + + return to_ns_common(dev_net(dev)); +} + +static struct class ipvtap_class = { + .name = "ipvtap", + .ns_type = &net_ns_type_operations, + .namespace = ipvtap_net_namespace, +}; + +struct ipvtap_dev { + struct ipvl_dev vlan; + struct tap_dev tap; +}; + +static void ipvtap_count_tx_dropped(struct tap_dev *tap) +{ + struct ipvtap_dev *vlantap = container_of(tap, struct ipvtap_dev, tap); + struct ipvl_dev *vlan = &vlantap->vlan; + + this_cpu_inc(vlan->pcpu_stats->tx_drps); +} + +static void ipvtap_count_rx_dropped(struct tap_dev *tap) +{ + struct ipvtap_dev *vlantap = container_of(tap, struct ipvtap_dev, tap); + struct ipvl_dev *vlan = &vlantap->vlan; + + ipvlan_count_rx(vlan, 0, 0, 0); +} + +static void ipvtap_update_features(struct tap_dev *tap, + netdev_features_t features) +{ + struct ipvtap_dev *vlantap = container_of(tap, struct ipvtap_dev, tap); + struct ipvl_dev *vlan = &vlantap->vlan; + + vlan->sfeatures = features; + netdev_update_features(vlan->dev); +} + +static int ipvtap_newlink(struct net_device *dev, + struct rtnl_newlink_params *params, + struct netlink_ext_ack *extack) +{ + struct ipvtap_dev *vlantap = netdev_priv(dev); + int err; + + INIT_LIST_HEAD(&vlantap->tap.queue_list); + + /* Since macvlan supports all offloads by default, make + * tap support all offloads also. + */ + vlantap->tap.tap_features = TUN_OFFLOADS; + vlantap->tap.count_tx_dropped = ipvtap_count_tx_dropped; + vlantap->tap.update_features = ipvtap_update_features; + vlantap->tap.count_rx_dropped = ipvtap_count_rx_dropped; + + err = netdev_rx_handler_register(dev, tap_handle_frame, &vlantap->tap); + if (err) + return err; + + /* Don't put anything that may fail after macvlan_common_newlink + * because we can't undo what it does. + */ + err = ipvlan_link_new(dev, params, extack); + if (err) { + netdev_rx_handler_unregister(dev); + return err; + } + + vlantap->tap.dev = vlantap->vlan.dev; + + return err; +} + +static void __ipvtap_dellink(struct net *net, struct net_device *dev, + struct list_head *head) +{ + struct ipvtap_dev *vlantap = netdev_priv(dev); + + netdev_rx_handler_unregister(dev); + tap_del_queues(&vlantap->tap); + __ipvlan_link_delete(net, dev, head); +} + +static void ipvtap_dellink(struct net_device *dev, + struct list_head *head) +{ + struct ipvtap_dev *vlantap = netdev_priv(dev); + struct ipvl_port *port = vlantap->vlan.port; + + mutex_lock(&port->pnodes_lock); + if (!vlantap->vlan.dying) + __ipvtap_dellink(dev_net(dev), dev, head); + mutex_unlock(&port->pnodes_lock); +} + +static void ipvtap_setup(struct net_device *dev) +{ + ipvlan_link_setup(dev); + dev->tx_queue_len = TUN_READQ_SIZE; + dev->priv_flags &= ~IFF_NO_QUEUE; +} + +static struct rtnl_link_ops ipvtap_link_ops __read_mostly = { + .kind = "ipvtap", + .setup = ipvtap_setup, + .newlink = ipvtap_newlink, + .dellink = ipvtap_dellink, + .priv_size = sizeof(struct ipvtap_dev), +}; + +static int ipvtap_device_event(struct notifier_block *unused, + unsigned long event, void *ptr) +{ + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + struct ipvtap_dev *vlantap; + struct device *classdev; + dev_t devt; + int err; + char tap_name[IFNAMSIZ]; + + if (dev->rtnl_link_ops != &ipvtap_link_ops) + return NOTIFY_DONE; + + snprintf(tap_name, IFNAMSIZ, "tap%d", dev->ifindex); + vlantap = netdev_priv(dev); + + switch (event) { + case NETDEV_REGISTER: + /* Create the device node here after the network device has + * been registered but before register_netdevice has + * finished running. + */ + err = tap_get_minor(ipvtap_major, &vlantap->tap); + if (err) + return notifier_from_errno(err); + + devt = MKDEV(MAJOR(ipvtap_major), vlantap->tap.minor); + classdev = device_create(&ipvtap_class, &dev->dev, devt, + dev, "%s", tap_name); + if (IS_ERR(classdev)) { + tap_free_minor(ipvtap_major, &vlantap->tap); + return notifier_from_errno(PTR_ERR(classdev)); + } + err = sysfs_create_link(&dev->dev.kobj, &classdev->kobj, + tap_name); + if (err) + return notifier_from_errno(err); + break; + case NETDEV_UNREGISTER: + /* vlan->minor == 0 if NETDEV_REGISTER above failed */ + if (vlantap->tap.minor == 0) + break; + sysfs_remove_link(&dev->dev.kobj, tap_name); + devt = MKDEV(MAJOR(ipvtap_major), vlantap->tap.minor); + device_destroy(&ipvtap_class, devt); + tap_free_minor(ipvtap_major, &vlantap->tap); + break; + case NETDEV_CHANGE_TX_QUEUE_LEN: + if (tap_queue_resize(&vlantap->tap)) + return NOTIFY_BAD; + break; + } + + return NOTIFY_DONE; +} + +static struct notifier_block ipvtap_notifier_block __read_mostly = { + .notifier_call = ipvtap_device_event, +}; + +static int __init ipvtap_init(void) +{ + int err; + + __ipvtap_dellink_ptr = __ipvtap_dellink; + + err = tap_create_cdev(&ipvtap_cdev, &ipvtap_major, "ipvtap", + THIS_MODULE); + if (err) + goto out1; + + err = class_register(&ipvtap_class); + if (err) + goto out2; + + err = register_netdevice_notifier(&ipvtap_notifier_block); + if (err) + goto out3; + + err = ipvlan_link_register(&ipvtap_link_ops); + if (err) + goto out4; + + return 0; + +out4: + unregister_netdevice_notifier(&ipvtap_notifier_block); +out3: + class_unregister(&ipvtap_class); +out2: + tap_destroy_cdev(ipvtap_major, &ipvtap_cdev); +out1: + __ipvtap_dellink_ptr = NULL; + + return err; +} +module_init(ipvtap_init); + +static void __exit ipvtap_exit(void) +{ + rtnl_link_unregister(&ipvtap_link_ops); + unregister_netdevice_notifier(&ipvtap_notifier_block); + class_unregister(&ipvtap_class); + tap_destroy_cdev(ipvtap_major, &ipvtap_cdev); + __ipvtap_dellink_ptr = NULL; +} +module_exit(ipvtap_exit); +MODULE_ALIAS_RTNL_LINK("ipvtap"); +MODULE_AUTHOR("Sainath Grandhi <sainath.grandhi@intel.com>"); +MODULE_DESCRIPTION("IP-VLAN based tap driver"); +MODULE_LICENSE("GPL"); |
