diff mbox series

bpf: fix: address of local auto-variable assigned to a function parameter.

Message ID 1608793298-123684-1-git-send-email-abaci-bugfix@linux.alibaba.com
State New
Headers show
Series bpf: fix: address of local auto-variable assigned to a function parameter. | expand

Commit Message

Abaci Team Dec. 24, 2020, 7:01 a.m. UTC
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.

Signed-off-by: YANG LI <abaci-bugfix@linux.alibaba.com>
Reported-by: Abaci <abaci@linux.alibaba.com>
---
 kernel/bpf/devmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Ahern Dec. 25, 2020, 12:49 a.m. UTC | #1
On 12/24/20 12:01 AM, YANG LI wrote:
> 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.


txq can only be accessed in this devmap context. Was it actually hit
during runtime or is this report based on code analysis?


> 

> Fix this error by defining the struct xdp_txq_info in function

> dev_map_run_prog() as a static type.

> 

> Signed-off-by: YANG LI <abaci-bugfix@linux.alibaba.com>

> Reported-by: Abaci <abaci@linux.alibaba.com>

> ---

>  kernel/bpf/devmap.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c

> index f6e9c68..af6f004 100644

> --- a/kernel/bpf/devmap.c

> +++ b/kernel/bpf/devmap.c

> @@ -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);

>
diff mbox series

Patch

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index f6e9c68..af6f004 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -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);