1. 11 Jan, 2013 3 commits
    • Chuansheng Liu's avatar
      firmware loader: Fix the concurrent request_firmware() race for kref_get/put · 235db1e9
      Chuansheng Liu authored
      commit bd9eb7fb upstream.
      
      There is one race that both request_firmware() with the same
      firmware name.
      
      The race scenerio is as below:
      CPU1                                                  CPU2
      request_firmware() -->
      _request_firmware_load() return err                   another request_firmware() is coming -->
      _request_firmware_cleanup is called -->               _request_firmware_prepare -->
      release_firmware --->                                 fw_lookup_and_allocate_buf -->
                                                            spin_lock(&fwc->lock)
      ...                                                   __fw_lookup_buf() return true
      fw_free_buf() will be called -->                      ...
      kref_put -->
      decrease the refcount to 0
                                                            kref_get(&tmp->ref) ==> it will trigger warning
                                                                                    due to refcount == 0
      __fw_free_buf() -->
      ...                                                   spin_unlock(&fwc->lock)
      spin_lock(&fwc->lock)
      list_del(&buf->list)
      spin_unlock(&fwc->lock)
      kfree(buf)
                                                            After that, the freed buf will be used.
      
      The key race is decreasing refcount to 0 and list_del is not protected together by
      fwc->lock, and it is possible another thread try to get it between refcount==0
      and list_del.
      
      Fix it here to protect it together.
      Acked-by: default avatarMing Lei <ming.lei@canonical.com>
      Signed-off-by: default avatarliu chuansheng <chuansheng.liu@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      235db1e9
    • Chuansheng Liu's avatar
      firmware loader: Fix the race FW_STATUS_DONE is followed by class_timeout · 42b5489a
      Chuansheng Liu authored
      commit ce2fcbd9 upstream.
      
      There is a race as below when calling request_firmware():
      CPU1                                   CPU2
      write 0 > loading
      mutex_lock(&fw_lock)
      ...
      set_bit FW_STATUS_DONE                 class_timeout is coming
                                             set_bit FW_STATUS_ABORT
      complete_all &completion
      ...
      mutex_unlock(&fw_lock)
      
      In this time, the bit FW_STATUS_DONE and FW_STATUS_ABORT are set,
      and request_firmware() will return failure due to condition in
      _request_firmware_load():
      	if (!buf->size || test_bit(FW_STATUS_ABORT, &buf->status))
      		retval = -ENOENT;
      
      But from the above scenerio, it should be a successful requesting.
      So we need judge if the bit FW_STATUS_DONE is already set before
      calling fw_load_abort() in timeout function.
      
      As Ming's proposal, we need change the timer into sched_work to
      benefit from using &fw_lock mutex also.
      Signed-off-by: default avatarliu chuansheng <chuansheng.liu@intel.com>
      Acked-by: default avatarMing Lei <ming.lei@canonical.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      42b5489a
    • Eric Dumazet's avatar
      net: fix a race in gro_cell_poll() · e66e367b
      Eric Dumazet authored
      [ Upstream commit f8e8f97c ]
      
      Dmitry Kravkov reported packet drops for GRE packets since GRO support
      was added.
      
      There is a race in gro_cell_poll() because we call napi_complete()
      without any synchronization with a concurrent gro_cells_receive()
      
      Once bug was triggered, we queued packets but did not schedule NAPI
      poll.
      
      We can fix this issue using the spinlock protected the napi_skbs queue,
      as we have to hold it to perform skb dequeue anyway.
      
      As we open-code skb_dequeue(), we no longer need to mask IRQS, as both
      producer and consumer run under BH context.
      
      Bug added in commit c9e6bc64 (net: add gro_cells infrastructure)
      Reported-by: default avatarDmitry Kravkov <dmitry@broadcom.com>
      Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
      Tested-by: default avatarDmitry Kravkov <dmitry@broadcom.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e66e367b
  2. 17 Dec, 2012 28 commits
  3. 11 Dec, 2012 3 commits
    • Linus Torvalds's avatar
      Linux 3.7 · 29594404
      Linus Torvalds authored
      29594404
    • Florian Fainelli's avatar
      Input: matrix-keymap - provide proper module license · 55220bb3
      Florian Fainelli authored
      The matrix-keymap module is currently lacking a proper module license,
      add one so we don't have this module tainting the entire kernel.  This
      issue has been present since commit 1932811f ("Input: matrix-keymap
      - uninline and prepare for device tree support")
      Signed-off-by: default avatarFlorian Fainelli <florian@openwrt.org>
      CC: stable@vger.kernel.org # v3.5+
      Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      55220bb3
    • Linus Torvalds's avatar
      Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net · 2c68bc72
      Linus Torvalds authored
      Pull networking fixes from David Miller:
      
       1) Netlink socket dumping had several missing verifications and checks.
      
          In particular, address comparisons in the request byte code
          interpreter could access past the end of the address in the
          inet_request_sock.
      
          Also, address family and address prefix lengths were not validated
          properly at all.
      
          This means arbitrary applications can read past the end of certain
          kernel data structures.
      
          Fixes from Neal Cardwell.
      
       2) ip_check_defrag() operates in contexts where we're in the process
          of, or about to, input the packet into the real protocols
          (specifically macvlan and AF_PACKET snooping).
      
          Unfortunately, it does a pskb_may_pull() which can modify the
          backing packet data which is not legal if the SKB is shared.  It
          very much can be shared in this context.
      
          Deal with the possibility that the SKB is segmented by using
          skb_copy_bits().
      
          Fix from Johannes Berg based upon a report by Eric Leblond.
      
      * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net:
        ipv4: ip_check_defrag must not modify skb before unsharing
        inet_diag: validate port comparison byte code to prevent unsafe reads
        inet_diag: avoid unsafe and nonsensical prefix matches in inet_diag_bc_run()
        inet_diag: validate byte code to prevent oops in inet_diag_bc_run()
        inet_diag: fix oops for IPv4 AF_INET6 TCP SYN-RECV state
      2c68bc72
  4. 10 Dec, 2012 4 commits
    • Linus Torvalds's avatar
      Revert "revert "Revert "mm: remove __GFP_NO_KSWAPD""" and associated damage · caf49191
      Linus Torvalds authored
      This reverts commits a5091539 and
      d7c3b937.
      
      This is a revert of a revert of a revert.  In addition, it reverts the
      even older i915 change to stop using the __GFP_NO_KSWAPD flag due to the
      original commits in linux-next.
      
      It turns out that the original patch really was bogus, and that the
      original revert was the correct thing to do after all.  We thought we
      had fixed the problem, and then reverted the revert, but the problem
      really is fundamental: waking up kswapd simply isn't the right thing to
      do, and direct reclaim sometimes simply _is_ the right thing to do.
      
      When certain allocations fail, we simply should try some direct reclaim,
      and if that fails, fail the allocation.  That's the right thing to do
      for THP allocations, which can easily fail, and the GPU allocations want
      to do that too.
      
      So starting kswapd is sometimes simply wrong, and removing the flag that
      said "don't start kswapd" was a mistake.  Let's hope we never revisit
      this mistake again - and certainly not this many times ;)
      Acked-by: default avatarMel Gorman <mgorman@suse.de>
      Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Cc: Rik van Riel <riel@redhat.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      caf49191
    • Johannes Berg's avatar
      ipv4: ip_check_defrag must not modify skb before unsharing · 1bf3751e
      Johannes Berg authored
      ip_check_defrag() might be called from af_packet within the
      RX path where shared SKBs are used, so it must not modify
      the input SKB before it has unshared it for defragmentation.
      Use skb_copy_bits() to get the IP header and only pull in
      everything later.
      
      The same is true for the other caller in macvlan as it is
      called from dev->rx_handler which can also get a shared SKB.
      Reported-by: default avatarEric Leblond <eric@regit.org>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      1bf3751e
    • Linus Torvalds's avatar
      Revert "mm: avoid waking kswapd for THP allocations when compaction is deferred or contended" · 31f8d42d
      Linus Torvalds authored
      This reverts commit 782fd304.
      
      We are going to reinstate the __GFP_NO_KSWAPD flag that has been
      removed, the removal reverted, and then removed again.  Making this
      commit a pointless fixup for a problem that was caused by the removal of
      __GFP_NO_KSWAPD flag.
      
      The thing is, we really don't want to wake up kswapd for THP allocations
      (because they fail quite commonly under any kind of memory pressure,
      including when there is tons of memory free), and these patches were
      just trying to fix up the underlying bug: the original removal of
      __GFP_NO_KSWAPD in commit c6543459 ("mm: remove __GFP_NO_KSWAPD")
      was simply bogus.
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      31f8d42d
    • Neal Cardwell's avatar
      inet_diag: validate port comparison byte code to prevent unsafe reads · 5e1f5420
      Neal Cardwell authored
      Add logic to verify that a port comparison byte code operation
      actually has the second inet_diag_bc_op from which we read the port
      for such operations.
      
      Previously the code blindly referenced op[1] without first checking
      whether a second inet_diag_bc_op struct could fit there. So a
      malicious user could make the kernel read 4 bytes beyond the end of
      the bytecode array by claiming to have a whole port comparison byte
      code (2 inet_diag_bc_op structs) when in fact the bytecode was not
      long enough to hold both.
      Signed-off-by: default avatarNeal Cardwell <ncardwell@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      5e1f5420
  5. 09 Dec, 2012 2 commits
    • Neal Cardwell's avatar
      inet_diag: avoid unsafe and nonsensical prefix matches in inet_diag_bc_run() · f67caec9
      Neal Cardwell authored
      Add logic to check the address family of the user-supplied conditional
      and the address family of the connection entry. We now do not do
      prefix matching of addresses from different address families (AF_INET
      vs AF_INET6), except for the previously existing support for having an
      IPv4 prefix match an IPv4-mapped IPv6 address (which this commit
      maintains as-is).
      
      This change is needed for two reasons:
      
      (1) The addresses are different lengths, so comparing a 128-bit IPv6
      prefix match condition to a 32-bit IPv4 connection address can cause
      us to unwittingly walk off the end of the IPv4 address and read
      garbage or oops.
      
      (2) The IPv4 and IPv6 address spaces are semantically distinct, so a
      simple bit-wise comparison of the prefixes is not meaningful, and
      would lead to bogus results (except for the IPv4-mapped IPv6 case,
      which this commit maintains).
      Signed-off-by: default avatarNeal Cardwell <ncardwell@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      f67caec9
    • Neal Cardwell's avatar
      inet_diag: validate byte code to prevent oops in inet_diag_bc_run() · 405c0059
      Neal Cardwell authored
      Add logic to validate INET_DIAG_BC_S_COND and INET_DIAG_BC_D_COND
      operations.
      
      Previously we did not validate the inet_diag_hostcond, address family,
      address length, and prefix length. So a malicious user could make the
      kernel read beyond the end of the bytecode array by claiming to have a
      whole inet_diag_hostcond when the bytecode was not long enough to
      contain a whole inet_diag_hostcond of the given address family. Or
      they could make the kernel read up to about 27 bytes beyond the end of
      a connection address by passing a prefix length that exceeded the
      length of addresses of the given family.
      Signed-off-by: default avatarNeal Cardwell <ncardwell@google.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      405c0059