linux_dsm_epyc7002/net/rds
Pavel Skripkin 5946fbf483 net: rds: fix memory leak in rds_recvmsg
[ Upstream commit 49bfcbfd989a8f1f23e705759a6bb099de2cff9f ]

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   |  }

Fixes: bdbe6fbc6a ("RDS: recv.c")
Reported-and-tested-by: syzbot+5134cdf021c4ed5aaa5f@syzkaller.appspotmail.com
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Reviewed-by: Håkon Bugge <haakon.bugge@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-06-23 14:42:42 +02:00
..
af_rds.c
bind.c
cong.c
connection.c RDS tcp loopback connection can hang 2021-06-16 12:01:36 +02:00
ib_cm.c
ib_frmr.c
ib_mr.h
ib_rdma.c
ib_recv.c
ib_ring.c
ib_send.c
ib_stats.c
ib_sysctl.c
ib.c
ib.h
info.c
info.h
Kconfig
loop.c
loop.h
Makefile
message.c net/rds: Fix a use after free in rds_message_map_pages 2021-04-14 08:42:09 +02:00
page.c
rdma_transport.c
rdma_transport.h
rdma.c
rds_single_path.h
rds.h
recv.c net: rds: fix memory leak in rds_recvmsg 2021-06-23 14:42:42 +02:00
send.c
stats.c
sysctl.c
tcp_connect.c
tcp_listen.c RDS tcp loopback connection can hang 2021-06-16 12:01:36 +02:00
tcp_recv.c
tcp_send.c
tcp_stats.c
tcp.c RDS tcp loopback connection can hang 2021-06-16 12:01:36 +02:00
tcp.h RDS tcp loopback connection can hang 2021-06-16 12:01:36 +02:00
threads.c
transport.c