linux-stable/net/x25
Hannes Frederic Sowa 4485f23cb4 net: rework recvmsg handler msg_name and msg_namelen logic
CVE-2013-7266

BugLink: http://bugs.launchpad.net/bugs/1267081

This patch now always passes msg->msg_namelen as 0. recvmsg handlers must
set msg_namelen to the proper size <= sizeof(struct sockaddr_storage)
to return msg_name to the user.

This prevents numerous uninitialized memory leaks we had in the
recvmsg handlers and makes it harder for new code to accidentally leak
uninitialized memory.

Optimize for the case recvfrom is called with NULL as address. We don't
need to copy the address at all, so set it to NULL before invoking the
recvmsg handler. We can do so, because all the recvmsg handlers must
cope with the case a plain read() is called on them. read() also sets
msg_name to NULL.

Also document these changes in include/linux/net.h as suggested by David
Miller.

Changes since RFC:

Set msg->msg_name = NULL if user specified a NULL in msg_name but had a
non-null msg_namelen in verify_iovec/verify_compat_iovec. This doesn't
affect sendto as it would bail out earlier while trying to copy-in the
address. It also more naturally reflects the logic by the callers of
verify_iovec.

With this change in place I could remove "
if (!uaddr || msg_sys->msg_namelen == 0)
	msg->msg_name = NULL
".

This change does not alter the user visible error logic as we ignore
msg_namelen as long as msg_name is NULL.

Also remove two unnecessary curly brackets in ___sys_recvmsg and change
comments to netdev style.

Cc: David Miller <davem@davemloft.net>
Suggested-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
(back ported from commit f3d3342602)
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
Acked-by: Andy Whitcroft <andy.whitcroft@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
2014-05-19 07:54:00 +02:00
..
af_x25.c net: rework recvmsg handler msg_name and msg_namelen logic 2014-05-19 07:54:00 +02:00
Kconfig [NET]: move config options out to individual protocols 2005-07-11 21:13:56 -07:00
Makefile [X.25]: Add call forwarding 2007-02-08 13:34:02 -08:00
sysctl_net_x25.c net: '&' redux 2008-11-03 18:21:05 -08:00
x25_dev.c netns: Use net_eq() to compare net-namespaces for optimization. 2008-07-19 22:34:43 -07:00
x25_facilities.c x25: Prevent crashing when parsing bad X.25 facilities 2010-12-09 13:27:10 -08:00
x25_forward.c [X25]: use LIST_HEAD instead of LIST_HEAD_INIT 2008-01-28 14:56:53 -08:00
x25_in.c memory corruption in X.25 facilities parsing 2010-12-09 13:27:09 -08:00
x25_link.c x25: Do not reference freed memory. 2011-03-02 09:47:07 -05:00
x25_out.c [SK_BUFF]: Introduce skb_copy_to_linear_data{_offset} 2007-04-25 22:28:29 -07:00
x25_proc.c net: correct off-by-one write allocations reports 2009-06-18 00:29:12 -07:00
x25_route.c [X25]: use LIST_HEAD instead of LIST_HEAD_INIT 2008-01-28 14:56:53 -08:00
x25_subr.c [X25]: Avoid divides and sparse warnings 2008-01-28 15:02:03 -08:00
x25_timer.c x25: Fix sleep from timer on socket destroy. 2009-06-16 05:40:30 -07:00