1. 13 11月, 2013 1 次提交
    • M
      ipc, msg: fix message length check for negative values · 4e9b45a1
      Mathias Krause 提交于
      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 <sys/stat.h>
        | #include <sys/msg.h>
        | #include <unistd.h>
        | #include <fcntl.h>
        |
        | int main(void) {
        |     long msg = 1;
        |     int fd;
        |
        |     fd = open("/proc/sys/kernel/msgmax", O_WRONLY);
        |     write(fd, "-1", 2);
        |     close(fd);
        |
        |     msgsnd(0, &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: NMathias Krause <minipli@googlemail.com>
      Cc: Pax Team <pageexec@freemail.hu>
      Cc: Davidlohr Bueso <davidlohr@hp.com>
      Cc: Brad Spengler <spender@grsecurity.net>
      Cc: Manfred Spraul <manfred@colorfullife.com>
      Cc: <stable@vger.kernel.org>	[ v2.3.27+ -- yes, that old ;) ]
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      4e9b45a1
  2. 05 1月, 2013 2 次提交
  3. 13 10月, 2012 1 次提交
  4. 07 6月, 2008 1 次提交
  5. 29 4月, 2008 1 次提交
    • N
      ipc: scale msgmni to the amount of lowmem · f7bf3df8
      Nadia Derbey 提交于
      On large systems we'd like to allow a larger number of message queues.  In
      some cases up to 32K.  However simply setting MSGMNI to a larger value may
      cause problems for smaller systems.
      
      The first patch of this series introduces a default maximum number of message
      queue ids that scales with the amount of lowmem.
      
      Since msgmni is per namespace and there is no amount of memory dedicated to
      each namespace so far, the second patch of this series scales msgmni to the
      number of ipc namespaces too.
      
      Since msgmni depends on the amount of memory, it becomes necessary to
      recompute it upon memory add/remove.  In the 4th patch, memory hotplug
      management is added: a notifier block is registered into the memory hotplug
      notifier chain for the ipc subsystem.  Since the ipc namespaces are not linked
      together, they have their own notification chain: one notifier_block is
      defined per ipc namespace.  Each time an ipc namespace is created (removed) it
      registers (unregisters) its notifier block in (from) the ipcns chain.  The
      callback routine registered in the memory chain invokes the ipcns notifier
      chain with the IPCNS_MEMCHANGE event.  Each callback routine registered in the
      ipcns namespace, in turn, recomputes msgmni for the owning namespace.
      
      The 5th patch makes it possible to keep the memory hotplug notifier chain's
      lock for a lesser amount of time: instead of directly notifying the ipcns
      notifier chain upon memory add/remove, a work item is added to the global
      workqueue.  When activated, this work item is the one who notifies the ipcns
      notifier chain.
      
      Since msgmni depends on the number of ipc namespaces, it becomes necessary to
      recompute it upon ipc namespace creation / removal.  The 6th patch uses the
      ipc namespace notifier chain for that purpose: that chain is notified each
      time an ipc namespace is created or removed.  This makes it possible to
      recompute msgmni for all the namespaces each time one of them is created or
      removed.
      
      When msgmni is explicitely set from userspace, we should avoid recomputing it
      upon memory add/remove or ipcns creation/removal.  This is what the 7th patch
      does: it simply unregisters the ipcns callback routine as soon as msgmni has
      been changed from procfs or sysctl().
      
      Even if msgmni is set by hand, it should be possible to make it back
      automatically recomputed upon memory add/remove or ipcns creation/removal.
      This what is achieved in patch 8: if set to a negative value, msgmni is added
      back to the ipcns notifier chain, making it automatically recomputed again.
      
      This patch:
      
      Compute msg_ctlmni to make it scale with the amount of lowmem.  msg_ctlmni is
      now set to make the message queues occupy 1/32 of the available lowmem.
      
      Some cleaning has also been done for the MSGPOOL constant: the msgctl man page
      says it's not used, but it also defines it as a size in bytes (the code
      expresses it in Kbytes).
      Signed-off-by: NNadia Derbey <Nadia.Derbey@bull.net>
      Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
      Cc: Matt Helsley <matthltc@us.ibm.com>
      Cc: Mingming Cao <cmm@us.ibm.com>
      Cc: Pierre Peiffer <pierre.peiffer@bull.net>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      f7bf3df8
  6. 20 10月, 2007 1 次提交
    • N
      ipc: store ipcs into IDRs · 7ca7e564
      Nadia Derbey 提交于
      This patch introduces ipcs storage into IDRs. The main changes are:
        . This ipc_ids structure is changed: the entries array is changed into a
          root idr structure.
        . The grow_ary() routine is removed: it is not needed anymore when adding
          an ipc structure, since we are now using the IDR facility.
        . The ipc_rmid() routine interface is changed:
             . there is no need for this routine to return the pointer passed in as
               argument: it is now declared as a void
             . since the id is now part of the kern_ipc_perm structure, no need to
               have it as an argument to the routine
      Signed-off-by: NNadia Derbey <Nadia.Derbey@bull.net>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      7ca7e564
  7. 08 12月, 2006 1 次提交
    • S
      [PATCH] Fix the size limit of compat space msgsize · 651971cb
      suzuki 提交于
      Currently we allocate 64k space on the user stack and use it the msgbuf for
      sys_{msgrcv,msgsnd} for compat and the results are later copied in user [
      by copy_in_user].  This patch introduces helper routines for
      sys_{msgrcv,msgsnd} as below:
      
      do_msgsnd() : Accepts the mtype and user space ptr to the buffer along with
      the msqid and msgflg.
      
      do_msgrcv() : Accepts a kernel space ptr to mtype and a userspace ptr to
      the buffer.  The mtype has to be copied back the user space msgbuf by the
      caller.
      
      These changes avoid the need to allocate the msgsize on the userspace (
      thus removing the size limt ) and the overhead of an extra copy_in_user().
      Signed-off-by: NSuzuki K P <suzuki@in.ibm.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: "David S. Miller" <davem@davemloft.net>
      Signed-off-by: NAndrew Morton <akpm@osdl.org>
      Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
      651971cb
  8. 25 4月, 2006 1 次提交
  9. 08 9月, 2005 1 次提交
  10. 17 4月, 2005 1 次提交
    • L
      Linux-2.6.12-rc2 · 1da177e4
      Linus Torvalds 提交于
      Initial git repository build. I'm not bothering with the full history,
      even though we have it. We can create a separate "historical" git
      archive of that later if we want to, and in the meantime it's about
      3.2GB when imported into git - space that would just make the early
      git days unnecessarily complicated, when we don't have a lot of good
      infrastructure for it.
      
      Let it rip!
      1da177e4