fix use after free
cover fix use after free
These are bug fixes reported by PVS studio. Later patches can consolidate the FOREACH_SAFE macros, but these patches are intended to fix the current bugs in main and stable branches.
Stephen Hemminger (2):
net/qede: fix use after free
bus/fslmc: fix use after free
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 10 +++++++++- drivers/net/qede/qede_filter.c | 20 ++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-)
Signature · 1 line
2.47.2
PATCH 1/2 net/qede: fix use after free
The loop cleaning up flowdir resources was using SLIST_FOREACH but the inner loop would call rte_free. Found by building with address sanitizer undefined check.
Also remove needless initialization, and null check.
--- drivers/net/qede/qede_filter.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/net/qede/qede_filter.c +12 -8
@@ -12,6 +12,13 @@#include "qede_ethdev.h" +#ifndef SLIST_FOREACH_SAFE +#define SLIST_FOREACH_SAFE (var, head, field, tvar) \ + for ((var) = SLIST_FIRST((head)); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) +#endif +/* VXLAN tunnel classification mapping */ const struct _qede_udp_tunn_types { uint16_t rte_filter_type;
@@ -154,15 +161,12 @@ int qede_check_fdir_support(struct rte_eth_dev *eth_dev)void qede_fdir_dealloc_resc (struct rte_eth_dev *eth_dev) {struct qede_dev *qdev =QEDE_INIT_QDEV (eth_dev); -struct qede_arfs_entry *tmp =NULL ; +struct qede_arfs_entry *tmp, *tmp2; - SLIST_FOREACH(tmp, &qdev->arfs_info.arfs_list_head, list) { -if (tmp) { -rte_memzone_free (tmp->mz); -SLIST_REMOVE (&qdev->arfs_info.arfs_list_head, tmp, - qede_arfs_entry, list); -rte_free (tmp); - } + SLIST_FOREACH_SAFE(tmp, &qdev->arfs_info.arfs_list_head, list, tmp2) { +rte_memzone_free (tmp->mz); +SLIST_REMOVE (&qdev->arfs_info.arfs_list_head, tmp, qede_arfs_entry, list); +rte_free (tmp); } }
Signature · 1 line
2.47.2
PATCH 2/2 bus/fslmc: fix use after free
In reply to Stephen HemmingerThe cleanup loop would deference the dpio_dev after freeing. Use TAILQ_FOREACH_SAFE to fix that.
Found by building with sanitizer undefined flag.
--- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +9 -1
@@ -38,6 +38,13 @@#include "dpaa2_hw_dpio.h" #include <mc/fsl_dpmng.h> +#ifndef TAILQ_FOREACH_SAFE +#define TAILQ_FOREACH_SAFE (var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) +#endif +#define NUM_HOST_CPUS RTE_MAX_LCOREstruct dpaa2_io_portal_t dpaa2_io_portal[RTE_MAX_LCORE ];
@@ -403,6 +410,7 @@ dpaa2_create_dpio_device(int vdev_fd, struct rte_dpaa2_device *obj) {struct dpaa2_dpio_dev *dpio_dev =NULL ; +struct dpaa2_dpio_dev *dpio_tmp;struct vfio_region_info reg_info = { .argsz =sizeof (reg_info)};struct qbman_swp_desc p_des;struct dpio_attr attr;
@@ -588,7 +596,7 @@ dpaa2_create_dpio_device(int vdev_fd,rte_free (dpio_dev);/* For each element in the list, cleanup */ - TAILQ_FOREACH(dpio_dev, &dpio_dev_list, next) { + TAILQ_FOREACH_SAFE(dpio_dev, &dpio_dev_list, next, dpio_tmp) {if (dpio_dev->dpio) {dpio_disable (dpio_dev->dpio,CMD_PRI_LOW , dpio_dev->token);
Signature · 1 line
2.47.2
Re: [PATCH 2/2] bus/fslmc: fix use after free
Quoted 1 line
The cleanup loop would deference the
dpio_devafter freeing.
…
dereference?
Regards,
Markus