net: rds: fix memory leak in rds_recvmsg
Subsystems (4)
PATCH 1/1 net: rds: fix memory leak in rds_recvmsg
Syzbot reported memory leak in rds. The problem was in unputted refcount in case of error.
int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
int msg_flags)
{
...
if (!rds_next_incoming(rs, &inc)) {
...
}After this "if" inc refcount incremented and
if (rds_cmsg_recv(inc, msg, rs)) {
ret = -EFAULT;
goto out;
}
...
out:
return ret;
}in case of rds_cmsg_recv() fail the refcount won't be decremented. And it's easy to see from ftrace log, that rds_inc_addref() don't have rds_inc_put() pair in rds_recvmsg() after rds_cmsg_recv()
1) | rds_recvmsg() {
1) 3.721 us | rds_inc_addref();
1) 3.853 us | rds_message_inc_copy_to_user();
1) + 10.395 us | rds_cmsg_recv();
1) + 34.260 us | }--- net/rds/recv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/rds/recv.c +2 -1
@@ -714,7 +714,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,if (rds_cmsg_recv (inc, msg, rs)) { ret = -EFAULT ; - goto out; + goto out_put; }rds_recvmsg_zcookie (rs, msg);
@@ -740,6 +740,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,break ; } +out_put:if (inc)rds_inc_put (inc);
Signature · 1 line
2.31.1
Quoted 38 lines · Pavel Skripkin
Syzbot reported memory leak in rds. The problem was in unputted refcount in case of error.
int rds_recvmsg(struct socket *sock, struct msghdr *msg,
size_tsize,
intmsg_flags)
{
...if (!rds_next_incoming(rs, &inc)) { ... }After this "if" inc refcount incremented and
if (rds_cmsg_recv(inc, msg, rs)) { ret = -EFAULT; goto out; } ... out: return ret; }in case of
rds_cmsg_recv()fail the refcount won't be decremented. And it's easy to see from ftrace log, thatrds_inc_addref()don't haverds_inc_put()pair inrds_recvmsg()afterrds_cmsg_recv()1) | rds_recvmsg() { 1) 3.721 us | rds_inc_addref(); 1) 3.853 us | rds_message_inc_copy_to_user(); 1) + 10.395 us | rds_cmsg_recv(); 1) + 34.260 us | }
Quoted 3 lines
Fixes bdbe6fbc6a2f ("RDS: recv.c")Reported-and-tested-by [email protected]Signed-off-by Pavel Skripkin <[email protected]>
Thank for your commit and analyses. One small nit below.
Quoted 9 lines
---
net/rds/recv.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/rds/recv.c +0
-0
net/rds/recv.c int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, · line 717
Quoted 5 lines
net/rds/recv.c +1
-1@@ -714,7 +714,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,if (rds_cmsg_recv (inc, msg, rs)) { ret = -EFAULT ; - goto out; + goto out_put;
Would a simple "break;" do it here and no need for the next hunk?
Thxs, Håkon
Quoted 14 lines
net/rds/recv.c +1
-0}rds_recvmsg_zcookie (rs, msg);@@ -740,6 +740,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,break ; } +out_put:if (inc)rds_inc_put (inc);Signature · 1 line
2.31.1
Quoted 65 lines · On Tue, 8 Jun 2021 07:11:27 +0000 Haakon Bugge <[email protected]> wrote:
Quoted 39 lines
On 7 Jun 2021, at 21:41, Pavel Skripkin <[email protected]> wrote:
Syzbot reported memory leak in rds. The problem was in unputted refcount in case of error.
int
rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, int msg_flags)
{
...if (!rds_next_incoming(rs, &inc)) { ... }After this "if" inc refcount incremented and
if (rds_cmsg_recv(inc, msg, rs)) { ret = -EFAULT; goto out; } ... out: return ret; }in case of
rds_cmsg_recv()fail the refcount won't be decremented. And it's easy to see from ftrace log, thatrds_inc_addref()don't haverds_inc_put()pair inrds_recvmsg()afterrds_cmsg_recv()1) | rds_recvmsg() { 1) 3.721 us | rds_inc_addref(); 1) 3.853 us | rds_message_inc_copy_to_user(); 1) + 10.395 us | rds_cmsg_recv(); 1) + 34.260 us | }Quoted 4 lines
Fixes bdbe6fbc6a2f ("RDS: recv.c")Reported-and-tested-by:
[email protected]Signed-off-by Pavel Skripkin <[email protected]>Thank for your commit and analyses. One small nit below.
Quoted 9 lines
---
net/rds/recv.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)net/rds/recv.c +0
-0net/rds/recv.c int rds_recvmsg(struct socket *sock, struct · line 718
Quoted 6 lines
net/rds/recv.c +1
-1@@ -714,7 +714,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, if (rds_cmsg_recv(inc, msg, rs)) { ret = -EFAULT ; - goto out; + goto out_put;Would a simple "break;" do it here and no need for the next hunk?
Quoted 2 lines
Thxs, Håkon
Sure! I'll send v2 soon. Thank you for feedback :)
With regards,
Pavel Skripkin
PATCH v2 1/1 net: rds: fix memory leak in rds_recvmsg
In reply to Haakon BuggeSyzbot reported memory leak in rds. The problem was in unputted refcount in case of error.
int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
int msg_flags)
{
...
if (!rds_next_incoming(rs, &inc)) {
...
}After this "if" inc refcount incremented and
if (rds_cmsg_recv(inc, msg, rs)) {
ret = -EFAULT;
goto out;
}
...
out:
return ret;
}in case of rds_cmsg_recv() fail the refcount won't be decremented. And it's easy to see from ftrace log, that rds_inc_addref() don't have rds_inc_put() pair in rds_recvmsg() after rds_cmsg_recv()
1) | rds_recvmsg() {
1) 3.721 us | rds_inc_addref();
1) 3.853 us | rds_message_inc_copy_to_user();
1) + 10.395 us | rds_cmsg_recv();
1) + 34.260 us | }---
Changes in v2:
Changed goto to break.
--- net/rds/recv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/rds/recv.c +1 -1
@@ -714,7 +714,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,if (rds_cmsg_recv (inc, msg, rs)) { ret = -EFAULT ; - goto out; +break ; }rds_recvmsg_zcookie (rs, msg);
Signature · 1 line
2.31.1
Quoted 38 lines · Pavel Skripkin
Syzbot reported memory leak in rds. The problem was in unputted refcount in case of error.
int rds_recvmsg(struct socket *sock, struct msghdr *msg,
size_tsize,
intmsg_flags)
{
...if (!rds_next_incoming(rs, &inc)) { ... }After this "if" inc refcount incremented and
if (rds_cmsg_recv(inc, msg, rs)) { ret = -EFAULT; goto out; } ... out: return ret; }in case of
rds_cmsg_recv()fail the refcount won't be decremented. And it's easy to see from ftrace log, thatrds_inc_addref()don't haverds_inc_put()pair inrds_recvmsg()afterrds_cmsg_recv()1) | rds_recvmsg() { 1) 3.721 us | rds_inc_addref(); 1) 3.853 us | rds_message_inc_copy_to_user(); 1) + 10.395 us | rds_cmsg_recv(); 1) + 34.260 us | }
Quoted 3 lines
Fixes bdbe6fbc6a2f ("RDS: recv.c")Reported-and-tested-by [email protected]Signed-off-by Pavel Skripkin <[email protected]>
Thanks for fixing this, Håkon
Quoted 25 lines
---
Changes in v2:
Changed goto to break.---
net/rds/recv.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)net/rds/recv.c +1
-1@@ -714,7 +714,7 @@ int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,if (rds_cmsg_recv (inc, msg, rs)) { ret = -EFAULT ; - goto out; +break ; }rds_recvmsg_zcookie (rs, msg);Signature · 1 line
2.31.1
Quoted 35 lines · Pavel Skripkin
Syzbot reported memory leak in rds. The problem was in unputted refcount in case of error.
int rds_recvmsg(struct socket *sock, struct msghdr *msg,
size_tsize,
intmsg_flags)
{
...if (!rds_next_incoming(rs, &inc)) { ... }After this "if" inc refcount incremented and
if (rds_cmsg_recv(inc, msg, rs)) { ret = -EFAULT; goto out; } ... out: return ret; }in case of
rds_cmsg_recv()fail the refcount won't be decremented. And it's easy to see from ftrace log, thatrds_inc_addref()don't haverds_inc_put()pair inrds_recvmsg()afterrds_cmsg_recv()1) | rds_recvmsg() { 1) 3.721 us | rds_inc_addref(); 1) 3.853 us | rds_message_inc_copy_to_user(); 1) + 10.395 us | rds_cmsg_recv(); 1) + 34.260 us | }
Quoted 8 lines
Fixes bdbe6fbc6a2f ("RDS: recv.c")Reported-and-tested-by [email protected]Signed-off-by Pavel Skripkin <[email protected]>---
Changes in v2:
Changed goto to break.
Looks fine by me. Thanks for the fix.
This patch was applied to netdev/net.git (refs/heads/master):
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
Quoted 9 lines · On Tue, 8 Jun 2021 11:06:41 +0300 you wrote:
Syzbot reported memory leak in rds. The problem
was in unputted refcount in case of error.int rds_recvmsg(struct socket *sock, struct msghdr *msg,
size_tsize,
intmsg_flags)
{
...[...]
Here is the summary with links:
- [v2] net: rds: fix memory leak in rds_recvmsg
https://git.kernel.org/netdev/net/c/49bfcbfd989a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html