Blame macsec-0039-macsec_linux-Fix-NULL-pointer-dereference-on-error-c.patch

e688ea7
From 5db86df6a849684fda6a7ee53978a1ba931848cb Mon Sep 17 00:00:00 2001
e688ea7
Message-Id: <5db86df6a849684fda6a7ee53978a1ba931848cb.1491601565.git.davide.caratti@gmail.com>
e688ea7
From: Davide Caratti <davide.caratti@gmail.com>
e688ea7
Date: Fri, 24 Mar 2017 10:25:24 +0100
e688ea7
Subject: [PATCH] macsec_linux: Fix NULL pointer dereference on error cases
e688ea7
e688ea7
In case wpa_supplicant is using driver_macsec_linux, but macsec module
e688ea7
is not (yet) loaded in the kernel, nl_socket_alloc() fails and drv->sk
e688ea7
is NULL. In this case, don't call libnl functions rntl_link_add() or
e688ea7
rtnl_link_change() using such NULL pointer, to prevent program from
e688ea7
getting segmentation faults like:
e688ea7
e688ea7
 Program received signal SIGSEGV, Segmentation fault.
e688ea7
 nl_socket_get_local_port (sk=sk@entry=0x0) at socket.c:365
e688ea7
 365             if (sk->s_local.nl_pid == 0) {
e688ea7
 (gdb) p sk
e688ea7
 $1 = (const struct nl_sock *) 0x0
e688ea7
 (gdb) bt
e688ea7
 #0  nl_socket_get_local_port (sk=sk@entry=0x0) at socket.c:365
e688ea7
 #1  0x00007ffff79c56a0 in nl_complete_msg (sk=sk@entry=0x0,
e688ea7
  msg=msg@entry=0x55555595a1f0) at nl.c:491
e688ea7
 #2  0x00007ffff79c56d1 in nl_send_auto (sk=sk@entry=0x0,
e688ea7
  msg=msg@entry=0x55555595a1f0) at nl.c:522
e688ea7
 #3  0x00007ffff79c652f in nl_send_sync (sk=sk@entry=0x0,
e688ea7
  msg=0x55555595a1f0) at nl.c:556
e688ea7
 #4  0x00007ffff755faf5 in rtnl_link_add (sk=0x0,
e688ea7
  link=link@entry=0x55555595b0f0, flags=flags@entry=1024) at route/link.c:1548
e688ea7
 #5  0x000055555567a298 in macsec_drv_create_transmit_sc (priv=0x55555593b130,
e688ea7
  sc=0x55555593b320, conf_offset=<optimized out>) at ../src/drivers/driver_macsec_linux.c:998
e688ea7
e688ea7
Signed-off-by: Davide Caratti <davide.caratti@gmail.com>
e688ea7
---
e688ea7
 src/drivers/driver_macsec_linux.c | 11 +++++++++++
e688ea7
 1 file changed, 11 insertions(+)
e688ea7
e688ea7
diff --git a/src/drivers/driver_macsec_linux.c b/src/drivers/driver_macsec_linux.c
e688ea7
index 5dab77a..0694e60 100644
e688ea7
--- a/src/drivers/driver_macsec_linux.c
e688ea7
+++ b/src/drivers/driver_macsec_linux.c
e688ea7
@@ -168,6 +168,9 @@ static int try_commit(struct macsec_drv_data *drv)
e688ea7
 {
e688ea7
 	int err;
e688ea7
 
e688ea7
+	if (!drv->sk)
e688ea7
+		return 0;
e688ea7
+
e688ea7
 	if (!drv->link)
e688ea7
 		return 0;
e688ea7
 
e688ea7
@@ -982,6 +985,11 @@ static int macsec_drv_create_transmit_sc(
e688ea7
 
e688ea7
 	wpa_printf(MSG_DEBUG, "%s", __func__);
e688ea7
 
e688ea7
+	if (!drv->sk) {
e688ea7
+		wpa_printf(MSG_ERROR, DRV_PREFIX "NULL rtnl socket");
e688ea7
+		return -1;
e688ea7
+	}
e688ea7
+
e688ea7
 	link = rtnl_link_macsec_alloc();
e688ea7
 	if (!link) {
e688ea7
 		wpa_printf(MSG_ERROR, DRV_PREFIX "couldn't allocate link");
e688ea7
@@ -1048,6 +1056,9 @@ static int macsec_drv_delete_transmit_sc(void *priv, struct transmit_sc *sc)
e688ea7
 
e688ea7
 	wpa_printf(MSG_DEBUG, "%s", __func__);
e688ea7
 
e688ea7
+	if (!drv->sk)
e688ea7
+		return 0;
e688ea7
+
e688ea7
 	if (!drv->created_link) {
e688ea7
 		rtnl_link_put(drv->link);
e688ea7
 		drv->link = NULL;
e688ea7
-- 
e688ea7
2.7.4
e688ea7