1. 22 1月, 2016 3 次提交
    • I
      libceph: fix ceph_msg_revoke() · 67645d76
      Ilya Dryomov 提交于
      There are a number of problems with revoking a "was sending" message:
      
      (1) We never make any attempt to revoke data - only kvecs contibute to
      con->out_skip.  However, once the header (envelope) is written to the
      socket, our peer learns data_len and sets itself to expect at least
      data_len bytes to follow front or front+middle.  If ceph_msg_revoke()
      is called while the messenger is sending message's data portion,
      anything we send after that call is counted by the OSD towards the now
      revoked message's data portion.  The effects vary, the most common one
      is the eventual hang - higher layers get stuck waiting for the reply to
      the message that was sent out after ceph_msg_revoke() returned and
      treated by the OSD as a bunch of data bytes.  This is what Matt ran
      into.
      
      (2) Flat out zeroing con->out_kvec_bytes worth of bytes to handle kvecs
      is wrong.  If ceph_msg_revoke() is called before the tag is sent out or
      while the messenger is sending the header, we will get a connection
      reset, either due to a bad tag (0 is not a valid tag) or a bad header
      CRC, which kind of defeats the purpose of revoke.  Currently the kernel
      client refuses to work with header CRCs disabled, but that will likely
      change in the future, making this even worse.
      
      (3) con->out_skip is not reset on connection reset, leading to one or
      more spurious connection resets if we happen to get a real one between
      con->out_skip is set in ceph_msg_revoke() and before it's cleared in
      write_partial_skip().
      
      Fixing (1) and (3) is trivial.  The idea behind fixing (2) is to never
      zero the tag or the header, i.e. send out tag+header regardless of when
      ceph_msg_revoke() is called.  That way the header is always correct, no
      unnecessary resets are induced and revoke stands ready for disabled
      CRCs.  Since ceph_msg_revoke() rips out con->out_msg, introduce a new
      "message out temp" and copy the header into it before sending.
      
      Cc: stable@vger.kernel.org # 4.0+
      Reported-by: NMatt Conner <matt.conner@keepertech.com>
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      Tested-by: NMatt Conner <matt.conner@keepertech.com>
      Reviewed-by: NSage Weil <sage@redhat.com>
      67645d76
    • G
      libceph: use list_for_each_entry_safe · 10bcee14
      Geliang Tang 提交于
      Use list_for_each_entry_safe() instead of list_for_each_safe() to
      simplify the code.
      Signed-off-by: NGeliang Tang <geliangtang@163.com>
      [idryomov@gmail.com: nuke call to list_splice_init() as well]
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      10bcee14
    • G
      libceph: use list_next_entry instead of list_entry_next · 17ddc49b
      Geliang Tang 提交于
      list_next_entry has been defined in list.h, so I replace list_entry_next
      with it.
      Signed-off-by: NGeliang Tang <geliangtang@163.com>
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      17ddc49b
  2. 03 11月, 2015 5 次提交
    • I
      libceph: clear msg->con in ceph_msg_release() only · 583d0fef
      Ilya Dryomov 提交于
      The following bit in ceph_msg_revoke_incoming() is unsafe:
      
          struct ceph_connection *con = msg->con;
          if (!con)
                  return;
          mutex_lock(&con->mutex);
          <more msg->con use>
      
      There is nothing preventing con from getting destroyed right after
      msg->con test.  One easy way to reproduce this is to disable message
      signing only on the server side and try to map an image.  The system
      will go into a
      
          libceph: read_partial_message ffff880073f0ab68 signature check failed
          libceph: osd0 192.168.255.155:6801 bad crc/signature
          libceph: read_partial_message ffff880073f0ab68 signature check failed
          libceph: osd0 192.168.255.155:6801 bad crc/signature
      
      loop which has to be interrupted with Ctrl-C.  Hit Ctrl-C and you are
      likely to end up with a random GP fault if the reset handler executes
      "within" ceph_msg_revoke_incoming():
      
                           <yet another reply w/o a signature>
                                         ...
                <Ctrl-C>
          rbd_obj_request_end
            ceph_osdc_cancel_request
              __unregister_request
                ceph_osdc_put_request
                  ceph_msg_revoke_incoming
                                         ...
                                      osd_reset
                                        __kick_osd_requests
                                          __reset_osd
                                            remove_osd
                                              ceph_con_close
                                                reset_connection
                                                  <clear con->in_msg->con>
                                                  <put con ref>
                                                    put_osd
                                                      <free osd/con>
                    <msg->con use> <-- !!!
      
      If ceph_msg_revoke_incoming() executes "before" the reset handler,
      osd/con will be leaked because ceph_msg_revoke_incoming() clears
      con->in_msg but doesn't put con ref, while reset_connection() only puts
      con ref if con->in_msg != NULL.
      
      The current msg->con scheme was introduced by commits 38941f80
      ("libceph: have messages point to their connection") and 92ce034b
      ("libceph: have messages take a connection reference"), which defined
      when messages get associated with a connection and when that
      association goes away.  Part of the problem is that this association is
      supposed to go away in much too many places; closing this race entirely
      requires either a rework of the existing or an addition of a new layer
      of synchronization.
      
      In lieu of that, we can make it *much* less likely to hit by
      disassociating messages only on their destruction and resend through
      a different connection.  This makes the code simpler and is probably
      a good thing to do regardless - this patch adds a msg_con_set() helper
      which is is called from only three places: ceph_con_send() and
      ceph_con_in_msg_alloc() to set msg->con and ceph_msg_release() to clear
      it.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      583d0fef
    • I
      libceph: add nocephx_sign_messages option · a51983e4
      Ilya Dryomov 提交于
      Support for message signing was merged into 3.19, along with
      nocephx_require_signatures option.  But, all that option does is allow
      the kernel client to talk to clusters that don't support MSG_AUTH
      feature bit.  That's pretty useless, given that it's been supported
      since bobtail.
      
      Meanwhile, if one disables message signing on the server side with
      "cephx sign messages = false", it becomes impossible to use the kernel
      client since it expects messages to be signed if MSG_AUTH was
      negotiated.  Add nocephx_sign_messages option to support this use case.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      a51983e4
    • I
      libceph: stop duplicating client fields in messenger · 859bff51
      Ilya Dryomov 提交于
      supported_features and required_features serve no purpose at all, while
      nocrc and tcp_nodelay belong to ceph_options::flags.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      859bff51
    • I
      libceph: msg signing callouts don't need con argument · 79dbd1ba
      Ilya Dryomov 提交于
      We can use msg->con instead - at the point we sign an outgoing message
      or check the signature on the incoming one, msg->con is always set.  We
      wouldn't know how to sign a message without an associated session (i.e.
      msg->con == NULL) and being able to sign a message using an explicitly
      provided authorizer is of no use.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      79dbd1ba
    • S
      libceph: use local variable cursor instead of &msg->cursor · 343128ce
      Shraddha Barke 提交于
      Use local variable cursor in place of &msg->cursor in
      read_partial_msg_data() and write_partial_msg_data().
      Signed-off-by: NShraddha Barke <shraddha.6596@gmail.com>
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      343128ce
  3. 18 9月, 2015 1 次提交
  4. 09 9月, 2015 4 次提交
  5. 10 7月, 2015 2 次提交
    • I
      libceph: treat sockaddr_storage with uninitialized family as blank · c44bd69c
      Ilya Dryomov 提交于
      addr_is_blank() should return true if family is neither AF_INET nor
      AF_INET6.  This is what its counterpart entity_addr_t::is_blank_ip() is
      doing and it is the right thing to do: in process_banner() we check if
      our address is blank and if it is "learn" it from our peer.  As it is,
      we never learn our address and always send out a blank one.  This goes
      way back to ceph.git commit dd732cbfc1c9 ("use sockaddr_storage; and
      some ipv6 support groundwork") from 2009.
      
      While at at, do not open-code ipv6_addr_any() and use INADDR_ANY
      constant instead of 0.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      Reviewed-by: NSage Weil <sage@redhat.com>
      c44bd69c
    • I
      libceph: enable ceph in a non-default network namespace · 757856d2
      Ilya Dryomov 提交于
      Grab a reference on a network namespace of the 'rbd map' (in case of
      rbd) or 'mount' (in case of ceph) process and use that to open sockets
      instead of always using init_net and bailing if network namespace is
      anything but init_net.  Be careful to not share struct ceph_client
      instances between different namespaces and don't add any code in the
      !CONFIG_NET_NS case.
      
      This is based on a patch from Hong Zhiguo <zhiguohong@tencent.com>.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      Reviewed-by: NSage Weil <sage@redhat.com>
      757856d2
  6. 30 6月, 2015 1 次提交
  7. 25 6月, 2015 1 次提交
  8. 11 5月, 2015 1 次提交
  9. 20 4月, 2015 1 次提交
    • I
      libceph: don't overwrite specific con error msgs · 67c64eb7
      Ilya Dryomov 提交于
      - specific con->error_msg messages (e.g. "protocol version mismatch")
        end up getting overwritten by a catch-all "socket error on read
        / write", introduced in commit 3a140a0d ("libceph: report socket
        read/write error message")
      - "bad message sequence # for incoming message" loses to "bad crc" due
        to the fact that -EBADMSG is used for both
      
      Fix it, and tidy up con->error_msg assignments and pr_errs while at it.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      67c64eb7
  10. 08 4月, 2015 1 次提交
    • I
      Revert "libceph: use memalloc flags for net IO" · 6d7fdb0a
      Ilya Dryomov 提交于
      This reverts commit 89baaa57.
      
      Dirty page throttling should be sufficient for us in the general case
      so there is no need to use __GFP_MEMALLOC - it would be needed only in
      the swap-over-rbd case, which we currently don't support.  (It would
      probably take approximately the commit that is being reverted to add
      that support, but we would also need the "swap" option to distinguish
      from the general case and make sure swap ceph_client-s aren't shared
      with anything else.)  See ceph-devel threads [1] and [2] for the
      details of why enabling pfmemalloc reserves for all cases is a bad
      thing.
      
      On top of potential system lockups related to drained emergency
      reserves, this turned out to cause ceph lockups in case peers are on
      the same host and communicating via loopback due to sk_filter()
      dropping pfmemalloc skbs on the receiving side because the receiving
      loopback socket is not tagged with SOCK_MEMALLOC.
      
      [1] "SOCK_MEMALLOC vs loopback"
          http://www.spinics.net/lists/ceph-devel/msg22998.html
      [2] "[PATCH] libceph: don't set memalloc flags in loopback case"
          http://www.spinics.net/lists/ceph-devel/msg23392.html
      
      Conflicts:
      	net/ceph/messenger.c [ context: tcp_nodelay option ]
      
      Cc: Mike Christie <michaelc@cs.wisc.edu>
      Cc: Mel Gorman <mgorman@suse.de>
      Cc: Sage Weil <sage@redhat.com>
      Cc: stable@vger.kernel.org # 3.18+, needs backporting
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      Acked-by: NMike Christie <michaelc@cs.wisc.edu>
      Acked-by: NMel Gorman <mgorman@suse.de>
      6d7fdb0a
  11. 19 2月, 2015 1 次提交
  12. 18 12月, 2014 2 次提交
  13. 30 10月, 2014 1 次提交
    • M
      libceph: use memalloc flags for net IO · 89baaa57
      Mike Christie 提交于
      This patch has ceph's lib code use the memalloc flags.
      
      If the VM layer needs to write data out to free up memory to handle new
      allocation requests, the block layer must be able to make forward progress.
      To handle that requirement we use structs like mempools to reserve memory for
      objects like bios and requests.
      
      The problem is when we send/receive block layer requests over the network
      layer, net skb allocations can fail and the system can lock up.
      To solve this, the memalloc related flags were added. NBD, iSCSI
      and NFS uses these flags to tell the network/vm layer that it should
      use memory reserves to fullfill allcation requests for structs like
      skbs.
      
      I am running ceph in a bunch of VMs in my laptop, so this patch was
      not tested very harshly.
      Signed-off-by: NMike Christie <michaelc@cs.wisc.edu>
      Reviewed-by: NIlya Dryomov <idryomov@redhat.com>
      89baaa57
  14. 15 10月, 2014 3 次提交
  15. 09 8月, 2014 1 次提交
    • I
      libceph: set last_piece in ceph_msg_data_pages_cursor_init() correctly · 5f740d7e
      Ilya Dryomov 提交于
      Determining ->last_piece based on the value of ->page_offset + length
      is incorrect because length here is the length of the entire message.
      ->last_piece set to false even if page array data item length is <=
      PAGE_SIZE, which results in invalid length passed to
      ceph_tcp_{send,recv}page() and causes various asserts to fire.
      
          # cat pages-cursor-init.sh
          #!/bin/bash
          rbd create --size 10 --image-format 2 foo
          FOO_DEV=$(rbd map foo)
          dd if=/dev/urandom of=$FOO_DEV bs=1M &>/dev/null
          rbd snap create foo@snap
          rbd snap protect foo@snap
          rbd clone foo@snap bar
          # rbd_resize calls librbd rbd_resize(), size is in bytes
          ./rbd_resize bar $(((4 << 20) + 512))
          rbd resize --size 10 bar
          BAR_DEV=$(rbd map bar)
          # trigger a 512-byte copyup -- 512-byte page array data item
          dd if=/dev/urandom of=$BAR_DEV bs=1M count=1 seek=5
      
      The problem exists only in ceph_msg_data_pages_cursor_init(),
      ceph_msg_data_pages_advance() does the right thing.  The size_t cast is
      unnecessary.
      
      Cc: stable@vger.kernel.org # 3.10+
      Signed-off-by: NIlya Dryomov <ilya.dryomov@inktank.com>
      Reviewed-by: NSage Weil <sage@redhat.com>
      Reviewed-by: NAlex Elder <elder@linaro.org>
      5f740d7e
  16. 08 7月, 2014 2 次提交
  17. 17 5月, 2014 1 次提交
  18. 12 4月, 2014 1 次提交
    • D
      net: Fix use after free by removing length arg from sk_data_ready callbacks. · 676d2369
      David S. Miller 提交于
      Several spots in the kernel perform a sequence like:
      
      	skb_queue_tail(&sk->s_receive_queue, skb);
      	sk->sk_data_ready(sk, skb->len);
      
      But at the moment we place the SKB onto the socket receive queue it
      can be consumed and freed up.  So this skb->len access is potentially
      to freed up memory.
      
      Furthermore, the skb->len can be modified by the consumer so it is
      possible that the value isn't accurate.
      
      And finally, no actual implementation of this callback actually uses
      the length argument.  And since nobody actually cared about it's
      value, lots of call sites pass arbitrary values in such as '0' and
      even '1'.
      
      So just remove the length argument from the callback, that way there
      is no confusion whatsoever and all of these use-after-free cases get
      fixed as a side effect.
      
      Based upon a patch by Eric Dumazet and his suggestion to audit this
      issue tree-wide.
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      676d2369
  19. 05 4月, 2014 1 次提交
  20. 08 2月, 2014 1 次提交
  21. 26 1月, 2014 1 次提交
    • I
      libceph: add ceph_kv{malloc,free}() and switch to them · eeb0bed5
      Ilya Dryomov 提交于
      Encapsulate kmalloc vs vmalloc memory allocation and freeing logic into
      two helpers, ceph_kvmalloc() and ceph_kvfree(), and switch to them.
      
      ceph_kvmalloc() kmalloc()'s a maximum of 8 pages, anything bigger is
      vmalloc()'ed with __GFP_HIGHMEM set.  This changes the existing
      behaviour:
      
      - for buffers (ceph_buffer_new()), from trying to kmalloc() everything
        and using vmalloc() just as a fallback
      
      - for messages (ceph_msg_new()), from going to vmalloc() for anything
        bigger than a page
      
      - for messages (ceph_msg_new()), from disallowing vmalloc() to use high
        memory
      Signed-off-by: NIlya Dryomov <ilya.dryomov@inktank.com>
      Reviewed-by: NSage Weil <sage@inktank.com>
      eeb0bed5
  22. 14 1月, 2014 2 次提交
  23. 01 1月, 2014 3 次提交