<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/ipc, branch v3.12.10</title>
<subtitle>Linux kernel source tree</subtitle>
<id>https://git.amat.us/linux/atom/ipc?h=v3.12.10</id>
<link rel='self' href='https://git.amat.us/linux/atom/ipc?h=v3.12.10'/>
<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>ipc,shm: fix shm_file deletion races</title>
<updated>2013-11-29T19:27:54Z</updated>
<author>
<name>Greg Thelen</name>
<email>gthelen@google.com</email>
</author>
<published>2013-11-21T22:32:00Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=dd272212175ad47ee84cf38e9d5f99502df2d930'/>
<id>urn:sha1:dd272212175ad47ee84cf38e9d5f99502df2d930</id>
<content type='text'>
commit a399b29dfbaaaf91162b2dc5a5875dd51bbfa2a1 upstream.

When IPC_RMID races with other shm operations there's potential for
use-after-free of the shm object's associated file (shm_file).

Here's the race before this patch:

  TASK 1                     TASK 2
  ------                     ------
  shm_rmid()
    ipc_lock_object()
                             shmctl()
                             shp = shm_obtain_object_check()

    shm_destroy()
      shum_unlock()
      fput(shp-&gt;shm_file)
                             ipc_lock_object()
                             shmem_lock(shp-&gt;shm_file)
                             &lt;OOPS&gt;

The oops is caused because shm_destroy() calls fput() after dropping the
ipc_lock.  fput() clears the file's f_inode, f_path.dentry, and
f_path.mnt, which causes various NULL pointer references in task 2.  I
reliably see the oops in task 2 if with shmlock, shmu

This patch fixes the races by:
1) set shm_file=NULL in shm_destroy() while holding ipc_object_lock().
2) modify at risk operations to check shm_file while holding
   ipc_object_lock().

Example workloads, which each trigger oops...

Workload 1:
  while true; do
    id=$(shmget 1 4096)
    shm_rmid $id &amp;
    shmlock $id &amp;
    wait
  done

  The oops stack shows accessing NULL f_inode due to racing fput:
    _raw_spin_lock
    shmem_lock
    SyS_shmctl

Workload 2:
  while true; do
    id=$(shmget 1 4096)
    shmat $id 4096 &amp;
    shm_rmid $id &amp;
    wait
  done

  The oops stack is similar to workload 1 due to NULL f_inode:
    touch_atime
    shmem_mmap
    shm_mmap
    mmap_region
    do_mmap_pgoff
    do_shmat
    SyS_shmat

Workload 3:
  while true; do
    id=$(shmget 1 4096)
    shmlock $id
    shm_rmid $id &amp;
    shmunlock $id &amp;
    wait
  done

  The oops stack shows second fput tripping on an NULL f_inode.  The
  first fput() completed via from shm_destroy(), but a racing thread did
  a get_file() and queued this fput():
    locks_remove_flock
    __fput
    ____fput
    task_work_run
    do_notify_resume
    int_signal

Fixes: c2c737a0461e ("ipc,shm: shorten critical region for shmat")
Fixes: 2caacaa82a51 ("ipc,shm: shorten critical region for shmctl")
Signed-off-by: Greg Thelen &lt;gthelen@google.com&gt;
Cc: Davidlohr Bueso &lt;davidlohr@hp.com&gt;
Cc: Rik van Riel &lt;riel@redhat.com&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>ipc,shm: correct error return value in shmctl (SHM_UNLOCK)</title>
<updated>2013-11-29T19:27:53Z</updated>
<author>
<name>Jesper Nilsson</name>
<email>jesper.nilsson@axis.com</email>
</author>
<published>2013-11-21T22:32:08Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=bf628e80c085da4aec49792b087516160283c2fe'/>
<id>urn:sha1:bf628e80c085da4aec49792b087516160283c2fe</id>
<content type='text'>
commit 3a72660b07d86d60457ca32080b1ce8c2b628ee2 upstream.

Commit 2caacaa82a51 ("ipc,shm: shorten critical region for shmctl")
restructured the ipc shm to shorten critical region, but introduced a
path where the return value could be -EPERM, even if the operation
actually was performed.

Before the commit, the err return value was reset by the return value
from security_shm_shmctl() after the if (!ns_capable(...)) statement.

Now, we still exit the if statement with err set to -EPERM, and in the
case of SHM_UNLOCK, it is not reset at all, and used as the return value
from shmctl.

To fix this, we only set err when errors occur, leaving the fallthrough
case alone.

Signed-off-by: Jesper Nilsson &lt;jesper.nilsson@axis.com&gt;
Cc: Davidlohr Bueso &lt;davidlohr@hp.com&gt;
Cc: Rik van Riel &lt;riel@redhat.com&gt;
Cc: Michel Lespinasse &lt;walken@google.com&gt;
Cc: Al Viro &lt;viro@zeniv.linux.org.uk&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>ipc, msg: forbid negative values for "msg{max,mnb,mni}"</title>
<updated>2013-11-03T18:53:11Z</updated>
<author>
<name>Mathias Krause</name>
<email>minipli@googlemail.com</email>
</author>
<published>2013-11-03T11:36:28Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=9bf76ca325d5e9208eb343f7bd4cc666f703ed30'/>
<id>urn:sha1:9bf76ca325d5e9208eb343f7bd4cc666f703ed30</id>
<content type='text'>
Negative message lengths make no sense -- so don't do negative queue
lenghts or identifier counts. Prevent them from getting negative.

Also change the underlying data types to be unsigned to avoid hairy
surprises with sign extensions in cases where those variables get
evaluated in unsigned expressions with bigger data types, e.g size_t.

In case a user still wants to have "unlimited" sizes she could just use
INT_MAX instead.

Signed-off-by: Mathias Krause &lt;minipli@googlemail.com&gt;
Cc: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ipc/sem.c: synchronize semop and semctl with IPC_RMID</title>
<updated>2013-10-17T04:35:52Z</updated>
<author>
<name>Manfred Spraul</name>
<email>manfred@colorfullife.com</email>
</author>
<published>2013-10-16T20:46:45Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=6e224f94597842c5eb17f1fc2208d20b6f7f7d49'/>
<id>urn:sha1:6e224f94597842c5eb17f1fc2208d20b6f7f7d49</id>
<content type='text'>
After acquiring the semlock spinlock, operations must test that the
array is still valid.

 - semctl() and exit_sem() would walk stale linked lists (ugly, but
   should be ok: all lists are empty)

 - semtimedop() would sleep forever - and if woken up due to a signal -
   access memory after free.

The patch also:
 - standardizes the tests for .deleted, so that all tests in one
   function leave the function with the same approach.
 - unconditionally tests for .deleted immediately after every call to
   sem_lock - even it it means that for semctl(GETALL), .deleted will be
   tested twice.

Both changes make the review simpler: After every sem_lock, there must
be a test of .deleted, followed by a goto to the cleanup code (if the
function uses "goto cleanup").

The only exception is semctl_down(): If sem_ids().rwsem is locked, then
the presence in ids-&gt;ipcs_idr is equivalent to !.deleted, thus no
additional test is required.

Signed-off-by: Manfred Spraul &lt;manfred@colorfullife.com&gt;
Cc: Mike Galbraith &lt;efault@gmx.de&gt;
Acked-by: Davidlohr Bueso &lt;davidlohr@hp.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: update locking scheme comments</title>
<updated>2013-10-17T04:35:52Z</updated>
<author>
<name>Davidlohr Bueso</name>
<email>davidlohr@hp.com</email>
</author>
<published>2013-10-16T20:46:45Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=18ccee263c7e250a57f01c9434658f11f4118a64'/>
<id>urn:sha1:18ccee263c7e250a57f01c9434658f11f4118a64</id>
<content type='text'>
The initial documentation was a bit incomplete, update accordingly.

[akpm@linux-foundation.org: make it more readable in 80 columns]
Signed-off-by: Davidlohr Bueso &lt;davidlohr@hp.com&gt;
Acked-by: 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;
</content>
</entry>
<entry>
<title>ipc,msg: prevent race with rmid in msgsnd,msgrcv</title>
<updated>2013-09-30T21:31:03Z</updated>
<author>
<name>Davidlohr Bueso</name>
<email>davidlohr@hp.com</email>
</author>
<published>2013-09-30T20:45:26Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=4271b05a227dc6175b66c3d9941aeab09048aeb2'/>
<id>urn:sha1:4271b05a227dc6175b66c3d9941aeab09048aeb2</id>
<content type='text'>
This fixes a race in both msgrcv() and msgsnd() between finding the msg
and actually dealing with the queue, as another thread can delete shmid
underneath us if we are preempted before acquiring the
kern_ipc_perm.lock.

Manfred illustrates this nicely:

Assume a preemptible kernel that is preempted just after

    msq = msq_obtain_object_check(ns, msqid)

in do_msgrcv().  The only lock that is held is rcu_read_lock().

Now the other thread processes IPC_RMID.  When the first task is
resumed, then it will happily wait for messages on a deleted queue.

Fix this by checking for if the queue has been deleted after taking the
lock.

Signed-off-by: Davidlohr Bueso &lt;davidlohr@hp.com&gt;
Reported-by: Manfred Spraul &lt;manfred@colorfullife.com&gt;
Cc: Rik van Riel &lt;riel@redhat.com&gt;
Cc: Mike Galbraith &lt;efault@gmx.de&gt;
Cc: &lt;stable@vger.kernel.org&gt; 	[3.11]
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/sem.c: update sem_otime for all operations</title>
<updated>2013-09-30T21:31:03Z</updated>
<author>
<name>Manfred Spraul</name>
<email>manfred@colorfullife.com</email>
</author>
<published>2013-09-30T20:45:25Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=0e8c665699e953fa58dc1b0b0d09e5dce7343cc7'/>
<id>urn:sha1:0e8c665699e953fa58dc1b0b0d09e5dce7343cc7</id>
<content type='text'>
In commit 0a2b9d4c7967 ("ipc/sem.c: move wake_up_process out of the
spinlock section"), the update of semaphore's sem_otime(last semop time)
was moved to one central position (do_smart_update).

But since do_smart_update() is only called for operations that modify
the array, this means that wait-for-zero semops do not update sem_otime
anymore.

The fix is simple:
Non-alter operations must update sem_otime.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Manfred Spraul &lt;manfred@colorfullife.com&gt;
Reported-by: Jia He &lt;jiakernel@gmail.com&gt;
Tested-by: Jia He &lt;jiakernel@gmail.com&gt;
Cc: Davidlohr Bueso &lt;davidlohr.bueso@hp.com&gt;
Cc: Mike Galbraith &lt;efault@gmx.de&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/sem.c: synchronize the proc interface</title>
<updated>2013-09-30T21:31:01Z</updated>
<author>
<name>Manfred Spraul</name>
<email>manfred@colorfullife.com</email>
</author>
<published>2013-09-30T20:45:07Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=d8c633766ad88527f25d9f81a5c2f083d78a2b39'/>
<id>urn:sha1:d8c633766ad88527f25d9f81a5c2f083d78a2b39</id>
<content type='text'>
The proc interface is not aware of sem_lock(), it instead calls
ipc_lock_object() directly.  This means that simple semop() operations
can run in parallel with the proc interface.  Right now, this is
uncritical, because the implementation doesn't do anything that requires
a proper synchronization.

But it is dangerous and therefore should be fixed.

Signed-off-by: Manfred Spraul &lt;manfred@colorfullife.com&gt;
Cc: Davidlohr Bueso &lt;davidlohr.bueso@hp.com&gt;
Cc: Mike Galbraith &lt;efault@gmx.de&gt;
Cc: Rik van Riel &lt;riel@redhat.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/sem.c: optimize sem_lock()</title>
<updated>2013-09-30T21:31:01Z</updated>
<author>
<name>Manfred Spraul</name>
<email>manfred@colorfullife.com</email>
</author>
<published>2013-09-30T20:45:06Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=6d07b68ce16ae9535955ba2059dedba5309c3ca1'/>
<id>urn:sha1:6d07b68ce16ae9535955ba2059dedba5309c3ca1</id>
<content type='text'>
Operations that need access to the whole array must guarantee that there
are no simple operations ongoing.  Right now this is achieved by
spin_unlock_wait(sem-&gt;lock) on all semaphores.

If complex_count is nonzero, then this spin_unlock_wait() is not
necessary, because it was already performed in the past by the thread
that increased complex_count and even though sem_perm.lock was dropped
inbetween, no simple operation could have started, because simple
operations cannot start when complex_count is non-zero.

Signed-off-by: Manfred Spraul &lt;manfred@colorfullife.com&gt;
Cc: Mike Galbraith &lt;bitbucket@online.de&gt;
Cc: Rik van Riel &lt;riel@redhat.com&gt;
Reviewed-by: Davidlohr Bueso &lt;davidlohr@hp.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>
</feed>
