* memory leak in tipc_group_create_member
@ 2019-08-02 2:38 syzbot
2019-08-02 12:18 ` Ying Xue
2020-09-12 10:22 ` Peilin Ye
0 siblings, 2 replies; 12+ messages in thread
From: syzbot @ 2019-08-02 2:38 UTC (permalink / raw)
To: davem, jon.maloy, linux-kernel, netdev, syzkaller-bugs,
tipc-discussion, ying.xue
Hello,
syzbot found the following crash on:
HEAD commit: a9815a4f Merge branch 'x86-urgent-for-linus' of git://git...
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=12a6dbf0600000
kernel config: https://syzkaller.appspot.com/x/.config?x=37c48fb52e3789e6
dashboard link: https://syzkaller.appspot.com/bug?extid=f95d90c454864b3b5bc9
compiler: gcc (GCC) 9.0.0 20181231 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13be3ecc600000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11c992b4600000
IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com
executing program
BUG: memory leak
unreferenced object 0xffff888122bca200 (size 128):
comm "syz-executor232", pid 7065, jiffies 4294943817 (age 8.880s)
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 18 a2 bc 22 81 88 ff ff ..........."....
backtrace:
[<000000005bada299>] kmemleak_alloc_recursive
include/linux/kmemleak.h:43 [inline]
[<000000005bada299>] slab_post_alloc_hook mm/slab.h:522 [inline]
[<000000005bada299>] slab_alloc mm/slab.c:3319 [inline]
[<000000005bada299>] kmem_cache_alloc_trace+0x145/0x2c0 mm/slab.c:3548
[<00000000e7bcdc9f>] kmalloc include/linux/slab.h:552 [inline]
[<00000000e7bcdc9f>] kzalloc include/linux/slab.h:748 [inline]
[<00000000e7bcdc9f>] tipc_group_create_member+0x3c/0x190
net/tipc/group.c:306
[<0000000005f56f40>] tipc_group_add_member+0x34/0x40
net/tipc/group.c:327
[<0000000044406683>] tipc_nametbl_build_group+0x9b/0xf0
net/tipc/name_table.c:600
[<000000009f71e803>] tipc_sk_join net/tipc/socket.c:2901 [inline]
[<000000009f71e803>] tipc_setsockopt+0x170/0x490 net/tipc/socket.c:3006
[<000000007f61cbc2>] __sys_setsockopt+0x10f/0x220 net/socket.c:2084
[<00000000cc630372>] __do_sys_setsockopt net/socket.c:2100 [inline]
[<00000000cc630372>] __se_sys_setsockopt net/socket.c:2097 [inline]
[<00000000cc630372>] __x64_sys_setsockopt+0x26/0x30 net/socket.c:2097
[<00000000ec30be33>] do_syscall_64+0x76/0x1a0
arch/x86/entry/common.c:296
[<00000000271be3e6>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.
syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: memory leak in tipc_group_create_member
2019-08-02 2:38 memory leak in tipc_group_create_member syzbot
@ 2019-08-02 12:18 ` Ying Xue
2020-09-12 10:22 ` Peilin Ye
1 sibling, 0 replies; 12+ messages in thread
From: Ying Xue @ 2019-08-02 12:18 UTC (permalink / raw)
To: Hillf Danton, syzbot
Cc: davem, jon.maloy, linux-kernel, netdev, syzkaller-bugs, tipc-discussion
On 8/2/19 3:44 PM, Hillf Danton wrote:
>
> On Thu, 01 Aug 2019 19:38:06 -0700
>> Hello,
>>
>> syzbot found the following crash on:
>>
>> HEAD commit: a9815a4f Merge branch 'x86-urgent-for-linus' of git://git...
>> git tree: upstream
>> console output: https://syzkaller.appspot.com/x/log.txt?x=12a6dbf0600000
>> kernel config: https://syzkaller.appspot.com/x/.config?x=37c48fb52e3789e6
>> dashboard link: https://syzkaller.appspot.com/bug?extid=f95d90c454864b3b5bc9
>> compiler: gcc (GCC) 9.0.0 20181231 (experimental)
>> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13be3ecc600000
>> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11c992b4600000
>>
>> IMPORTANT: if you fix the bug, please add the following tag to the commit:
>> Reported-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com
>>
>> executing program
>> BUG: memory leak
>> unreferenced object 0xffff888122bca200 (size 128):
>> comm "syz-executor232", pid 7065, jiffies 4294943817 (age 8.880s)
>> hex dump (first 32 bytes):
>> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
>> 00 00 00 00 00 00 00 00 18 a2 bc 22 81 88 ff ff ..........."....
>> backtrace:
>> [<000000005bada299>] kmemleak_alloc_recursive include/linux/kmemleak.h:43 [inline]
>> [<000000005bada299>] slab_post_alloc_hook mm/slab.h:522 [inline]
>> [<000000005bada299>] slab_alloc mm/slab.c:3319 [inline]
>> [<000000005bada299>] kmem_cache_alloc_trace+0x145/0x2c0 mm/slab.c:3548
>> [<00000000e7bcdc9f>] kmalloc include/linux/slab.h:552 [inline]
>> [<00000000e7bcdc9f>] kzalloc include/linux/slab.h:748 [inline]
>> [<00000000e7bcdc9f>] tipc_group_create_member+0x3c/0x190 net/tipc/group.c:306
>> [<0000000005f56f40>] tipc_group_add_member+0x34/0x40 net/tipc/group.c:327
>> [<0000000044406683>] tipc_nametbl_build_group+0x9b/0xf0 net/tipc/name_table.c:600
>> [<000000009f71e803>] tipc_sk_join net/tipc/socket.c:2901 [inline]
>> [<000000009f71e803>] tipc_setsockopt+0x170/0x490 net/tipc/socket.c:3006
>> [<000000007f61cbc2>] __sys_setsockopt+0x10f/0x220 net/socket.c:2084
>> [<00000000cc630372>] __do_sys_setsockopt net/socket.c:2100 [inline]
>> [<00000000cc630372>] __se_sys_setsockopt net/socket.c:2097 [inline]
>> [<00000000cc630372>] __x64_sys_setsockopt+0x26/0x30 net/socket.c:2097
>> [<00000000ec30be33>] do_syscall_64+0x76/0x1a0 arch/x86/entry/common.c:296
>> [<00000000271be3e6>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
>>
Acked-by: Ying Xue <ying.xue@windriver.com>
>
> --- a/net/tipc/group.c
> +++ b/net/tipc/group.c
> @@ -273,7 +273,7 @@ static struct tipc_member *tipc_group_fi
> return NULL;
> }
>
> -static void tipc_group_add_to_tree(struct tipc_group *grp,
> +static struct tipc_member *tipc_group_add_to_tree(struct tipc_group *grp,
> struct tipc_member *m)
> {
> u64 nkey, key = (u64)m->node << 32 | m->port;
> @@ -282,7 +282,6 @@ static void tipc_group_add_to_tree(struc
>
> n = &grp->members.rb_node;
> while (*n) {
> - tmp = container_of(*n, struct tipc_member, tree_node);
> parent = *n;
> tmp = container_of(parent, struct tipc_member, tree_node);
> nkey = (u64)tmp->node << 32 | tmp->port;
> @@ -291,17 +290,18 @@ static void tipc_group_add_to_tree(struc
> else if (key > nkey)
> n = &(*n)->rb_right;
> else
> - return;
> + return tmp;
> }
> rb_link_node(&m->tree_node, parent, n);
> rb_insert_color(&m->tree_node, &grp->members);
> + return m;
> }
>
> static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
> u32 node, u32 port,
> u32 instance, int state)
> {
> - struct tipc_member *m;
> + struct tipc_member *m, *n;
>
> m = kzalloc(sizeof(*m), GFP_ATOMIC);
> if (!m)
> @@ -315,10 +315,14 @@ static struct tipc_member *tipc_group_cr
> m->instance = instance;
> m->bc_acked = grp->bc_snd_nxt - 1;
> grp->member_cnt++;
> - tipc_group_add_to_tree(grp, m);
> - tipc_nlist_add(&grp->dests, m->node);
> - m->state = state;
> - return m;
> + n = tipc_group_add_to_tree(grp, m);
> + if (n == m) {
> + tipc_nlist_add(&grp->dests, m->node);
> + m->state = state;
> + } else {
> + kfree(m);
> + }
> + return n;
> }
>
> void tipc_group_add_member(struct tipc_group *grp, u32 node,
> --
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Linux-kernel-mentees] [PATCH net] tipc: Fix memory leak in tipc_group_create_member()
2019-08-02 2:38 memory leak in tipc_group_create_member syzbot
@ 2020-09-12 10:22 ` Peilin Ye
2020-09-12 10:22 ` Peilin Ye
1 sibling, 0 replies; 12+ messages in thread
From: Peilin Ye @ 2020-09-12 10:22 UTC (permalink / raw)
To: Jon Maloy, Ying Xue
Cc: Peilin Ye, David S. Miller, Jakub Kicinski, Hillf Danton,
Greg Kroah-Hartman, netdev, tipc-discussion,
linux-kernel-mentees, syzkaller-bugs, linux-kernel
tipc_group_add_to_tree() returns silently if `key` matches `nkey` of an
existing node, causing tipc_group_create_member() to leak memory. Let
tipc_group_add_to_tree() return an error in such a case, so that
tipc_group_create_member() can handle it properly.
Fixes: 75da2163dbb6 ("tipc: introduce communication groups")
Reported-and-tested-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com
Cc: Hillf Danton <hdanton@sina.com>
Link: https://syzkaller.appspot.com/bug?id=048390604fe1b60df34150265479202f10e13aff
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
Decoded syzbot reproducer in pseudo-C:
fd0 = socket(AF_TIPC, SOCK_DGRAM, 0);
sockaddr_tipc.family = AF_TIPC;
sockaddr_tipc.addrtype = TIPC_ADDR_NAMESEQ;
sockaddr_tipc.scope = 0;
sockaddr_tipc.addr.namesq.type = TIPC_RESERVED_TYPES + 1;
bind(fd0, &sockaddr_tipc, sizeof(sockaddr_tipc));
tipc_group_req0.type = TIPC_RESERVED_TYPES + 1;
setsockopt(fd0, SOL_TIPC, TIPC_GROUP_JOIN, &tipc_group_req0, sizeof(tipc_group_req0));
fd1 = socket(AF_TIPC, SOCK_STREAM, 0);
tipc_group_req1.type = TIPC_RESERVED_TYPES + 1;
tipc_group_req1.scope = TIPC_CLUSTER_SCOPE;
setsockopt(fd1, SOL_TIPC, TIPC_GROUP_JOIN, &tipc_group_req1, sizeof(tipc_group_req1));
net/tipc/group.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/tipc/group.c b/net/tipc/group.c
index 588c2d2b0c69..553cf08b4d76 100644
--- a/net/tipc/group.c
+++ b/net/tipc/group.c
@@ -273,8 +273,8 @@ static struct tipc_member *tipc_group_find_node(struct tipc_group *grp,
return NULL;
}
-static void tipc_group_add_to_tree(struct tipc_group *grp,
- struct tipc_member *m)
+static int tipc_group_add_to_tree(struct tipc_group *grp,
+ struct tipc_member *m)
{
u64 nkey, key = (u64)m->node << 32 | m->port;
struct rb_node **n, *parent = NULL;
@@ -291,10 +291,11 @@ static void tipc_group_add_to_tree(struct tipc_group *grp,
else if (key > nkey)
n = &(*n)->rb_right;
else
- return;
+ return -1;
}
rb_link_node(&m->tree_node, parent, n);
rb_insert_color(&m->tree_node, &grp->members);
+ return 0;
}
static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
@@ -302,6 +303,7 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
u32 instance, int state)
{
struct tipc_member *m;
+ int ret;
m = kzalloc(sizeof(*m), GFP_ATOMIC);
if (!m)
@@ -314,8 +316,12 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
m->port = port;
m->instance = instance;
m->bc_acked = grp->bc_snd_nxt - 1;
+ ret = tipc_group_add_to_tree(grp, m);
+ if (ret < 0) {
+ kfree(m);
+ return NULL;
+ }
grp->member_cnt++;
- tipc_group_add_to_tree(grp, m);
tipc_nlist_add(&grp->dests, m->node);
m->state = state;
return m;
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Linux-kernel-mentees] [PATCH net] tipc: Fix memory leak in tipc_group_create_member()
@ 2020-09-12 10:22 ` Peilin Ye
0 siblings, 0 replies; 12+ messages in thread
From: Peilin Ye @ 2020-09-12 10:22 UTC (permalink / raw)
To: Jon Maloy, Ying Xue
Cc: Hillf Danton, netdev, syzkaller-bugs, linux-kernel,
David S. Miller, tipc-discussion, Jakub Kicinski,
linux-kernel-mentees, Peilin Ye
tipc_group_add_to_tree() returns silently if `key` matches `nkey` of an
existing node, causing tipc_group_create_member() to leak memory. Let
tipc_group_add_to_tree() return an error in such a case, so that
tipc_group_create_member() can handle it properly.
Fixes: 75da2163dbb6 ("tipc: introduce communication groups")
Reported-and-tested-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com
Cc: Hillf Danton <hdanton@sina.com>
Link: https://syzkaller.appspot.com/bug?id=048390604fe1b60df34150265479202f10e13aff
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
Decoded syzbot reproducer in pseudo-C:
fd0 = socket(AF_TIPC, SOCK_DGRAM, 0);
sockaddr_tipc.family = AF_TIPC;
sockaddr_tipc.addrtype = TIPC_ADDR_NAMESEQ;
sockaddr_tipc.scope = 0;
sockaddr_tipc.addr.namesq.type = TIPC_RESERVED_TYPES + 1;
bind(fd0, &sockaddr_tipc, sizeof(sockaddr_tipc));
tipc_group_req0.type = TIPC_RESERVED_TYPES + 1;
setsockopt(fd0, SOL_TIPC, TIPC_GROUP_JOIN, &tipc_group_req0, sizeof(tipc_group_req0));
fd1 = socket(AF_TIPC, SOCK_STREAM, 0);
tipc_group_req1.type = TIPC_RESERVED_TYPES + 1;
tipc_group_req1.scope = TIPC_CLUSTER_SCOPE;
setsockopt(fd1, SOL_TIPC, TIPC_GROUP_JOIN, &tipc_group_req1, sizeof(tipc_group_req1));
net/tipc/group.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/tipc/group.c b/net/tipc/group.c
index 588c2d2b0c69..553cf08b4d76 100644
--- a/net/tipc/group.c
+++ b/net/tipc/group.c
@@ -273,8 +273,8 @@ static struct tipc_member *tipc_group_find_node(struct tipc_group *grp,
return NULL;
}
-static void tipc_group_add_to_tree(struct tipc_group *grp,
- struct tipc_member *m)
+static int tipc_group_add_to_tree(struct tipc_group *grp,
+ struct tipc_member *m)
{
u64 nkey, key = (u64)m->node << 32 | m->port;
struct rb_node **n, *parent = NULL;
@@ -291,10 +291,11 @@ static void tipc_group_add_to_tree(struct tipc_group *grp,
else if (key > nkey)
n = &(*n)->rb_right;
else
- return;
+ return -1;
}
rb_link_node(&m->tree_node, parent, n);
rb_insert_color(&m->tree_node, &grp->members);
+ return 0;
}
static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
@@ -302,6 +303,7 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
u32 instance, int state)
{
struct tipc_member *m;
+ int ret;
m = kzalloc(sizeof(*m), GFP_ATOMIC);
if (!m)
@@ -314,8 +316,12 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
m->port = port;
m->instance = instance;
m->bc_acked = grp->bc_snd_nxt - 1;
+ ret = tipc_group_add_to_tree(grp, m);
+ if (ret < 0) {
+ kfree(m);
+ return NULL;
+ }
grp->member_cnt++;
- tipc_group_add_to_tree(grp, m);
tipc_nlist_add(&grp->dests, m->node);
m->state = state;
return m;
--
2.25.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH net] tipc: Fix memory leak in tipc_group_create_member()
2020-09-12 10:22 ` Peilin Ye
@ 2020-09-13 1:23 ` David Miller
-1 siblings, 0 replies; 12+ messages in thread
From: David Miller @ 2020-09-13 1:23 UTC (permalink / raw)
To: yepeilin.cs
Cc: jmaloy, ying.xue, kuba, hdanton, gregkh, netdev, tipc-discussion,
linux-kernel-mentees, syzkaller-bugs, linux-kernel
From: Peilin Ye <yepeilin.cs@gmail.com>
Date: Sat, 12 Sep 2020 06:22:30 -0400
> @@ -291,10 +291,11 @@ static void tipc_group_add_to_tree(struct tipc_group *grp,
> else if (key > nkey)
> n = &(*n)->rb_right;
> else
> - return;
> + return -1;
Use a real error code like "-EEXIST", thank you.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH net] tipc: Fix memory leak in tipc_group_create_member()
@ 2020-09-13 1:23 ` David Miller
0 siblings, 0 replies; 12+ messages in thread
From: David Miller @ 2020-09-13 1:23 UTC (permalink / raw)
To: yepeilin.cs
Cc: hdanton, netdev, syzkaller-bugs, linux-kernel, jmaloy,
tipc-discussion, ying.xue, kuba, linux-kernel-mentees
From: Peilin Ye <yepeilin.cs@gmail.com>
Date: Sat, 12 Sep 2020 06:22:30 -0400
> @@ -291,10 +291,11 @@ static void tipc_group_add_to_tree(struct tipc_group *grp,
> else if (key > nkey)
> n = &(*n)->rb_right;
> else
> - return;
> + return -1;
Use a real error code like "-EEXIST", thank you.
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH net] tipc: Fix memory leak in tipc_group_create_member()
2020-09-13 1:23 ` David Miller
@ 2020-09-13 7:49 ` Peilin Ye
-1 siblings, 0 replies; 12+ messages in thread
From: Peilin Ye @ 2020-09-13 7:49 UTC (permalink / raw)
To: David Miller
Cc: jmaloy, ying.xue, kuba, hdanton, gregkh, netdev, tipc-discussion,
linux-kernel-mentees, syzkaller-bugs, linux-kernel
On Sat, Sep 12, 2020 at 06:23:36PM -0700, David Miller wrote:
> From: Peilin Ye <yepeilin.cs@gmail.com>
> Date: Sat, 12 Sep 2020 06:22:30 -0400
>
> > @@ -291,10 +291,11 @@ static void tipc_group_add_to_tree(struct tipc_group *grp,
> > else if (key > nkey)
> > n = &(*n)->rb_right;
> > else
> > - return;
> > + return -1;
>
> Use a real error code like "-EEXIST", thank you.
Ah, I'll fix it in v2 soon, sorry about that. I saw another function in
this file returning -1.
Peilin Ye
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH net] tipc: Fix memory leak in tipc_group_create_member()
@ 2020-09-13 7:49 ` Peilin Ye
0 siblings, 0 replies; 12+ messages in thread
From: Peilin Ye @ 2020-09-13 7:49 UTC (permalink / raw)
To: David Miller
Cc: hdanton, netdev, syzkaller-bugs, linux-kernel, jmaloy,
tipc-discussion, ying.xue, kuba, linux-kernel-mentees
On Sat, Sep 12, 2020 at 06:23:36PM -0700, David Miller wrote:
> From: Peilin Ye <yepeilin.cs@gmail.com>
> Date: Sat, 12 Sep 2020 06:22:30 -0400
>
> > @@ -291,10 +291,11 @@ static void tipc_group_add_to_tree(struct tipc_group *grp,
> > else if (key > nkey)
> > n = &(*n)->rb_right;
> > else
> > - return;
> > + return -1;
>
> Use a real error code like "-EEXIST", thank you.
Ah, I'll fix it in v2 soon, sorry about that. I saw another function in
this file returning -1.
Peilin Ye
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Linux-kernel-mentees] [PATCH net v2] tipc: Fix memory leak in tipc_group_create_member()
2020-09-12 10:22 ` Peilin Ye
@ 2020-09-13 8:06 ` Peilin Ye
-1 siblings, 0 replies; 12+ messages in thread
From: Peilin Ye @ 2020-09-13 8:06 UTC (permalink / raw)
To: Jon Maloy, Ying Xue
Cc: Peilin Ye, David S. Miller, Jakub Kicinski, Hillf Danton,
Greg Kroah-Hartman, netdev, tipc-discussion,
linux-kernel-mentees, syzkaller-bugs, linux-kernel
tipc_group_add_to_tree() returns silently if `key` matches `nkey` of an
existing node, causing tipc_group_create_member() to leak memory. Let
tipc_group_add_to_tree() return an error in such a case, so that
tipc_group_create_member() can handle it properly.
Fixes: 75da2163dbb6 ("tipc: introduce communication groups")
Reported-and-tested-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com
Cc: Hillf Danton <hdanton@sina.com>
Link: https://syzkaller.appspot.com/bug?id=048390604fe1b60df34150265479202f10e13aff
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
Change in v2:
- let tipc_group_add_to_tree() return a real error code instead of -1.
(Suggested by David Miller <davem@davemloft.net>)
net/tipc/group.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/tipc/group.c b/net/tipc/group.c
index 588c2d2b0c69..b1fcd2ad5ecf 100644
--- a/net/tipc/group.c
+++ b/net/tipc/group.c
@@ -273,8 +273,8 @@ static struct tipc_member *tipc_group_find_node(struct tipc_group *grp,
return NULL;
}
-static void tipc_group_add_to_tree(struct tipc_group *grp,
- struct tipc_member *m)
+static int tipc_group_add_to_tree(struct tipc_group *grp,
+ struct tipc_member *m)
{
u64 nkey, key = (u64)m->node << 32 | m->port;
struct rb_node **n, *parent = NULL;
@@ -291,10 +291,11 @@ static void tipc_group_add_to_tree(struct tipc_group *grp,
else if (key > nkey)
n = &(*n)->rb_right;
else
- return;
+ return -EEXIST;
}
rb_link_node(&m->tree_node, parent, n);
rb_insert_color(&m->tree_node, &grp->members);
+ return 0;
}
static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
@@ -302,6 +303,7 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
u32 instance, int state)
{
struct tipc_member *m;
+ int ret;
m = kzalloc(sizeof(*m), GFP_ATOMIC);
if (!m)
@@ -314,8 +316,12 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
m->port = port;
m->instance = instance;
m->bc_acked = grp->bc_snd_nxt - 1;
+ ret = tipc_group_add_to_tree(grp, m);
+ if (ret < 0) {
+ kfree(m);
+ return NULL;
+ }
grp->member_cnt++;
- tipc_group_add_to_tree(grp, m);
tipc_nlist_add(&grp->dests, m->node);
m->state = state;
return m;
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Linux-kernel-mentees] [PATCH net v2] tipc: Fix memory leak in tipc_group_create_member()
@ 2020-09-13 8:06 ` Peilin Ye
0 siblings, 0 replies; 12+ messages in thread
From: Peilin Ye @ 2020-09-13 8:06 UTC (permalink / raw)
To: Jon Maloy, Ying Xue
Cc: Hillf Danton, netdev, syzkaller-bugs, linux-kernel,
David S. Miller, tipc-discussion, Jakub Kicinski,
linux-kernel-mentees, Peilin Ye
tipc_group_add_to_tree() returns silently if `key` matches `nkey` of an
existing node, causing tipc_group_create_member() to leak memory. Let
tipc_group_add_to_tree() return an error in such a case, so that
tipc_group_create_member() can handle it properly.
Fixes: 75da2163dbb6 ("tipc: introduce communication groups")
Reported-and-tested-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com
Cc: Hillf Danton <hdanton@sina.com>
Link: https://syzkaller.appspot.com/bug?id=048390604fe1b60df34150265479202f10e13aff
Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
---
Change in v2:
- let tipc_group_add_to_tree() return a real error code instead of -1.
(Suggested by David Miller <davem@davemloft.net>)
net/tipc/group.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/tipc/group.c b/net/tipc/group.c
index 588c2d2b0c69..b1fcd2ad5ecf 100644
--- a/net/tipc/group.c
+++ b/net/tipc/group.c
@@ -273,8 +273,8 @@ static struct tipc_member *tipc_group_find_node(struct tipc_group *grp,
return NULL;
}
-static void tipc_group_add_to_tree(struct tipc_group *grp,
- struct tipc_member *m)
+static int tipc_group_add_to_tree(struct tipc_group *grp,
+ struct tipc_member *m)
{
u64 nkey, key = (u64)m->node << 32 | m->port;
struct rb_node **n, *parent = NULL;
@@ -291,10 +291,11 @@ static void tipc_group_add_to_tree(struct tipc_group *grp,
else if (key > nkey)
n = &(*n)->rb_right;
else
- return;
+ return -EEXIST;
}
rb_link_node(&m->tree_node, parent, n);
rb_insert_color(&m->tree_node, &grp->members);
+ return 0;
}
static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
@@ -302,6 +303,7 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
u32 instance, int state)
{
struct tipc_member *m;
+ int ret;
m = kzalloc(sizeof(*m), GFP_ATOMIC);
if (!m)
@@ -314,8 +316,12 @@ static struct tipc_member *tipc_group_create_member(struct tipc_group *grp,
m->port = port;
m->instance = instance;
m->bc_acked = grp->bc_snd_nxt - 1;
+ ret = tipc_group_add_to_tree(grp, m);
+ if (ret < 0) {
+ kfree(m);
+ return NULL;
+ }
grp->member_cnt++;
- tipc_group_add_to_tree(grp, m);
tipc_nlist_add(&grp->dests, m->node);
m->state = state;
return m;
--
2.25.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH net v2] tipc: Fix memory leak in tipc_group_create_member()
2020-09-13 8:06 ` Peilin Ye
@ 2020-09-14 23:37 ` David Miller
-1 siblings, 0 replies; 12+ messages in thread
From: David Miller @ 2020-09-14 23:37 UTC (permalink / raw)
To: yepeilin.cs
Cc: jmaloy, ying.xue, kuba, hdanton, gregkh, netdev, tipc-discussion,
linux-kernel-mentees, syzkaller-bugs, linux-kernel
From: Peilin Ye <yepeilin.cs@gmail.com>
Date: Sun, 13 Sep 2020 04:06:05 -0400
> tipc_group_add_to_tree() returns silently if `key` matches `nkey` of an
> existing node, causing tipc_group_create_member() to leak memory. Let
> tipc_group_add_to_tree() return an error in such a case, so that
> tipc_group_create_member() can handle it properly.
>
> Fixes: 75da2163dbb6 ("tipc: introduce communication groups")
> Reported-and-tested-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com
> Cc: Hillf Danton <hdanton@sina.com>
> Link: https://syzkaller.appspot.com/bug?id=048390604fe1b60df34150265479202f10e13aff
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> ---
> Change in v2:
> - let tipc_group_add_to_tree() return a real error code instead of -1.
> (Suggested by David Miller <davem@davemloft.net>)
Applied and queued up for -stable, thank you.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH net v2] tipc: Fix memory leak in tipc_group_create_member()
@ 2020-09-14 23:37 ` David Miller
0 siblings, 0 replies; 12+ messages in thread
From: David Miller @ 2020-09-14 23:37 UTC (permalink / raw)
To: yepeilin.cs
Cc: hdanton, netdev, syzkaller-bugs, linux-kernel, jmaloy,
tipc-discussion, ying.xue, kuba, linux-kernel-mentees
From: Peilin Ye <yepeilin.cs@gmail.com>
Date: Sun, 13 Sep 2020 04:06:05 -0400
> tipc_group_add_to_tree() returns silently if `key` matches `nkey` of an
> existing node, causing tipc_group_create_member() to leak memory. Let
> tipc_group_add_to_tree() return an error in such a case, so that
> tipc_group_create_member() can handle it properly.
>
> Fixes: 75da2163dbb6 ("tipc: introduce communication groups")
> Reported-and-tested-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com
> Cc: Hillf Danton <hdanton@sina.com>
> Link: https://syzkaller.appspot.com/bug?id=048390604fe1b60df34150265479202f10e13aff
> Signed-off-by: Peilin Ye <yepeilin.cs@gmail.com>
> ---
> Change in v2:
> - let tipc_group_add_to_tree() return a real error code instead of -1.
> (Suggested by David Miller <davem@davemloft.net>)
Applied and queued up for -stable, thank you.
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2020-09-14 23:37 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-02 2:38 memory leak in tipc_group_create_member syzbot
2019-08-02 12:18 ` Ying Xue
2020-09-12 10:22 ` [Linux-kernel-mentees] [PATCH net] tipc: Fix memory leak in tipc_group_create_member() Peilin Ye
2020-09-12 10:22 ` Peilin Ye
2020-09-13 1:23 ` David Miller
2020-09-13 1:23 ` David Miller
2020-09-13 7:49 ` Peilin Ye
2020-09-13 7:49 ` Peilin Ye
2020-09-13 8:06 ` [Linux-kernel-mentees] [PATCH net v2] " Peilin Ye
2020-09-13 8:06 ` Peilin Ye
2020-09-14 23:37 ` David Miller
2020-09-14 23:37 ` David Miller
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.