<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/ipc/msgutil.c, branch v3.12.14</title>
<subtitle>Linux kernel source tree</subtitle>
<id>https://git.amat.us/linux/atom/ipc/msgutil.c?h=v3.12.14</id>
<link rel='self' href='https://git.amat.us/linux/atom/ipc/msgutil.c?h=v3.12.14'/>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/'/>
<updated>2013-12-04T19:05:22Z</updated>
<entry>
<title>ipc, msg: fix message length check for negative values</title>
<updated>2013-12-04T19:05:22Z</updated>
<author>
<name>Mathias Krause</name>
<email>minipli@googlemail.com</email>
</author>
<published>2013-11-12T23:11:47Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=620ff33d7cb1d446c1e24fbfe1a033106b99e5c4'/>
<id>urn:sha1:620ff33d7cb1d446c1e24fbfe1a033106b99e5c4</id>
<content type='text'>
commit 4e9b45a19241354daec281d7a785739829b52359 upstream.

On 64 bit systems the test for negative message sizes is bogus as the
size, which may be positive when evaluated as a long, will get truncated
to an int when passed to load_msg().  So a long might very well contain a
positive value but when truncated to an int it would become negative.

That in combination with a small negative value of msg_ctlmax (which will
be promoted to an unsigned type for the comparison against msgsz, making
it a big positive value and therefore make it pass the check) will lead to
two problems: 1/ The kmalloc() call in alloc_msg() will allocate a too
small buffer as the addition of alen is effectively a subtraction.  2/ The
copy_from_user() call in load_msg() will first overflow the buffer with
userland data and then, when the userland access generates an access
violation, the fixup handler copy_user_handle_tail() will try to fill the
remainder with zeros -- roughly 4GB.  That almost instantly results in a
system crash or reset.

  ,-[ Reproducer (needs to be run as root) ]--
  | #include &lt;sys/stat.h&gt;
  | #include &lt;sys/msg.h&gt;
  | #include &lt;unistd.h&gt;
  | #include &lt;fcntl.h&gt;
  |
  | int main(void) {
  |     long msg = 1;
  |     int fd;
  |
  |     fd = open("/proc/sys/kernel/msgmax", O_WRONLY);
  |     write(fd, "-1", 2);
  |     close(fd);
  |
  |     msgsnd(0, &amp;msg, 0xfffffff0, IPC_NOWAIT);
  |
  |     return 0;
  | }
  '---

Fix the issue by preventing msgsz from getting truncated by consistently
using size_t for the message length.  This way the size checks in
do_msgsnd() could still be passed with a negative value for msg_ctlmax but
we would fail on the buffer allocation in that case and error out.

Also change the type of m_ts from int to size_t to avoid similar nastiness
in other code paths -- it is used in similar constructs, i.e.  signed vs.
unsigned checks.  It should never become negative under normal
circumstances, though.

Setting msg_ctlmax to a negative value is an odd configuration and should
be prevented.  As that might break existing userland, it will be handled
in a separate commit so it could easily be reverted and reworked without
reintroducing the above described bug.

Hardening mechanisms for user copy operations would have catched that bug
early -- e.g.  checking slab object sizes on user copy operations as the
usercopy feature of the PaX patch does.  Or, for that matter, detect the
long vs.  int sign change due to truncation, as the size overflow plugin
of the very same patch does.

[akpm@linux-foundation.org: fix i386 min() warnings]
Signed-off-by: Mathias Krause &lt;minipli@googlemail.com&gt;
Cc: Pax Team &lt;pageexec@freemail.hu&gt;
Cc: Davidlohr Bueso &lt;davidlohr@hp.com&gt;
Cc: Brad Spengler &lt;spender@grsecurity.net&gt;
Cc: Manfred Spraul &lt;manfred@colorfullife.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs</title>
<updated>2013-05-02T00:51:54Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2013-05-02T00:51:54Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=20b4fb485227404329e41ad15588afad3df23050'/>
<id>urn:sha1:20b4fb485227404329e41ad15588afad3df23050</id>
<content type='text'>
Pull VFS updates from Al Viro,

Misc cleanups all over the place, mainly wrt /proc interfaces (switch
create_proc_entry to proc_create(), get rid of the deprecated
create_proc_read_entry() in favor of using proc_create_data() and
seq_file etc).

7kloc removed.

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (204 commits)
  don't bother with deferred freeing of fdtables
  proc: Move non-public stuff from linux/proc_fs.h to fs/proc/internal.h
  proc: Make the PROC_I() and PDE() macros internal to procfs
  proc: Supply a function to remove a proc entry by PDE
  take cgroup_open() and cpuset_open() to fs/proc/base.c
  ppc: Clean up scanlog
  ppc: Clean up rtas_flash driver somewhat
  hostap: proc: Use remove_proc_subtree()
  drm: proc: Use remove_proc_subtree()
  drm: proc: Use minor-&gt;index to label things, not PDE-&gt;name
  drm: Constify drm_proc_list[]
  zoran: Don't print proc_dir_entry data in debug
  reiserfs: Don't access the proc_dir_entry in r_open(), r_start() r_show()
  proc: Supply an accessor for getting the data from a PDE's parent
  airo: Use remove_proc_subtree()
  rtl8192u: Don't need to save device proc dir PDE
  rtl8187se: Use a dir under /proc/net/r8180/
  proc: Add proc_mkdir_data()
  proc: Move some bits from linux/proc_fs.h to linux/{of.h,signal.h,tty.h}
  proc: Move PDE_NET() to fs/proc/proc_net.c
  ...
</content>
</entry>
<entry>
<title>proc: Split the namespace stuff out into linux/proc_ns.h</title>
<updated>2013-05-01T21:29:39Z</updated>
<author>
<name>David Howells</name>
<email>dhowells@redhat.com</email>
</author>
<published>2013-04-12T00:50:06Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=0bb80f240520c4148b623161e7856858c021696d'/>
<id>urn:sha1:0bb80f240520c4148b623161e7856858c021696d</id>
<content type='text'>
Split the proc namespace stuff out into linux/proc_ns.h.

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
cc: netdev@vger.kernel.org
cc: Serge E. Hallyn &lt;serge.hallyn@ubuntu.com&gt;
cc: Eric W. Biederman &lt;ebiederm@xmission.com&gt;
Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
</content>
</entry>
<entry>
<title>ipc/msgutil.c: use linux/uaccess.h</title>
<updated>2013-05-01T15:12:57Z</updated>
<author>
<name>HoSung Jung</name>
<email>rain6557@gmail.com</email>
</author>
<published>2013-05-01T02:15:09Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=1e3c941c52eab70c8acb2f77829c24673445c858'/>
<id>urn:sha1:1e3c941c52eab70c8acb2f77829c24673445c858</id>
<content type='text'>
Signed-off-by: HoSung Jung &lt;rain6557@gmail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ipc: set EFAULT as default error in load_msg()</title>
<updated>2013-05-01T15:12:57Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-05-01T02:14:42Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=2b3097a294b6daaf390010de14ca50bfccbc6fb6'/>
<id>urn:sha1:2b3097a294b6daaf390010de14ca50bfccbc6fb6</id>
<content type='text'>
Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Acked-by: Stanislav Kinsbursky &lt;skinsbursky@parallels.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ipc: tighten msg copy loops</title>
<updated>2013-05-01T15:12:57Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-05-01T02:14:37Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=da085d4591a6fe11eac2e1f659f25b655e9f2e53'/>
<id>urn:sha1:da085d4591a6fe11eac2e1f659f25b655e9f2e53</id>
<content type='text'>
Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Acked-by: Stanislav Kinsbursky &lt;skinsbursky@parallels.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ipc: separate msg allocation from userspace copy</title>
<updated>2013-05-01T15:12:57Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-05-01T02:14:31Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=be5f4b335f6e05df1b5c24b7e7d79ff52d7b8dbc'/>
<id>urn:sha1:be5f4b335f6e05df1b5c24b7e7d79ff52d7b8dbc</id>
<content type='text'>
Separating msg allocation enables single-block vmalloc
allocation instead.

Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Acked-by: Stanislav Kinsbursky &lt;skinsbursky@parallels.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ipc: clamp with min()</title>
<updated>2013-05-01T15:12:57Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-05-01T02:14:25Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=3d8fa456d5ed22ce8db085a89a037b87568b2b64'/>
<id>urn:sha1:3d8fa456d5ed22ce8db085a89a037b87568b2b64</id>
<content type='text'>
Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Acked-by: Stanislav Kinsbursky &lt;skinsbursky@parallels.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ipc: fix potential oops when src msg &gt; 4k w/ MSG_COPY</title>
<updated>2013-03-08T23:05:33Z</updated>
<author>
<name>Peter Hurley</name>
<email>peter@hurleysoftware.com</email>
</author>
<published>2013-03-08T20:43:26Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=e1082f45f1e2bbf6e25f6b614fc6616ebf709d19'/>
<id>urn:sha1:e1082f45f1e2bbf6e25f6b614fc6616ebf709d19</id>
<content type='text'>
If the src msg is &gt; 4k, then dest-&gt;next points to the
next allocated segment; resetting it just prior to dereferencing
is bad.

Signed-off-by: Peter Hurley &lt;peter@hurleysoftware.com&gt;
Acked-by: Stanislav Kinsbursky &lt;skinsbursky@parallels.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ipc: simplify message copying</title>
<updated>2013-01-05T00:11:46Z</updated>
<author>
<name>Stanislav Kinsbursky</name>
<email>skinsbursky@parallels.com</email>
</author>
<published>2013-01-04T23:35:01Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=51eeacaa07d1372a7bc9612548ffe6cd846f4f2f'/>
<id>urn:sha1:51eeacaa07d1372a7bc9612548ffe6cd846f4f2f</id>
<content type='text'>
Remove the redundant and confusing fill_copy().  Also add copy_msg()
check for error.  In this case exit from the function have to be done
instead of break, because further code interprets any error as EAGAIN.

Also define copy_msg() for the case when CONFIG_CHECKPOINT_RESTORE is
disabled.

Signed-off-by: Stanislav Kinsbursky &lt;skinsbursky@parallels.com&gt;
Cc: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Cc: James Morris &lt;jmorris@namei.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
</feed>
