All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: fix: address of local auto-variable assigned to a function parameter.
@ 2020-12-24  7:01 YANG LI
  2020-12-24  7:31 ` Yonghong Song
  2020-12-25  0:49 ` David Ahern
  0 siblings, 2 replies; 3+ messages in thread
From: YANG LI @ 2020-12-24  7:01 UTC (permalink / raw)
  To: ast
  Cc: daniel, davem, kuba, hawk, john.fastabend, andrii, kafai,
	songliubraving, yhs, kpsingh, netdev, bpf, linux-kernel, YANG LI

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(-)

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf: fix: address of local auto-variable assigned to a function parameter.
  2020-12-24  7:01 [PATCH] bpf: fix: address of local auto-variable assigned to a function parameter YANG LI
@ 2020-12-24  7:31 ` Yonghong Song
  2020-12-25  0:49 ` David Ahern
  1 sibling, 0 replies; 3+ messages in thread
From: Yonghong Song @ 2020-12-24  7:31 UTC (permalink / raw)
  To: YANG LI, ast
  Cc: daniel, davem, kuba, hawk, john.fastabend, andrii, kafai,
	songliubraving, kpsingh, netdev, bpf, linux-kernel



On 12/23/20 11:01 PM, 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.
> 
> 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);

exposing txq outside the routine with 'static' definition is not
a good practice. maybe just reset xdp->txq = NULl right before
function return?

diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index f6e9c68afdd4..50f5c20a33a3 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -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$

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf: fix: address of local auto-variable assigned to a function parameter.
  2020-12-24  7:01 [PATCH] bpf: fix: address of local auto-variable assigned to a function parameter YANG LI
  2020-12-24  7:31 ` Yonghong Song
@ 2020-12-25  0:49 ` David Ahern
  1 sibling, 0 replies; 3+ messages in thread
From: David Ahern @ 2020-12-25  0:49 UTC (permalink / raw)
  To: YANG LI, ast
  Cc: daniel, davem, kuba, hawk, john.fastabend, andrii, kafai,
	songliubraving, yhs, kpsingh, netdev, bpf, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-25  0:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-24  7:01 [PATCH] bpf: fix: address of local auto-variable assigned to a function parameter YANG LI
2020-12-24  7:31 ` Yonghong Song
2020-12-25  0:49 ` David Ahern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.