[PATCH 4.14 17/41] kcm: Fix use-after-free caused by clonned sockets

From: Greg Kroah-Hartman
Date: Sat Jun 09 2018 - 11:35:44 EST


4.14-stable review patch. If anyone has any objections, please let me know.

------------------

From: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx>

[ Upstream commit eb7f54b90bd8f469834c5e86dcf72ebf9a629811 ]

(resend for properly queueing in patchwork)

kcm_clone() creates kernel socket, which does not take net counter.
Thus, the net may die before the socket is completely destructed,
i.e. kcm_exit_net() is executed before kcm_done().

Reported-by: syzbot+5f1a04e374a635efc426@xxxxxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx>
Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
net/kcm/kcmsock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/kcm/kcmsock.c
+++ b/net/kcm/kcmsock.c
@@ -1672,7 +1672,7 @@ static struct file *kcm_clone(struct soc
__module_get(newsock->ops->owner);

newsk = sk_alloc(sock_net(osock->sk), PF_KCM, GFP_KERNEL,
- &kcm_proto, true);
+ &kcm_proto, false);
if (!newsk) {
sock_release(newsock);
return ERR_PTR(-ENOMEM);