diff mbox series

net: qrtr: Fix memory leak on qrtr_tx_wait failure

Message ID 1617113468-19222-1-git-send-email-loic.poulain@linaro.org (mailing list archive)
State Accepted
Commit 8a03dd925786bdc3834d56ccc980bb70668efa35
Delegated to: Netdev Maintainers
Headers show
Series net: qrtr: Fix memory leak on qrtr_tx_wait failure | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers warning 8 maintainers not CCed: paskripkin@gmail.com baijiaju1990@gmail.com wenhu.wang@vivo.com miaoqinglang@huawei.com dan.carpenter@oracle.com necip@google.com xiyou.wangcong@gmail.com edumazet@google.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 3
netdev/header_inline success Link

Commit Message

Loic Poulain March 30, 2021, 2:11 p.m. UTC
qrtr_tx_wait does not check for radix_tree_insert failure, causing
the 'flow' object to be unreferenced after qrtr_tx_wait return. Fix
that by releasing flow on radix_tree_insert failure.

Fixes: 5fdeb0d372ab ("net: qrtr: Implement outgoing flow control")
Reported-by: syzbot+739016799a89c530b32a@syzkaller.appspotmail.com
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
---
 net/qrtr/qrtr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Bjorn Andersson March 30, 2021, 3:15 p.m. UTC | #1
On Tue 30 Mar 09:11 CDT 2021, Loic Poulain wrote:

> qrtr_tx_wait does not check for radix_tree_insert failure, causing
> the 'flow' object to be unreferenced after qrtr_tx_wait return. Fix
> that by releasing flow on radix_tree_insert failure.
> 
> Fixes: 5fdeb0d372ab ("net: qrtr: Implement outgoing flow control")
> Reported-by: syzbot+739016799a89c530b32a@syzkaller.appspotmail.com
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
>  net/qrtr/qrtr.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
> index f4ab3ca6..a01b50c7 100644
> --- a/net/qrtr/qrtr.c
> +++ b/net/qrtr/qrtr.c
> @@ -271,7 +271,10 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
>  		flow = kzalloc(sizeof(*flow), GFP_KERNEL);
>  		if (flow) {
>  			init_waitqueue_head(&flow->resume_tx);
> -			radix_tree_insert(&node->qrtr_tx_flow, key, flow);
> +			if (radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
> +				kfree(flow);
> +				flow = NULL;
> +			}
>  		}
>  	}
>  	mutex_unlock(&node->qrtr_tx_lock);
> -- 
> 2.7.4
>
Manivannan Sadhasivam March 30, 2021, 5:09 p.m. UTC | #2
On Tue, Mar 30, 2021 at 04:11:08PM +0200, Loic Poulain wrote:
> qrtr_tx_wait does not check for radix_tree_insert failure, causing
> the 'flow' object to be unreferenced after qrtr_tx_wait return. Fix
> that by releasing flow on radix_tree_insert failure.
> 
> Fixes: 5fdeb0d372ab ("net: qrtr: Implement outgoing flow control")
> Reported-by: syzbot+739016799a89c530b32a@syzkaller.appspotmail.com
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

Thanks,
Mani

> ---
>  net/qrtr/qrtr.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
> index f4ab3ca6..a01b50c7 100644
> --- a/net/qrtr/qrtr.c
> +++ b/net/qrtr/qrtr.c
> @@ -271,7 +271,10 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
>  		flow = kzalloc(sizeof(*flow), GFP_KERNEL);
>  		if (flow) {
>  			init_waitqueue_head(&flow->resume_tx);
> -			radix_tree_insert(&node->qrtr_tx_flow, key, flow);
> +			if (radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
> +				kfree(flow);
> +				flow = NULL;
> +			}
>  		}
>  	}
>  	mutex_unlock(&node->qrtr_tx_lock);
> -- 
> 2.7.4
>
patchwork-bot+netdevbpf@kernel.org March 30, 2021, 8:50 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Tue, 30 Mar 2021 16:11:08 +0200 you wrote:
> qrtr_tx_wait does not check for radix_tree_insert failure, causing
> the 'flow' object to be unreferenced after qrtr_tx_wait return. Fix
> that by releasing flow on radix_tree_insert failure.
> 
> Fixes: 5fdeb0d372ab ("net: qrtr: Implement outgoing flow control")
> Reported-by: syzbot+739016799a89c530b32a@syzkaller.appspotmail.com
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
> 
> [...]

Here is the summary with links:
  - net: qrtr: Fix memory leak on qrtr_tx_wait failure
    https://git.kernel.org/netdev/net/c/8a03dd925786

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
index f4ab3ca6..a01b50c7 100644
--- a/net/qrtr/qrtr.c
+++ b/net/qrtr/qrtr.c
@@ -271,7 +271,10 @@  static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
 		flow = kzalloc(sizeof(*flow), GFP_KERNEL);
 		if (flow) {
 			init_waitqueue_head(&flow->resume_tx);
-			radix_tree_insert(&node->qrtr_tx_flow, key, flow);
+			if (radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
+				kfree(flow);
+				flow = NULL;
+			}
 		}
 	}
 	mutex_unlock(&node->qrtr_tx_lock);