bpf: fix: address of local auto-variable assigned to a function parameter.
Subsystems (4)
PATCH 1/1 bpf: fix: address of local auto-variable assigned to a function parameter.
Assigning local variable txq to the outputting parameter xdp->txq is not safe, txq will be released after the end of the function call. Then the result of using xdp is unpredictable.
Fix this error by defining the struct xdp_txq_info in function dev_map_run_prog() as a static type.
--- kernel/bpf/devmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/devmap.c +1 -1
@@ -454,7 +454,7 @@ static struct xdp_buff *dev_map_run_prog(struct net_device *dev,struct xdp_buff *xdp, struct bpf_prog *xdp_prog) { - struct xdp_txq_info txq = { .dev = dev }; + static struct xdp_txq_info txq = { .dev = dev };u32 act;xdp_set_data_meta_invalid (xdp);
Signature · 1 line
1.8.3.1
Quoted 18 lines · YANG LI
Assigning local variable txq to the outputting parameter
xdp->txqis not safe, txq will be released after the end of the function call. Then the result of using xdp is unpredictable.Fix this error by defining the struct
xdp_txq_infoin functiondev_map_run_prog()as a static type.Signed-off-by YANG LI <[email protected]>Reported-by Abaci <[email protected]>--- kernel/bpf/devmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/devmap.c +0
-0
kernel/bpf/devmap.c static struct xdp_buff *dev_map_run_prog(struct net_device *dev, · line 460
Quoted 8 lines
kernel/bpf/devmap.c +1
-1@@ -454,7 +454,7 @@ static struct xdp_buff *dev_map_run_prog(struct net_device *dev,struct xdp_buff *xdp, struct bpf_prog *xdp_prog) { - struct xdp_txq_info txq = { .dev = dev }; + static struct xdp_txq_info txq = { .dev = dev };u32 act;xdp_set_data_meta_invalid (xdp);
exposing txq outside the routine with 'static' definition is not a good practice. maybe just reset xdp->txq = NULl right before function return?
kernel/bpf/devmap.c +1 -0
@@ -475,6 +475,7 @@ static struct xdp_buff *dev_map_run_prog(struct net_device *dev, }xdp_return_buff (xdp); + xdp->txq =NULL ;return NULL ; }
-bash-4.4$
Quoted 3 lines · YANG LI
Assigning local variable txq to the outputting parameter
xdp->txqis not safe, txq will be released after the end of the function call. Then the result of using xdp is unpredictable.
txq can only be accessed in this devmap context. Was it actually hit during runtime or is this report based on code analysis?
Quoted 24 lines
Fix this error by defining the struct
xdp_txq_infoin functiondev_map_run_prog()as a static type.Signed-off-by YANG LI <[email protected]>Reported-by Abaci <[email protected]>--- kernel/bpf/devmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/devmap.c +1
-1@@ -454,7 +454,7 @@ static struct xdp_buff *dev_map_run_prog(struct net_device *dev,struct xdp_buff *xdp, struct bpf_prog *xdp_prog) { - struct xdp_txq_info txq = { .dev = dev }; + static struct xdp_txq_info txq = { .dev = dev };u32 act;xdp_set_data_meta_invalid (xdp);