<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/net/compat.c, branch v3.17</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v3.17</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v3.17'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2014-07-29T19:20:22Z</updated>
<entry>
<title>net: sendmsg: fix NULL pointer dereference</title>
<updated>2014-07-29T19:20:22Z</updated>
<author>
<name>Andrey Ryabinin</name>
<email>ryabinin.a.a@gmail.com</email>
</author>
<published>2014-07-26T17:26:58Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=40eea803c6b2cfaab092f053248cbeab3f368412'/>
<id>urn:sha1:40eea803c6b2cfaab092f053248cbeab3f368412</id>
<content type='text'>
Sasha's report:
	&gt; While fuzzing with trinity inside a KVM tools guest running the latest -next
	&gt; kernel with the KASAN patchset, I've stumbled on the following spew:
	&gt;
	&gt; [ 4448.949424] ==================================================================
	&gt; [ 4448.951737] AddressSanitizer: user-memory-access on address 0
	&gt; [ 4448.952988] Read of size 2 by thread T19638:
	&gt; [ 4448.954510] CPU: 28 PID: 19638 Comm: trinity-c76 Not tainted 3.16.0-rc4-next-20140711-sasha-00046-g07d3099-dirty #813
	&gt; [ 4448.956823]  ffff88046d86ca40 0000000000000000 ffff880082f37e78 ffff880082f37a40
	&gt; [ 4448.958233]  ffffffffb6e47068 ffff880082f37a68 ffff880082f37a58 ffffffffb242708d
	&gt; [ 4448.959552]  0000000000000000 ffff880082f37a88 ffffffffb24255b1 0000000000000000
	&gt; [ 4448.961266] Call Trace:
	&gt; [ 4448.963158] dump_stack (lib/dump_stack.c:52)
	&gt; [ 4448.964244] kasan_report_user_access (mm/kasan/report.c:184)
	&gt; [ 4448.965507] __asan_load2 (mm/kasan/kasan.c:352)
	&gt; [ 4448.966482] ? netlink_sendmsg (net/netlink/af_netlink.c:2339)
	&gt; [ 4448.967541] netlink_sendmsg (net/netlink/af_netlink.c:2339)
	&gt; [ 4448.968537] ? get_parent_ip (kernel/sched/core.c:2555)
	&gt; [ 4448.970103] sock_sendmsg (net/socket.c:654)
	&gt; [ 4448.971584] ? might_fault (mm/memory.c:3741)
	&gt; [ 4448.972526] ? might_fault (./arch/x86/include/asm/current.h:14 mm/memory.c:3740)
	&gt; [ 4448.973596] ? verify_iovec (net/core/iovec.c:64)
	&gt; [ 4448.974522] ___sys_sendmsg (net/socket.c:2096)
	&gt; [ 4448.975797] ? put_lock_stats.isra.13 (./arch/x86/include/asm/preempt.h:98 kernel/locking/lockdep.c:254)
	&gt; [ 4448.977030] ? lock_release_holdtime (kernel/locking/lockdep.c:273)
	&gt; [ 4448.978197] ? lock_release_non_nested (kernel/locking/lockdep.c:3434 (discriminator 1))
	&gt; [ 4448.979346] ? check_chain_key (kernel/locking/lockdep.c:2188)
	&gt; [ 4448.980535] __sys_sendmmsg (net/socket.c:2181)
	&gt; [ 4448.981592] ? trace_hardirqs_on_caller (kernel/locking/lockdep.c:2600)
	&gt; [ 4448.982773] ? trace_hardirqs_on (kernel/locking/lockdep.c:2607)
	&gt; [ 4448.984458] ? syscall_trace_enter (arch/x86/kernel/ptrace.c:1500 (discriminator 2))
	&gt; [ 4448.985621] ? trace_hardirqs_on_caller (kernel/locking/lockdep.c:2600)
	&gt; [ 4448.986754] SyS_sendmmsg (net/socket.c:2201)
	&gt; [ 4448.987708] tracesys (arch/x86/kernel/entry_64.S:542)
	&gt; [ 4448.988929] ==================================================================

This reports means that we've come to netlink_sendmsg() with msg-&gt;msg_name == NULL and msg-&gt;msg_namelen &gt; 0.

After this report there was no usual "Unable to handle kernel NULL pointer dereference"
and this gave me a clue that address 0 is mapped and contains valid socket address structure in it.

This bug was introduced in f3d3342602f8bcbf37d7c46641cb9bca7618eb1c
(net: rework recvmsg handler msg_name and msg_namelen logic).
Commit message states that:
	"Set msg-&gt;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."
But in fact this affects sendto when address 0 is mapped and contains
socket address structure in it. In such case copy-in address will succeed,
verify_iovec() function will successfully exit with msg-&gt;msg_namelen &gt; 0
and msg-&gt;msg_name == NULL.

This patch fixes it by setting msg_namelen to 0 if msg_name == NULL.

Cc: Hannes Frederic Sowa &lt;hannes@stressinduktion.org&gt;
Cc: Eric Dumazet &lt;edumazet@google.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Reported-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
Signed-off-by: Andrey Ryabinin &lt;a.ryabinin@samsung.com&gt;
Acked-by: Hannes Frederic Sowa &lt;hannes@stressinduktion.org&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>net/compat: convert to COMPAT_SYSCALL_DEFINE with changing parameter types</title>
<updated>2014-03-06T15:30:45Z</updated>
<author>
<name>Heiko Carstens</name>
<email>heiko.carstens@de.ibm.com</email>
</author>
<published>2014-03-04T16:09:57Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=3a49a0f7181c243aa04e6c5e44ca70a90ead8f9a'/>
<id>urn:sha1:3a49a0f7181c243aa04e6c5e44ca70a90ead8f9a</id>
<content type='text'>
In order to allow the COMPAT_SYSCALL_DEFINE macro generate code that
performs proper zero and sign extension convert all 64 bit parameters
to their corresponding 32 bit compat counterparts.

Signed-off-by: Heiko Carstens &lt;heiko.carstens@de.ibm.com&gt;
</content>
</entry>
<entry>
<title>net/compat: convert to COMPAT_SYSCALL_DEFINE</title>
<updated>2014-03-06T14:35:11Z</updated>
<author>
<name>Heiko Carstens</name>
<email>heiko.carstens@de.ibm.com</email>
</author>
<published>2014-03-03T15:21:27Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=361d93c46f688d1a2209912bda377bdb48842cce'/>
<id>urn:sha1:361d93c46f688d1a2209912bda377bdb48842cce</id>
<content type='text'>
Convert all compat system call functions where all parameter types
have a size of four or less than four bytes, or are pointer types
to COMPAT_SYSCALL_DEFINE.
The implicit casts within COMPAT_SYSCALL_DEFINE will perform proper
zero and sign extension to 64 bit of all parameters if needed.

Signed-off-by: Heiko Carstens &lt;heiko.carstens@de.ibm.com&gt;
</content>
</entry>
<entry>
<title>x86, x32: Correct invalid use of user timespec in the kernel</title>
<updated>2014-01-31T02:44:13Z</updated>
<author>
<name>PaX Team</name>
<email>pageexec@freemail.hu</email>
</author>
<published>2014-01-31T00:59:25Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=2def2ef2ae5f3990aabdbe8a755911902707d268'/>
<id>urn:sha1:2def2ef2ae5f3990aabdbe8a755911902707d268</id>
<content type='text'>
The x32 case for the recvmsg() timout handling is broken:

  asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
                                      unsigned int vlen, unsigned int flags,
                                      struct compat_timespec __user *timeout)
  {
          int datagrams;
          struct timespec ktspec;

          if (flags &amp; MSG_CMSG_COMPAT)
                  return -EINVAL;

          if (COMPAT_USE_64BIT_TIME)
                  return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
                                        flags | MSG_CMSG_COMPAT,
                                        (struct timespec *) timeout);
          ...

The timeout pointer parameter is provided by userland (hence the __user
annotation) but for x32 syscalls it's simply cast to a kernel pointer
and is passed to __sys_recvmmsg which will eventually directly
dereference it for both reading and writing.  Other callers to
__sys_recvmmsg properly copy from userland to the kernel first.

The bug was introduced by commit ee4fa23c4bfc ("compat: Use
COMPAT_USE_64BIT_TIME in net/compat.c") and should affect all kernels
since 3.4 (and perhaps vendor kernels if they backported x32 support
along with this code).

Note that CONFIG_X86_X32_ABI gets enabled at build time and only if
CONFIG_X86_X32 is enabled and ld can build x32 executables.

Other uses of COMPAT_USE_64BIT_TIME seem fine.

This addresses CVE-2014-0038.

Signed-off-by: PaX Team &lt;pageexec@freemail.hu&gt;
Signed-off-by: H. Peter Anvin &lt;hpa@linux.intel.com&gt;
Cc: &lt;stable@vger.kernel.org&gt; # v3.4+
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>net: clamp -&gt;msg_namelen instead of returning an error</title>
<updated>2013-11-29T21:12:52Z</updated>
<author>
<name>Dan Carpenter</name>
<email>dan.carpenter@oracle.com</email>
</author>
<published>2013-11-27T12:40:21Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=db31c55a6fb245fdbb752a2ca4aefec89afabb06'/>
<id>urn:sha1:db31c55a6fb245fdbb752a2ca4aefec89afabb06</id>
<content type='text'>
If kmsg-&gt;msg_namelen &gt; sizeof(struct sockaddr_storage) then in the
original code that would lead to memory corruption in the kernel if you
had audit configured.  If you didn't have audit configured it was
harmless.

There are some programs such as beta versions of Ruby which use too
large of a buffer and returning an error code breaks them.  We should
clamp the -&gt;msg_namelen value instead.

Fixes: 1661bf364ae9 ("net: heap overflow in __audit_sockaddr()")
Reported-by: Eric Wong &lt;normalperson@yhbt.net&gt;
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Tested-by: Eric Wong &lt;normalperson@yhbt.net&gt;
Acked-by: Eric Dumazet &lt;edumazet@google.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>net: rework recvmsg handler msg_name and msg_namelen logic</title>
<updated>2013-11-21T02:52:30Z</updated>
<author>
<name>Hannes Frederic Sowa</name>
<email>hannes@stressinduktion.org</email>
</author>
<published>2013-11-21T02:14:22Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=f3d3342602f8bcbf37d7c46641cb9bca7618eb1c'/>
<id>urn:sha1:f3d3342602f8bcbf37d7c46641cb9bca7618eb1c</id>
<content type='text'>
This patch now always passes msg-&gt;msg_namelen as 0. recvmsg handlers must
set msg_namelen to the proper size &lt;= 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-&gt;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-&gt;msg_namelen == 0)
	msg-&gt;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 &lt;davem@davemloft.net&gt;
Suggested-by: Eric Dumazet &lt;eric.dumazet@gmail.com&gt;
Signed-off-by: Hannes Frederic Sowa &lt;hannes@stressinduktion.org&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>net: heap overflow in __audit_sockaddr()</title>
<updated>2013-10-03T20:05:14Z</updated>
<author>
<name>Dan Carpenter</name>
<email>dan.carpenter@oracle.com</email>
</author>
<published>2013-10-02T21:27:20Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=1661bf364ae9c506bc8795fef70d1532931be1e8'/>
<id>urn:sha1:1661bf364ae9c506bc8795fef70d1532931be1e8</id>
<content type='text'>
We need to cap -&gt;msg_namelen or it leads to a buffer overflow when we
to the memcpy() in __audit_sockaddr().  It requires CAP_AUDIT_CONTROL to
exploit this bug.

The call tree is:
___sys_recvmsg()
  move_addr_to_user()
    audit_sockaddr()
      __audit_sockaddr()

Reported-by: Jüri Aedla &lt;juri.aedla@gmail.com&gt;
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>net: Unbreak compat_sys_{send,recv}msg</title>
<updated>2013-06-06T18:52:14Z</updated>
<author>
<name>Andy Lutomirski</name>
<email>luto@amacapital.net</email>
</author>
<published>2013-06-05T19:38:26Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=a7526eb5d06b0084ef12d7b168d008fcf516caab'/>
<id>urn:sha1:a7526eb5d06b0084ef12d7b168d008fcf516caab</id>
<content type='text'>
I broke them in this commit:

    commit 1be374a0518a288147c6a7398792583200a67261
    Author: Andy Lutomirski &lt;luto@amacapital.net&gt;
    Date:   Wed May 22 14:07:44 2013 -0700

        net: Block MSG_CMSG_COMPAT in send(m)msg and recv(m)msg

This patch adds __sys_sendmsg and __sys_sendmsg as common helpers that accept
MSG_CMSG_COMPAT and blocks MSG_CMSG_COMPAT at the syscall entrypoints.  It
also reverts some unnecessary checks in sys_socketcall.

Apparently I was suffering from underscore blindness the first time around.

Signed-off-by: Andy Lutomirski &lt;luto@amacapital.net&gt;
Tested-by: Eric Dumazet &lt;edumazet@google.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>make get_file() return its argument</title>
<updated>2012-09-27T01:10:25Z</updated>
<author>
<name>Al Viro</name>
<email>viro@zeniv.linux.org.uk</email>
</author>
<published>2012-08-27T18:48:26Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=cb0942b81249798e15c3f04eee2946ef543e8115'/>
<id>urn:sha1:cb0942b81249798e15c3f04eee2946ef543e8115</id>
<content type='text'>
simplifies a bunch of callers...

Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
</content>
</entry>
<entry>
<title>net: Fix references to out-of-scope variables in put_cmsg_compat()</title>
<updated>2012-07-23T00:50:49Z</updated>
<author>
<name>Jesper Juhl</name>
<email>jj@chaosbits.net</email>
</author>
<published>2012-07-22T11:37:20Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=818810472b129004c16fc51bf0a570b60776bfb7'/>
<id>urn:sha1:818810472b129004c16fc51bf0a570b60776bfb7</id>
<content type='text'>
In net/compat.c::put_cmsg_compat() we may assign 'data' the address of
either the 'ctv' or 'cts' local variables inside the 'if
(!COMPAT_USE_64BIT_TIME)' branch.

Those variables go out of scope at the end of the 'if' statement, so
when we use 'data' further down in 'copy_to_user(CMSG_COMPAT_DATA(cm),
data, cmlen - sizeof(struct compat_cmsghdr))' there's no telling what
it may be refering to - not good.

Fix the problem by simply giving 'ctv' and 'cts' function scope.

Signed-off-by: Jesper Juhl &lt;jj@chaosbits.net&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
</feed>
