Message ID | 20210722161625.6956-1-paskripkin@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: qrtr: fix memory leak in qrtr_local_enqueue | 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 | success | CCed 7 of 7 maintainers |
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, 8 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 3 this patch: 3 |
netdev/header_inline | success | Link |
On Thu, Jul 22, 2021 at 07:16:25PM +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. > > 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> It'd be good if this patch can be extended to fix one more corner case here: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/qrtr/qrtr.c#n522 Thanks, Mani > --- > net/qrtr/qrtr.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c > index e6f4a6202f82..d5ce428d0b25 100644 > --- a/net/qrtr/qrtr.c > +++ b/net/qrtr/qrtr.c > @@ -839,6 +839,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 >
On Fri, 23 Jul 2021 17:57:53 +0530 Manivannan Sadhasivam <mani@kernel.org> wrote: > On Thu, Jul 22, 2021 at 07:16:25PM +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. > > > > 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> > > It'd be good if this patch can be extended to fix one more corner > case here: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/qrtr/qrtr.c#n522 > > Thanks, > Mani Hi, Manivannan! I will fix leak there too in v2, thank you! With regards, Pavel Skripkin > > > --- > > net/qrtr/qrtr.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c > > index e6f4a6202f82..d5ce428d0b25 100644 > > --- a/net/qrtr/qrtr.c > > +++ b/net/qrtr/qrtr.c > > @@ -839,6 +839,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 > >
diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index e6f4a6202f82..d5ce428d0b25 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -839,6 +839,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. Fixes: bdabad3e363d ("net: Add Qualcomm IPC router") Reported-and-tested-by: syzbot+35a511c72ea7356cdcf3@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> --- net/qrtr/qrtr.c | 2 ++ 1 file changed, 2 insertions(+)