netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/16] info leak fixes in recvmsg
@ 2013-04-07 11:51 Mathias Krause
  2013-04-07 11:51 ` [PATCH 01/16] atm: update msg_namelen in vcc_recvmsg() Mathias Krause
                   ` (16 more replies)
  0 siblings, 17 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

Hi Dave,

a few more info leak fixes in the recvmsg path. The error pattern here
is the protocol specific recvmsg function is missing the msg_namelen
assignment -- either completely or in early exit paths that do not
result in errors in __sys_recvmsg()/sys_recvfrom() and, in turn, make
them call move_addr_to_user(), leaking the then still uninitialized
sockaddr_storage stack variable to userland.

My audit was initiated by a rather coarse fix of the leak that can be
found in the grsecurity patch, putting a penalty on protocols complying
to the rules of recvmsg. So credits for finding the leak in the recvmsg
path in __sys_recvmsg() should go to Brad!

The buggy protocols/subsystems are rather obscure anyway. As a missing
assignment of msg_namelen coupled with a missing filling of msg_name
would only result in garbage -- the leak -- in case userland would care
about that information, i.e. would provide a msg_name pointer. But
obviously current userland does not.

While auditing the code for the above pattern I found a few more
'uninitialized members' kind of leaks related to the msg_name filling.
Those are fixed in this series, too.

I have to admit, I failed to test all of the patches due to missing
hardware, e.g. iucv depends on S390 -- hardware I've no access to :/


Please apply!


Mathias Krause (16):
  atm: update msg_namelen in vcc_recvmsg()
  ax25: fix info leak via msg_name in ax25_recvmsg()
  Bluetooth: fix possible info leak in bt_sock_recvmsg()
  Bluetooth: RFCOMM - Fix missing msg_namelen update in
    rfcomm_sock_recvmsg()
  Bluetooth: SCO - Fix missing msg_namelen update in sco_sock_recvmsg()
  caif: Fix missing msg_namelen update in caif_seqpkt_recvmsg()
  irda: Fix missing msg_namelen update in irda_recvmsg_dgram()
  iucv: Fix missing msg_namelen update in iucv_sock_recvmsg()
  l2tp: fix info leak in l2tp_ip6_recvmsg()
  llc: Fix missing msg_namelen update in llc_ui_recvmsg()
  netrom: fix info leak via msg_name in nr_recvmsg()
  NFC: llcp: fix info leaks via msg_name in llcp_sock_recvmsg()
  rose: fix info leak via msg_name in rose_recvmsg()
  tipc: fix info leaks via msg_name in recv_msg/recv_stream
  VSOCK: vmci - fix possible info leak in
    vmci_transport_dgram_dequeue()
  VSOCK: Fix missing msg_namelen update in vsock_stream_recvmsg()

 net/atm/common.c               |    2 ++
 net/ax25/af_ax25.c             |    1 +
 net/bluetooth/af_bluetooth.c   |    4 ++--
 net/bluetooth/rfcomm/sock.c    |    1 +
 net/bluetooth/sco.c            |    1 +
 net/caif/caif_socket.c         |    2 ++
 net/irda/af_irda.c             |    2 ++
 net/iucv/af_iucv.c             |    2 ++
 net/l2tp/l2tp_ip6.c            |    1 +
 net/llc/af_llc.c               |    2 ++
 net/netrom/af_netrom.c         |    1 +
 net/nfc/llcp/sock.c            |    3 +++
 net/rose/af_rose.c             |    1 +
 net/tipc/socket.c              |    7 +++++++
 net/vmw_vsock/af_vsock.c       |    2 ++
 net/vmw_vsock/vmci_transport.c |    3 ++-
 16 files changed, 32 insertions(+), 3 deletions(-)

-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 01/16] atm: update msg_namelen in vcc_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 02/16] ax25: fix info leak via msg_name in ax25_recvmsg() Mathias Krause
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

The current code does not fill the msg_name member in case it is set.
It also does not set the msg_namelen member to 0 and therefore makes
net/socket.c leak the local, uninitialized sockaddr_storage variable
to userland -- 128 bytes of kernel stack memory.

Fix that by simply setting msg_namelen to 0 as obviously nobody cared
about vcc_recvmsg() not filling the msg_name in case it was set.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/atm/common.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/atm/common.c b/net/atm/common.c
index 7b49100..737bef5 100644
--- a/net/atm/common.c
+++ b/net/atm/common.c
@@ -531,6 +531,8 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
 	struct sk_buff *skb;
 	int copied, error = -EINVAL;
 
+	msg->msg_namelen = 0;
+
 	if (sock->state != SS_CONNECTED)
 		return -ENOTCONN;
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 02/16] ax25: fix info leak via msg_name in ax25_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
  2013-04-07 11:51 ` [PATCH 01/16] atm: update msg_namelen in vcc_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 03/16] Bluetooth: fix possible info leak in bt_sock_recvmsg() Mathias Krause
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

When msg_namelen is non-zero the sockaddr info gets filled out, as
requested, but the code fails to initialize the padding bytes of struct
sockaddr_ax25 inserted by the compiler for alignment. Additionally the
msg_namelen value is updated to sizeof(struct full_sockaddr_ax25) but is
not always filled up to this size.

Both issues lead to the fact that the code will leak uninitialized
kernel stack bytes in net/socket.c.

Fix both issues by initializing the memory with memset(0).

Cc: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/ax25/af_ax25.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index 7b11f8b..e277e38 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -1642,6 +1642,7 @@ static int ax25_recvmsg(struct kiocb *iocb, struct socket *sock,
 		ax25_address src;
 		const unsigned char *mac = skb_mac_header(skb);
 
+		memset(sax, 0, sizeof(struct full_sockaddr_ax25));
 		ax25_addr_parse(mac + 1, skb->data - mac - 1, &src, NULL,
 				&digi, NULL, NULL);
 		sax->sax25_family = AF_AX25;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 03/16] Bluetooth: fix possible info leak in bt_sock_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
  2013-04-07 11:51 ` [PATCH 01/16] atm: update msg_namelen in vcc_recvmsg() Mathias Krause
  2013-04-07 11:51 ` [PATCH 02/16] ax25: fix info leak via msg_name in ax25_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 04/16] Bluetooth: RFCOMM - Fix missing msg_namelen update in rfcomm_sock_recvmsg() Mathias Krause
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

In case the socket is already shutting down, bt_sock_recvmsg() returns
with 0 without updating msg_namelen leading to net/socket.c leaking the
local, uninitialized sockaddr_storage variable to userland -- 128 bytes
of kernel stack memory.

Fix this by moving the msg_namelen assignment in front of the shutdown
test.

Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Gustavo Padovan <gustavo@padovan.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/bluetooth/af_bluetooth.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index d3ee69b..0d1b08c 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -230,6 +230,8 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 	if (flags & (MSG_OOB))
 		return -EOPNOTSUPP;
 
+	msg->msg_namelen = 0;
+
 	skb = skb_recv_datagram(sk, flags, noblock, &err);
 	if (!skb) {
 		if (sk->sk_shutdown & RCV_SHUTDOWN)
@@ -237,8 +239,6 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 		return err;
 	}
 
-	msg->msg_namelen = 0;
-
 	copied = skb->len;
 	if (len < copied) {
 		msg->msg_flags |= MSG_TRUNC;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 04/16] Bluetooth: RFCOMM - Fix missing msg_namelen update in rfcomm_sock_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (2 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 03/16] Bluetooth: fix possible info leak in bt_sock_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 05/16] Bluetooth: SCO - Fix missing msg_namelen update in sco_sock_recvmsg() Mathias Krause
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

If RFCOMM_DEFER_SETUP is set in the flags, rfcomm_sock_recvmsg() returns
early with 0 without updating the possibly set msg_namelen member. This,
in turn, leads to a 128 byte kernel stack leak in net/socket.c.

Fix this by updating msg_namelen in this case. For all other cases it
will be handled in bt_sock_stream_recvmsg().

Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Gustavo Padovan <gustavo@padovan.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/bluetooth/rfcomm/sock.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index c23bae8..7c9224b 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -608,6 +608,7 @@ static int rfcomm_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 
 	if (test_and_clear_bit(RFCOMM_DEFER_SETUP, &d->flags)) {
 		rfcomm_dlc_accept(d);
+		msg->msg_namelen = 0;
 		return 0;
 	}
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 05/16] Bluetooth: SCO - Fix missing msg_namelen update in sco_sock_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (3 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 04/16] Bluetooth: RFCOMM - Fix missing msg_namelen update in rfcomm_sock_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 06/16] caif: Fix missing msg_namelen update in caif_seqpkt_recvmsg() Mathias Krause
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

If the socket is in state BT_CONNECT2 and BT_SK_DEFER_SETUP is set in
the flags, sco_sock_recvmsg() returns early with 0 without updating the
possibly set msg_namelen member. This, in turn, leads to a 128 byte
kernel stack leak in net/socket.c.

Fix this by updating msg_namelen in this case. For all other cases it
will be handled in bt_sock_recvmsg().

Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Gustavo Padovan <gustavo@padovan.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/bluetooth/sco.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index fad0302..fb6192c 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -665,6 +665,7 @@ static int sco_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 	    test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
 		hci_conn_accept(pi->conn->hcon, 0);
 		sk->sk_state = BT_CONFIG;
+		msg->msg_namelen = 0;
 
 		release_sock(sk);
 		return 0;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 06/16] caif: Fix missing msg_namelen update in caif_seqpkt_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (4 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 05/16] Bluetooth: SCO - Fix missing msg_namelen update in sco_sock_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 07/16] irda: Fix missing msg_namelen update in irda_recvmsg_dgram() Mathias Krause
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

The current code does not fill the msg_name member in case it is set.
It also does not set the msg_namelen member to 0 and therefore makes
net/socket.c leak the local, uninitialized sockaddr_storage variable
to userland -- 128 bytes of kernel stack memory.

Fix that by simply setting msg_namelen to 0 as obviously nobody cared
about caif_seqpkt_recvmsg() not filling the msg_name in case it was
set.

Cc: Sjur Braendeland <sjur.brandeland@stericsson.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/caif/caif_socket.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
index 095259f..ff2ff3c 100644
--- a/net/caif/caif_socket.c
+++ b/net/caif/caif_socket.c
@@ -286,6 +286,8 @@ static int caif_seqpkt_recvmsg(struct kiocb *iocb, struct socket *sock,
 	if (m->msg_flags&MSG_OOB)
 		goto read_error;
 
+	m->msg_namelen = 0;
+
 	skb = skb_recv_datagram(sk, flags, 0 , &ret);
 	if (!skb)
 		goto read_error;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 07/16] irda: Fix missing msg_namelen update in irda_recvmsg_dgram()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (5 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 06/16] caif: Fix missing msg_namelen update in caif_seqpkt_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 08/16] iucv: Fix missing msg_namelen update in iucv_sock_recvmsg() Mathias Krause
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

The current code does not fill the msg_name member in case it is set.
It also does not set the msg_namelen member to 0 and therefore makes
net/socket.c leak the local, uninitialized sockaddr_storage variable
to userland -- 128 bytes of kernel stack memory.

Fix that by simply setting msg_namelen to 0 as obviously nobody cared
about irda_recvmsg_dgram() not filling the msg_name in case it was
set.

Cc: Samuel Ortiz <samuel@sortiz.org>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/irda/af_irda.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/irda/af_irda.c b/net/irda/af_irda.c
index d28e7f0..e493b33 100644
--- a/net/irda/af_irda.c
+++ b/net/irda/af_irda.c
@@ -1386,6 +1386,8 @@ static int irda_recvmsg_dgram(struct kiocb *iocb, struct socket *sock,
 
 	IRDA_DEBUG(4, "%s()\n", __func__);
 
+	msg->msg_namelen = 0;
+
 	skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
 				flags & MSG_DONTWAIT, &err);
 	if (!skb)
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 08/16] iucv: Fix missing msg_namelen update in iucv_sock_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (6 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 07/16] irda: Fix missing msg_namelen update in irda_recvmsg_dgram() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-08 11:14   ` Ursula Braun
  2013-04-07 11:51 ` [PATCH 09/16] l2tp: fix info leak in l2tp_ip6_recvmsg() Mathias Krause
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

The current code does not fill the msg_name member in case it is set.
It also does not set the msg_namelen member to 0 and therefore makes
net/socket.c leak the local, uninitialized sockaddr_storage variable
to userland -- 128 bytes of kernel stack memory.

Fix that by simply setting msg_namelen to 0 as obviously nobody cared
about iucv_sock_recvmsg() not filling the msg_name in case it was set.

Cc: Ursula Braun <ursula.braun@de.ibm.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
Remark: I failed to test that one as I've no access to a S390 system.

 net/iucv/af_iucv.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
index a7d11ffe..bf69358 100644
--- a/net/iucv/af_iucv.c
+++ b/net/iucv/af_iucv.c
@@ -1328,6 +1328,8 @@ static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 	struct sk_buff *skb, *rskb, *cskb;
 	int err = 0;
 
+	msg->msg_namelen = 0;
+
 	if ((sk->sk_state == IUCV_DISCONN) &&
 	    skb_queue_empty(&iucv->backlog_skb_q) &&
 	    skb_queue_empty(&sk->sk_receive_queue) &&
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 09/16] l2tp: fix info leak in l2tp_ip6_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (7 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 08/16] iucv: Fix missing msg_namelen update in iucv_sock_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 10/16] llc: Fix missing msg_namelen update in llc_ui_recvmsg() Mathias Krause
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

The L2TP code for IPv6 fails to initialize the l2tp_conn_id member of
struct sockaddr_l2tpip6 and therefore leaks four bytes kernel stack
in l2tp_ip6_recvmsg() in case msg_name is set.

Initialize l2tp_conn_id with 0 to avoid the info leak.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/l2tp/l2tp_ip6.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index c74f5a9..b8a6039 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -690,6 +690,7 @@ static int l2tp_ip6_recvmsg(struct kiocb *iocb, struct sock *sk,
 		lsa->l2tp_addr = ipv6_hdr(skb)->saddr;
 		lsa->l2tp_flowinfo = 0;
 		lsa->l2tp_scope_id = 0;
+		lsa->l2tp_conn_id = 0;
 		if (ipv6_addr_type(&lsa->l2tp_addr) & IPV6_ADDR_LINKLOCAL)
 			lsa->l2tp_scope_id = IP6CB(skb)->iif;
 	}
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 10/16] llc: Fix missing msg_namelen update in llc_ui_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (8 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 09/16] l2tp: fix info leak in l2tp_ip6_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 11/16] netrom: fix info leak via msg_name in nr_recvmsg() Mathias Krause
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

For stream sockets the code misses to update the msg_namelen member
to 0 and therefore makes net/socket.c leak the local, uninitialized
sockaddr_storage variable to userland -- 128 bytes of kernel stack
memory. The msg_namelen update is also missing for datagram sockets
in case the socket is shutting down during receive.

Fix both issues by setting msg_namelen to 0 early. It will be
updated later if we're going to fill the msg_name member.

Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/llc/af_llc.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 8870988..48aaa89 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -720,6 +720,8 @@ static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
 	int target;	/* Read at least this many bytes */
 	long timeo;
 
+	msg->msg_namelen = 0;
+
 	lock_sock(sk);
 	copied = -ENOTCONN;
 	if (unlikely(sk->sk_type == SOCK_STREAM && sk->sk_state == TCP_LISTEN))
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 11/16] netrom: fix info leak via msg_name in nr_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (9 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 10/16] llc: Fix missing msg_namelen update in llc_ui_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 12/16] NFC: llcp: fix info leaks via msg_name in llcp_sock_recvmsg() Mathias Krause
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

In case msg_name is set the sockaddr info gets filled out, as
requested, but the code fails to initialize the padding bytes of
struct sockaddr_ax25 inserted by the compiler for alignment. Also
the sax25_ndigis member does not get assigned, leaking four more
bytes.

Both issues lead to the fact that the code will leak uninitialized
kernel stack bytes in net/socket.c.

Fix both issues by initializing the memory with memset(0).

Cc: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/netrom/af_netrom.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
index d1fa1d9..7fcb307 100644
--- a/net/netrom/af_netrom.c
+++ b/net/netrom/af_netrom.c
@@ -1173,6 +1173,7 @@ static int nr_recvmsg(struct kiocb *iocb, struct socket *sock,
 	}
 
 	if (sax != NULL) {
+		memset(sax, 0, sizeof(sax));
 		sax->sax25_family = AF_NETROM;
 		skb_copy_from_linear_data_offset(skb, 7, sax->sax25_call.ax25_call,
 			      AX25_ADDR_LEN);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 12/16] NFC: llcp: fix info leaks via msg_name in llcp_sock_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (10 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 11/16] netrom: fix info leak via msg_name in nr_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:51 ` [PATCH 13/16] rose: fix info leak via msg_name in rose_recvmsg() Mathias Krause
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

The code in llcp_sock_recvmsg() does not initialize all the members of
struct sockaddr_nfc_llcp when filling the sockaddr info. Nor does it
initialize the padding bytes of the structure inserted by the compiler
for alignment.

Also, if the socket is in state LLCP_CLOSED or is shutting down during
receive the msg_namelen member is not updated to 0 while otherwise
returning with 0, i.e. "success". The msg_namelen update is also
missing for stream and seqpacket sockets which don't fill the sockaddr
info.

Both issues lead to the fact that the code will leak uninitialized
kernel stack bytes in net/socket.c.

Fix the first issue by initializing the memory used for sockaddr info
with memset(0). Fix the second one by setting msg_namelen to 0 early.
It will be updated later if we're going to fill the msg_name member.

Cc: Lauro Ramos Venancio <lauro.venancio@openbossa.org>
Cc: Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/nfc/llcp/sock.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
index 5c7cdf3..4741adc 100644
--- a/net/nfc/llcp/sock.c
+++ b/net/nfc/llcp/sock.c
@@ -646,6 +646,8 @@ static int llcp_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 
 	pr_debug("%p %zu\n", sk, len);
 
+	msg->msg_namelen = 0;
+
 	lock_sock(sk);
 
 	if (sk->sk_state == LLCP_CLOSED &&
@@ -691,6 +693,7 @@ static int llcp_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 
 		pr_debug("Datagram socket %d %d\n", ui_cb->dsap, ui_cb->ssap);
 
+		memset(sockaddr, 0, sizeof(*sockaddr));
 		sockaddr->sa_family = AF_NFC;
 		sockaddr->nfc_protocol = NFC_PROTO_NFC_DEP;
 		sockaddr->dsap = ui_cb->dsap;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 13/16] rose: fix info leak via msg_name in rose_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (11 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 12/16] NFC: llcp: fix info leaks via msg_name in llcp_sock_recvmsg() Mathias Krause
@ 2013-04-07 11:51 ` Mathias Krause
  2013-04-07 11:52 ` [PATCH 14/16] tipc: fix info leaks via msg_name in recv_msg/recv_stream Mathias Krause
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:51 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

The code in rose_recvmsg() does not initialize all of the members of
struct sockaddr_rose/full_sockaddr_rose when filling the sockaddr info.
Nor does it initialize the padding bytes of the structure inserted by
the compiler for alignment. This will lead to leaking uninitialized
kernel stack bytes in net/socket.c.

Fix the issue by initializing the memory used for sockaddr info with
memset(0).

Cc: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/rose/af_rose.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c
index cf68e6e..9c83474 100644
--- a/net/rose/af_rose.c
+++ b/net/rose/af_rose.c
@@ -1253,6 +1253,7 @@ static int rose_recvmsg(struct kiocb *iocb, struct socket *sock,
 	skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
 
 	if (srose != NULL) {
+		memset(srose, 0, msg->msg_namelen);
 		srose->srose_family = AF_ROSE;
 		srose->srose_addr   = rose->dest_addr;
 		srose->srose_call   = rose->dest_call;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 14/16] tipc: fix info leaks via msg_name in recv_msg/recv_stream
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (12 preceding siblings ...)
  2013-04-07 11:51 ` [PATCH 13/16] rose: fix info leak via msg_name in rose_recvmsg() Mathias Krause
@ 2013-04-07 11:52 ` Mathias Krause
  2013-04-07 11:52 ` [PATCH 15/16] VSOCK: vmci - fix possible info leak in vmci_transport_dgram_dequeue() Mathias Krause
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:52 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

The code in set_orig_addr() does not initialize all of the members of
struct sockaddr_tipc when filling the sockaddr info -- namely the union
is only partly filled. This will make recv_msg() and recv_stream() --
the only users of this function -- leak kernel stack memory as the
msg_name member is a local variable in net/socket.c.

Additionally to that both recv_msg() and recv_stream() fail to update
the msg_namelen member to 0 while otherwise returning with 0, i.e.
"success". This is the case for, e.g., non-blocking sockets. This will
lead to a 128 byte kernel stack leak in net/socket.c.

Fix the first issue by initializing the memory of the union with
memset(0). Fix the second one by setting msg_namelen to 0 early as it
will be updated later if we're going to fill the msg_name member.

Cc: Jon Maloy <jon.maloy@ericsson.com>
Cc: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/tipc/socket.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index a9622b6..515ce38 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -790,6 +790,7 @@ static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg)
 	if (addr) {
 		addr->family = AF_TIPC;
 		addr->addrtype = TIPC_ADDR_ID;
+		memset(&addr->addr, 0, sizeof(addr->addr));
 		addr->addr.id.ref = msg_origport(msg);
 		addr->addr.id.node = msg_orignode(msg);
 		addr->addr.name.domain = 0;	/* could leave uninitialized */
@@ -904,6 +905,9 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock,
 		goto exit;
 	}
 
+	/* will be updated in set_orig_addr() if needed */
+	m->msg_namelen = 0;
+
 	timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
 restart:
 
@@ -1013,6 +1017,9 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock,
 		goto exit;
 	}
 
+	/* will be updated in set_orig_addr() if needed */
+	m->msg_namelen = 0;
+
 	target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len);
 	timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 15/16] VSOCK: vmci - fix possible info leak in vmci_transport_dgram_dequeue()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (13 preceding siblings ...)
  2013-04-07 11:52 ` [PATCH 14/16] tipc: fix info leaks via msg_name in recv_msg/recv_stream Mathias Krause
@ 2013-04-07 11:52 ` Mathias Krause
  2013-04-07 11:52 ` [PATCH 16/16] VSOCK: Fix missing msg_namelen update in vsock_stream_recvmsg() Mathias Krause
  2013-04-07 20:31 ` [PATCH 00/16] info leak fixes in recvmsg David Miller
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:52 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

In case we received no data on the call to skb_recv_datagram(), i.e.
skb->data is NULL, vmci_transport_dgram_dequeue() will return with 0
without updating msg_namelen leading to net/socket.c leaking the local,
uninitialized sockaddr_storage variable to userland -- 128 bytes of
kernel stack memory.

Fix this by moving the already existing msg_namelen assignment a few
lines above.

Cc: Andy King <acking@vmware.com>
Cc: Dmitry Torokhov <dtor@vmware.com>
Cc: George Zhang <georgezhang@vmware.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/vmw_vsock/vmci_transport.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c
index a70ace8..a8e4e70 100644
--- a/net/vmw_vsock/vmci_transport.c
+++ b/net/vmw_vsock/vmci_transport.c
@@ -1727,6 +1727,8 @@ static int vmci_transport_dgram_dequeue(struct kiocb *kiocb,
 	if (flags & MSG_OOB || flags & MSG_ERRQUEUE)
 		return -EOPNOTSUPP;
 
+	msg->msg_namelen = 0;
+
 	/* Retrieve the head sk_buff from the socket's receive queue. */
 	err = 0;
 	skb = skb_recv_datagram(&vsk->sk, flags, noblock, &err);
@@ -1759,7 +1761,6 @@ static int vmci_transport_dgram_dequeue(struct kiocb *kiocb,
 	if (err)
 		goto out;
 
-	msg->msg_namelen = 0;
 	if (msg->msg_name) {
 		struct sockaddr_vm *vm_addr;
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 16/16] VSOCK: Fix missing msg_namelen update in vsock_stream_recvmsg()
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (14 preceding siblings ...)
  2013-04-07 11:52 ` [PATCH 15/16] VSOCK: vmci - fix possible info leak in vmci_transport_dgram_dequeue() Mathias Krause
@ 2013-04-07 11:52 ` Mathias Krause
  2013-04-07 20:31 ` [PATCH 00/16] info leak fixes in recvmsg David Miller
  16 siblings, 0 replies; 19+ messages in thread
From: Mathias Krause @ 2013-04-07 11:52 UTC (permalink / raw)
  To: David S. Miller
  Cc: netdev, Allan Stephens, Aloisio Almeida Jr, Andy King,
	Arnaldo Carvalho de Melo, Dmitry Torokhov, George Zhang,
	Gustavo Padovan, Johan Hedberg, Jon Maloy, Lauro Ramos Venancio,
	Marcel Holtmann, Ralf Baechle, Samuel Ortiz, Samuel Ortiz,
	Sjur Braendeland, Ursula Braun, Brad Spengler, Mathias Krause

The code misses to update the msg_namelen member to 0 and therefore
makes net/socket.c leak the local, uninitialized sockaddr_storage
variable to userland -- 128 bytes of kernel stack memory.

Cc: Andy King <acking@vmware.com>
Cc: Dmitry Torokhov <dtor@vmware.com>
Cc: George Zhang <georgezhang@vmware.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 net/vmw_vsock/af_vsock.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index ca511c4..08a228d 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1670,6 +1670,8 @@ vsock_stream_recvmsg(struct kiocb *kiocb,
 	vsk = vsock_sk(sk);
 	err = 0;
 
+	msg->msg_namelen = 0;
+
 	lock_sock(sk);
 
 	if (sk->sk_state != SS_CONNECTED) {
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/16] info leak fixes in recvmsg
  2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
                   ` (15 preceding siblings ...)
  2013-04-07 11:52 ` [PATCH 16/16] VSOCK: Fix missing msg_namelen update in vsock_stream_recvmsg() Mathias Krause
@ 2013-04-07 20:31 ` David Miller
  16 siblings, 0 replies; 19+ messages in thread
From: David Miller @ 2013-04-07 20:31 UTC (permalink / raw)
  To: minipli
  Cc: netdev, allan.stephens, aloisio.almeida, acking, acme, dtor,
	georgezhang, gustavo, johan.hedberg, jon.maloy, lauro.venancio,
	marcel, ralf, sameo, samuel, sjur.brandeland, ursula.braun,
	spender

From: Mathias Krause <minipli@googlemail.com>
Date: Sun,  7 Apr 2013 13:51:46 +0200

> a few more info leak fixes in the recvmsg path. The error pattern here
> is the protocol specific recvmsg function is missing the msg_namelen
> assignment -- either completely or in early exit paths that do not
> result in errors in __sys_recvmsg()/sys_recvfrom() and, in turn, make
> them call move_addr_to_user(), leaking the then still uninitialized
> sockaddr_storage stack variable to userland.
> 
> My audit was initiated by a rather coarse fix of the leak that can be
> found in the grsecurity patch, putting a penalty on protocols complying
> to the rules of recvmsg. So credits for finding the leak in the recvmsg
> path in __sys_recvmsg() should go to Brad!
> 
> The buggy protocols/subsystems are rather obscure anyway. As a missing
> assignment of msg_namelen coupled with a missing filling of msg_name
> would only result in garbage -- the leak -- in case userland would care
> about that information, i.e. would provide a msg_name pointer. But
> obviously current userland does not.
> 
> While auditing the code for the above pattern I found a few more
> 'uninitialized members' kind of leaks related to the msg_name filling.
> Those are fixed in this series, too.
> 
> I have to admit, I failed to test all of the patches due to missing
> hardware, e.g. iucv depends on S390 -- hardware I've no access to :/

All applied and queued up for -stable, thanks!

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 08/16] iucv: Fix missing msg_namelen update in iucv_sock_recvmsg()
  2013-04-07 11:51 ` [PATCH 08/16] iucv: Fix missing msg_namelen update in iucv_sock_recvmsg() Mathias Krause
@ 2013-04-08 11:14   ` Ursula Braun
  0 siblings, 0 replies; 19+ messages in thread
From: Ursula Braun @ 2013-04-08 11:14 UTC (permalink / raw)
  To: Mathias Krause
  Cc: David S. Miller, netdev, Allan Stephens, Aloisio Almeida Jr,
	Andy King, Arnaldo Carvalho de Melo, Dmitry Torokhov,
	George Zhang, Gustavo Padovan, Johan Hedberg, Jon Maloy,
	Lauro Ramos Venancio, Marcel Holtmann, Ralf Baechle, Samuel Ortiz,
	Samuel Ortiz, Sjur Braendeland, Ursula Braun, Brad Spengler

On Sun, 2013-04-07 at 13:51 +0200, Mathias Krause wrote:
> The current code does not fill the msg_name member in case it is set.
> It also does not set the msg_namelen member to 0 and therefore makes
> net/socket.c leak the local, uninitialized sockaddr_storage variable
> to userland -- 128 bytes of kernel stack memory.
> 
> Fix that by simply setting msg_namelen to 0 as obviously nobody cared
> about iucv_sock_recvmsg() not filling the msg_name in case it was set.
> 
> Cc: Ursula Braun <ursula.braun@de.ibm.com>
> Signed-off-by: Mathias Krause <minipli@googlemail.com>
> ---
> Remark: I failed to test that one as I've no access to a S390 system.
> 
>  net/iucv/af_iucv.c |    2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
> index a7d11ffe..bf69358 100644
> --- a/net/iucv/af_iucv.c
> +++ b/net/iucv/af_iucv.c
> @@ -1328,6 +1328,8 @@ static int iucv_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
>  	struct sk_buff *skb, *rskb, *cskb;
>  	int err = 0;
> 
> +	msg->msg_namelen = 0;
> +
>  	if ((sk->sk_state == IUCV_DISCONN) &&
>  	    skb_queue_empty(&iucv->backlog_skb_q) &&
>  	    skb_queue_empty(&sk->sk_receive_queue) &&
Acked-by: Ursula Braun <ursula.braun@de.ibm.com>

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2013-04-08 11:14 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-07 11:51 [PATCH 00/16] info leak fixes in recvmsg Mathias Krause
2013-04-07 11:51 ` [PATCH 01/16] atm: update msg_namelen in vcc_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 02/16] ax25: fix info leak via msg_name in ax25_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 03/16] Bluetooth: fix possible info leak in bt_sock_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 04/16] Bluetooth: RFCOMM - Fix missing msg_namelen update in rfcomm_sock_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 05/16] Bluetooth: SCO - Fix missing msg_namelen update in sco_sock_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 06/16] caif: Fix missing msg_namelen update in caif_seqpkt_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 07/16] irda: Fix missing msg_namelen update in irda_recvmsg_dgram() Mathias Krause
2013-04-07 11:51 ` [PATCH 08/16] iucv: Fix missing msg_namelen update in iucv_sock_recvmsg() Mathias Krause
2013-04-08 11:14   ` Ursula Braun
2013-04-07 11:51 ` [PATCH 09/16] l2tp: fix info leak in l2tp_ip6_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 10/16] llc: Fix missing msg_namelen update in llc_ui_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 11/16] netrom: fix info leak via msg_name in nr_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 12/16] NFC: llcp: fix info leaks via msg_name in llcp_sock_recvmsg() Mathias Krause
2013-04-07 11:51 ` [PATCH 13/16] rose: fix info leak via msg_name in rose_recvmsg() Mathias Krause
2013-04-07 11:52 ` [PATCH 14/16] tipc: fix info leaks via msg_name in recv_msg/recv_stream Mathias Krause
2013-04-07 11:52 ` [PATCH 15/16] VSOCK: vmci - fix possible info leak in vmci_transport_dgram_dequeue() Mathias Krause
2013-04-07 11:52 ` [PATCH 16/16] VSOCK: Fix missing msg_namelen update in vsock_stream_recvmsg() Mathias Krause
2013-04-07 20:31 ` [PATCH 00/16] info leak fixes in recvmsg David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).