From: Quentin Casasnovas Date: Tue, 24 Nov 2015 22:13:21 +0000 (-0500) Subject: RDS: fix race condition when sending a message on unbound socket X-Git-Tag: submit/tizen/20170309.044430~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a1cac907a92216089dbe9d51a4d7f2651534ce66;p=profile%2Fwearable%2Fplatform%2Fkernel%2Flinux-3.18-exynos7270.git RDS: fix race condition when sending a message on unbound socket [ Upstream commit 8c7188b23474cca017b3ef354c4a58456f68303a ] Sasha's found a NULL pointer dereference in the RDS connection code when sending a message to an apparently unbound socket. The problem is caused by the code checking if the socket is bound in rds_sendmsg(), which checks the rs_bound_addr field without taking a lock on the socket. This opens a race where rs_bound_addr is temporarily set but where the transport is not in rds_bind(), leading to a NULL pointer dereference when trying to dereference 'trans' in __rds_conn_create(). Vegard wrote a reproducer for this issue, so kindly ask him to share if you're interested. I cannot reproduce the NULL pointer dereference using Vegard's reproducer with this patch, whereas I could without. Complete earlier incomplete fix to CVE-2015-6937: 74e98eb08588 ("RDS: verify the underlying transport exists before creating a connection") Cc: David S. Miller Cc: stable@vger.kernel.org Change-Id: I7b41743a51bd3213de624d6165c6366c9f808067 Reviewed-by: Vegard Nossum Reviewed-by: Sasha Levin Acked-by: Santosh Shilimkar Signed-off-by: Quentin Casasnovas Signed-off-by: David S. Miller Signed-off-by: Sasha Levin [mainline backport of commit 96c7b10cd8000973035b667adf62ea1164f4b9b4] Change-Id: I7b41743a51bd3213de624d6165c6366c9f808067 Signed-off-by: Jaechul Lee --- diff --git a/net/rds/send.c b/net/rds/send.c index 0a64541020b..0bae8d43b01 100644 --- a/net/rds/send.c +++ b/net/rds/send.c @@ -958,11 +958,13 @@ int rds_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, release_sock(sk); } - /* racing with another thread binding seems ok here */ + lock_sock(sk); if (daddr == 0 || rs->rs_bound_addr == 0) { + release_sock(sk); ret = -ENOTCONN; /* XXX not a great errno */ goto out; } + release_sock(sk); /* size of rm including all sgs */ ret = rds_rm_size(msg, payload_len);