Message ID | 20210723153132.6159-1-paskripkin@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 52f3456a96c06760b9bfae460e39596fec7af22e |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [v2] net: qrtr: fix memory leaks | expand |
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 | fail | 1 blamed authors not CCed: courtney.cavin@sonymobile.com; 2 maintainers not CCed: linux-arm-msm@vger.kernel.org courtney.cavin@sonymobile.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, 19 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 3 this patch: 3 |
netdev/header_inline | success | Link |
On Fri, Jul 23, 2021 at 06:31:32PM +0300, Pavel Skripkin wrote: > Syzbot reported memory leak in qrtr. The problem was in unputted > struct sock. qrtr_local_enqueue() function calls qrtr_port_lookup() > which takes sock reference if port was found. Then there is the following > check: > > if (!ipc || &ipc->sk == skb->sk) { > ... > return -ENODEV; > } > > Since we should drop the reference before returning from this function and > ipc can be non-NULL inside this if, we should add qrtr_port_put() inside > this if. > > The similar corner case is in qrtr_endpoint_post() as Manivannan > reported. In case of sock_queue_rcv_skb() failure we need to put > port reference to avoid leaking struct sock pointer. > > Fixes: e04df98adf7d ("net: qrtr: Remove receive worker") > Fixes: bdabad3e363d ("net: Add Qualcomm IPC router") > Reported-and-tested-by: syzbot+35a511c72ea7356cdcf3@syzkaller.appspotmail.com > Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> Reviewed-by: Manivannan Sadhasivam <mani@kernel.org> Thanks, Mani > --- > > Changes in v2: > Added missing qrtr_port_put() in qrtr_endpoint_post() as Manivannan > reported. > > --- > net/qrtr/qrtr.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c > index b34358282f37..a8b2c9b21a8d 100644 > --- a/net/qrtr/qrtr.c > +++ b/net/qrtr/qrtr.c > @@ -514,8 +514,10 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) > if (!ipc) > goto err; > > - if (sock_queue_rcv_skb(&ipc->sk, skb)) > + if (sock_queue_rcv_skb(&ipc->sk, skb)) { > + qrtr_port_put(ipc); > goto err; > + } > > qrtr_port_put(ipc); > } > @@ -850,6 +852,8 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, > > ipc = qrtr_port_lookup(to->sq_port); > if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */ > + if (ipc) > + qrtr_port_put(ipc); > kfree_skb(skb); > return -ENODEV; > } > -- > 2.32.0 >
Hello: This patch was applied to netdev/net.git (refs/heads/master): On Fri, 23 Jul 2021 18:31:32 +0300 you wrote: > Syzbot reported memory leak in qrtr. The problem was in unputted > struct sock. qrtr_local_enqueue() function calls qrtr_port_lookup() > which takes sock reference if port was found. Then there is the following > check: > > if (!ipc || &ipc->sk == skb->sk) { > ... > return -ENODEV; > } > > [...] Here is the summary with links: - [v2] net: qrtr: fix memory leaks https://git.kernel.org/netdev/net/c/52f3456a96c0 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index b34358282f37..a8b2c9b21a8d 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -514,8 +514,10 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) if (!ipc) goto err; - if (sock_queue_rcv_skb(&ipc->sk, skb)) + if (sock_queue_rcv_skb(&ipc->sk, skb)) { + qrtr_port_put(ipc); goto err; + } qrtr_port_put(ipc); } @@ -850,6 +852,8 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, ipc = qrtr_port_lookup(to->sq_port); if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */ + if (ipc) + qrtr_port_put(ipc); kfree_skb(skb); return -ENODEV; }
Syzbot reported memory leak in qrtr. The problem was in unputted struct sock. qrtr_local_enqueue() function calls qrtr_port_lookup() which takes sock reference if port was found. Then there is the following check: if (!ipc || &ipc->sk == skb->sk) { ... return -ENODEV; } Since we should drop the reference before returning from this function and ipc can be non-NULL inside this if, we should add qrtr_port_put() inside this if. The similar corner case is in qrtr_endpoint_post() as Manivannan reported. In case of sock_queue_rcv_skb() failure we need to put port reference to avoid leaking struct sock pointer. Fixes: e04df98adf7d ("net: qrtr: Remove receive worker") Fixes: bdabad3e363d ("net: Add Qualcomm IPC router") Reported-and-tested-by: syzbot+35a511c72ea7356cdcf3@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> --- Changes in v2: Added missing qrtr_port_put() in qrtr_endpoint_post() as Manivannan reported. --- net/qrtr/qrtr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)