1. 31 10月, 2020 3 次提交
  2. 30 10月, 2020 2 次提交
    • J
      tipc: add stricter control of reserved service types · 72671b35
      Jon Maloy 提交于
      TIPC reserves 64 service types for current and future internal use.
      Therefore, the bind() function is meant to block regular user sockets
      from being bound to these values, while it should let through such
      bindings from internal users.
      
      However, since we at the design moment saw no way to distinguish
      between regular and internal users the filter function ended up
      with allowing all bindings of the reserved types which were really
      in use ([0,1]), and block all the rest ([2,63]).
      
      This is risky, since a regular user may bind to the service type
      representing the topology server (TIPC_TOP_SRV == 1) or the one used
      for indicating neighboring node status (TIPC_CFG_SRV == 0), and wreak
      havoc for users of those services, i.e., most users.
      
      The reality is however that TIPC_CFG_SRV never is bound through the
      bind() function, since it doesn't represent a regular socket, and
      TIPC_TOP_SRV can also be made to bypass the checks in tipc_bind()
      by introducing a different entry function, tipc_sk_bind().
      
      It should be noted that although this is a change of the API semantics,
      there is no risk we will break any currently working applications by
      doing this. Any application trying to bind to the values in question
      would be badly broken from the outset, so there is no chance we would
      find any such applications in real-world production systems.
      
      v2: Added warning printout when a user is blocked from binding,
          as suggested by Jakub Kicinski
      Acked-by: NYung Xue <ying.xue@windriver.com>
      Signed-off-by: NJon Maloy <jmaloy@redhat.com>
      Link: https://lore.kernel.org/r/20201030012938.489557-1-jmaloy@redhat.comSigned-off-by: NJakub Kicinski <kuba@kernel.org>
      72671b35
    • T
      tipc: fix memory leak caused by tipc_buf_append() · ceb1eb2f
      Tung Nguyen 提交于
      Commit ed42989e ("tipc: fix the skb_unshare() in tipc_buf_append()")
      replaced skb_unshare() with skb_copy() to not reduce the data reference
      counter of the original skb intentionally. This is not the correct
      way to handle the cloned skb because it causes memory leak in 2
      following cases:
       1/ Sending multicast messages via broadcast link
        The original skb list is cloned to the local skb list for local
        destination. After that, the data reference counter of each skb
        in the original list has the value of 2. This causes each skb not
        to be freed after receiving ACK:
        tipc_link_advance_transmq()
        {
         ...
         /* release skb */
         __skb_unlink(skb, &l->transmq);
         kfree_skb(skb); <-- memory exists after being freed
        }
      
       2/ Sending multicast messages via replicast link
        Similar to the above case, each skb cannot be freed after purging
        the skb list:
        tipc_mcast_xmit()
        {
         ...
         __skb_queue_purge(pkts); <-- memory exists after being freed
        }
      
      This commit fixes this issue by using skb_unshare() instead. Besides,
      to avoid use-after-free error reported by KASAN, the pointer to the
      fragment is set to NULL before calling skb_unshare() to make sure that
      the original skb is not freed after freeing the fragment 2 times in
      case skb_unshare() returns NULL.
      
      Fixes: ed42989e ("tipc: fix the skb_unshare() in tipc_buf_append()")
      Acked-by: NJon Maloy <jmaloy@redhat.com>
      Reported-by: NThang Hoang Ngo <thang.h.ngo@dektech.com.au>
      Signed-off-by: NTung Nguyen <tung.q.nguyen@dektech.com.au>
      Reviewed-by: NXin Long <lucien.xin@gmail.com>
      Acked-by: NCong Wang <xiyou.wangcong@gmail.com>
      Link: https://lore.kernel.org/r/20201027032403.1823-1-tung.q.nguyen@dektech.com.auSigned-off-by: NJakub Kicinski <kuba@kernel.org>
      ceb1eb2f
  3. 26 10月, 2020 1 次提交
  4. 17 10月, 2020 2 次提交
  5. 10 10月, 2020 2 次提交
    • H
      tipc: fix NULL pointer dereference in tipc_named_rcv · 7b50ee3d
      Hoang Huu Le 提交于
      In the function node_lost_contact(), we call __skb_queue_purge() without
      grabbing the list->lock. This can cause to a race-condition why processing
      the list 'namedq' in calling path tipc_named_rcv()->tipc_named_dequeue().
      
          [] BUG: kernel NULL pointer dereference, address: 0000000000000000
          [] #PF: supervisor read access in kernel mode
          [] #PF: error_code(0x0000) - not-present page
          [] PGD 7ca63067 P4D 7ca63067 PUD 6c553067 PMD 0
          [] Oops: 0000 [#1] SMP NOPTI
          [] CPU: 1 PID: 15 Comm: ksoftirqd/1 Tainted: G  O  5.9.0-rc6+ #2
          [] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS [...]
          [] RIP: 0010:tipc_named_rcv+0x103/0x320 [tipc]
          [] Code: 41 89 44 24 10 49 8b 16 49 8b 46 08 49 c7 06 00 00 00 [...]
          [] RSP: 0018:ffffc900000a7c58 EFLAGS: 00000282
          [] RAX: 00000000000012ec RBX: 0000000000000000 RCX: ffff88807bde1270
          [] RDX: 0000000000002c7c RSI: 0000000000002c7c RDI: ffff88807b38f1a8
          [] RBP: ffff88807b006288 R08: ffff88806a367800 R09: ffff88806a367900
          [] R10: ffff88806a367a00 R11: ffff88806a367b00 R12: ffff88807b006258
          [] R13: ffff88807b00628a R14: ffff888069334d00 R15: ffff88806a434600
          [] FS:  0000000000000000(0000) GS:ffff888079480000(0000) knlGS:0[...]
          [] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
          [] CR2: 0000000000000000 CR3: 0000000077320000 CR4: 00000000000006e0
          [] Call Trace:
          []  ? tipc_bcast_rcv+0x9a/0x1a0 [tipc]
          []  tipc_rcv+0x40d/0x670 [tipc]
          []  ? _raw_spin_unlock+0xa/0x20
          []  tipc_l2_rcv_msg+0x55/0x80 [tipc]
          []  __netif_receive_skb_one_core+0x8c/0xa0
          []  process_backlog+0x98/0x140
          []  net_rx_action+0x13a/0x420
          []  __do_softirq+0xdb/0x316
          []  ? smpboot_thread_fn+0x2f/0x1e0
          []  ? smpboot_thread_fn+0x74/0x1e0
          []  ? smpboot_thread_fn+0x14e/0x1e0
          []  run_ksoftirqd+0x1a/0x40
          []  smpboot_thread_fn+0x149/0x1e0
          []  ? sort_range+0x20/0x20
          []  kthread+0x131/0x150
          []  ? kthread_unuse_mm+0xa0/0xa0
          []  ret_from_fork+0x22/0x30
          [] Modules linked in: veth tipc(O) ip6_udp_tunnel udp_tunnel [...]
          [] CR2: 0000000000000000
          [] ---[ end trace 65c276a8e2e2f310 ]---
      
      To fix this, we need to grab the lock of the 'namedq' list on both
      path calling.
      
      Fixes: cad2929d ("tipc: update a binding service via broadcast")
      Acked-by: NJon Maloy <jmaloy@redhat.com>
      Signed-off-by: NHoang Huu Le <hoang.h.le@dektech.com.au>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      7b50ee3d
    • C
      tipc: fix the skb_unshare() in tipc_buf_append() · ed42989e
      Cong Wang 提交于
      skb_unshare() drops a reference count on the old skb unconditionally,
      so in the failure case, we end up freeing the skb twice here.
      And because the skb is allocated in fclone and cloned by caller
      tipc_msg_reassemble(), the consequence is actually freeing the
      original skb too, thus triggered the UAF by syzbot.
      
      Fix this by replacing this skb_unshare() with skb_cloned()+skb_copy().
      
      Fixes: ff48b622 ("tipc: use skb_unshare() instead in tipc_buf_append()")
      Reported-and-tested-by: syzbot+e96a7ba46281824cc46a@syzkaller.appspotmail.com
      Cc: Jon Maloy <jmaloy@redhat.com>
      Cc: Ying Xue <ying.xue@windriver.com>
      Signed-off-by: NCong Wang <xiyou.wangcong@gmail.com>
      Reviewed-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      ed42989e
  6. 03 10月, 2020 1 次提交
  7. 19 9月, 2020 7 次提交
    • W
      net: tipc: Supply missing udp_media.h include file · 5f3666e8
      Wang Hai 提交于
      If the header file containing a function's prototype isn't included by
      the sourcefile containing the associated function, the build system
      complains of missing prototypes.
      
      Fixes the following W=1 kernel build warning(s):
      
      net/tipc/udp_media.c:446:5: warning: no previous prototype for ‘tipc_udp_nl_dump_remoteip’ [-Wmissing-prototypes]
      net/tipc/udp_media.c:532:5: warning: no previous prototype for ‘tipc_udp_nl_add_bearer_data’ [-Wmissing-prototypes]
      net/tipc/udp_media.c:614:5: warning: no previous prototype for ‘tipc_udp_nl_bearer_add’ [-Wmissing-prototypes]
      Signed-off-by: NWang Hai <wanghai38@huawei.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      5f3666e8
    • Y
      tipc: Remove unused macro CF_SERVER · 7eae7f72
      YueHaibing 提交于
      It is no used any more, so can remove it.
      Signed-off-by: NYueHaibing <yuehaibing@huawei.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      7eae7f72
    • R
      net: tipc: delete duplicated words · 60462191
      Randy Dunlap 提交于
      Drop repeated words in net/tipc/.
      Signed-off-by: NRandy Dunlap <rdunlap@infradead.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Jon Maloy <jmaloy@redhat.com>
      Cc: Ying Xue <ying.xue@windriver.com>
      Cc: tipc-discussion@lists.sourceforge.net
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      60462191
    • T
      tipc: add automatic rekeying for encryption key · 23700da2
      Tuong Lien 提交于
      Rekeying is required for security since a key is less secure when using
      for a long time. Also, key will be detached when its nonce value (or
      seqno ...) is exhausted. We now make the rekeying process automatic and
      configurable by user.
      
      Basically, TIPC will at a specific interval generate a new key by using
      the kernel 'Random Number Generator' cipher, then attach it as the node
      TX key and securely distribute to others in the cluster as RX keys (-
      the key exchange). The automatic key switching will then take over, and
      make the new key active shortly. Afterwards, the traffic from this node
      will be encrypted with the new session key. The same can happen in peer
      nodes but not necessarily at the same time.
      
      For simplicity, the automatically generated key will be initiated as a
      per node key. It is not too hard to also support a cluster key rekeying
      (e.g. a given node will generate a unique cluster key and update to the
      others in the cluster...), but that doesn't bring much benefit, while a
      per-node key is even more secure.
      
      We also enable user to force a rekeying or change the rekeying interval
      via netlink, the new 'set key' command option: 'TIPC_NLA_NODE_REKEYING'
      is added for these purposes as follows:
      - A value >= 1 will be set as the rekeying interval (in minutes);
      - A value of 0 will disable the rekeying;
      - A value of 'TIPC_REKEYING_NOW' (~0) will force an immediate rekeying;
      
      The default rekeying interval is (60 * 24) minutes i.e. done every day.
      There isn't any restriction for the value but user shouldn't set it too
      small or too large which results in an "ineffective" rekeying (thats ok
      for testing though).
      Acked-by: NJon Maloy <jmaloy@redhat.com>
      Signed-off-by: NTuong Lien <tuong.t.lien@dektech.com.au>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      23700da2
    • T
      tipc: add automatic session key exchange · 1ef6f7c9
      Tuong Lien 提交于
      With support from the master key option in the previous commit, it
      becomes easy to make frequent updates/exchanges of session keys between
      authenticated cluster nodes.
      Basically, there are two situations where the key exchange will take in
      place:
      
      - When a new node joins the cluster (with the master key), it will need
        to get its peer's TX key, so that be able to decrypt further messages
        from that peer.
      
      - When a new session key is generated (by either user manual setting or
        later automatic rekeying feature), the key will be distributed to all
        peer nodes in the cluster.
      
      A key to be exchanged is encapsulated in the data part of a 'MSG_CRYPTO
      /KEY_DISTR_MSG' TIPC v2 message, then xmit-ed as usual and encrypted by
      using the master key before sending out. Upon receipt of the message it
      will be decrypted in the same way as regular messages, then attached as
      the sender's RX key in the receiver node.
      
      In this way, the key exchange is reliable by the link layer, as well as
      security, integrity and authenticity by the crypto layer.
      
      Also, the forward security will be easily achieved by user changing the
      master key actively but this should not be required very frequently.
      
      The key exchange feature is independent on the presence of a master key
      Note however that the master key still is needed for new nodes to be
      able to join the cluster. It is also optional, and can be turned off/on
      via the sysfs: 'net/tipc/key_exchange_enabled' [default 1: enabled].
      
      Backward compatibility is guaranteed because for nodes that do not have
      master key support, key exchange using master key ie. tx_key = 0 if any
      will be shortly discarded at the message validation step. In other
      words, the key exchange feature will be automatically disabled to those
      nodes.
      
      v2: fix the "implicit declaration of function 'tipc_crypto_key_flush'"
      error in node.c. The function only exists when built with the TIPC
      "CONFIG_TIPC_CRYPTO" option.
      
      v3: use 'info->extack' for a message emitted due to netlink operations
      instead (- David's comment).
      Reported-by: Nkernel test robot <lkp@intel.com>
      Acked-by: NJon Maloy <jmaloy@redhat.com>
      Signed-off-by: NTuong Lien <tuong.t.lien@dektech.com.au>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1ef6f7c9
    • T
      tipc: introduce encryption master key · daef1ee3
      Tuong Lien 提交于
      In addition to the supported cluster & per-node encryption keys for the
      en/decryption of TIPC messages, we now introduce one option for user to
      set a cluster key as 'master key', which is simply a symmetric key like
      the former but has a longer life cycle. It has two purposes:
      
      - Authentication of new member nodes in the cluster. New nodes, having
        no knowledge of current session keys in the cluster will still be
        able to join the cluster as long as they know the master key. This is
        because all neighbor discovery (LINK_CONFIG) messages must be
        encrypted with this key.
      
      - Encryption of session encryption keys during automatic exchange and
        update of those.This is a feature we will introduce in a later commit
        in this series.
      
      We insert the new key into the currently unused slot 0 in the key array
      and start using it immediately once the user has set it.
      After joining, a node only knowing the master key should be fully
      communicable to existing nodes in the cluster, although those nodes may
      have their own session keys activated (i.e. not the master one). To
      support this, we define a 'grace period', starting from the time a node
      itself reports having no RX keys, so the existing nodes will use the
      master key for encryption instead. The grace period can be extended but
      will automatically stop after e.g. 5 seconds without a new report. This
      is also the basis for later key exchanging feature as the new node will
      be impossible to decrypt anything without the support from master key.
      
      For user to set a master key, we define a new netlink flag -
      'TIPC_NLA_NODE_KEY_MASTER', so it can be added to the current 'set key'
      netlink command to specify the setting key to be a master key.
      
      Above all, the traditional cluster/per-node key mechanism is guaranteed
      to work when user comes not to use this master key option. This is also
      compatible to legacy nodes without the feature supported.
      
      Even this master key can be updated without any interruption of cluster
      connectivity but is so is needed, this has to be coordinated and set by
      the user.
      Acked-by: NJon Maloy <jmaloy@redhat.com>
      Signed-off-by: NTuong Lien <tuong.t.lien@dektech.com.au>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      daef1ee3
    • T
      tipc: optimize key switching time and logic · f779bf79
      Tuong Lien 提交于
      We reduce the lasting time for a pending TX key to be active as well as
      for a passive RX key to be freed which generally helps speed up the key
      switching. It is not expected to be too fast but should not be too slow
      either. Also the key handling logic is simplified that a pending RX key
      will be removed automatically if it is found not working after a number
      of times; the probing for a pending TX key is now carried on a specific
      message user ('LINK_PROTOCOL' or 'LINK_CONFIG') which is more efficient
      than using a timer on broadcast messages, the timer is reserved for use
      later as needed.
      
      The kernel logs or 'pr***()' are now made as clear as possible to user.
      Some prints are added, removed or changed to the debug-level. The
      'TIPC_CRYPTO_DEBUG' definition is removed, and the 'pr_debug()' is used
      instead which will be much helpful in runtime.
      
      Besides we also optimize the code in some other places as a preparation
      for later commits.
      
      v2: silent more kernel logs, also use 'info->extack' for a message
      emitted due to netlink operations instead (- David's comments).
      Acked-by: NJon Maloy <jmaloy@redhat.com>
      Signed-off-by: NTuong Lien <tuong.t.lien@dektech.com.au>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      f779bf79
  8. 16 9月, 2020 1 次提交
  9. 15 9月, 2020 2 次提交
    • X
      tipc: use skb_unshare() instead in tipc_buf_append() · ff48b622
      Xin Long 提交于
      In tipc_buf_append() it may change skb's frag_list, and it causes
      problems when this skb is cloned. skb_unclone() doesn't really
      make this skb's flag_list available to change.
      
      Shuang Li has reported an use-after-free issue because of this
      when creating quite a few macvlan dev over the same dev, where
      the broadcast packets will be cloned and go up to the stack:
      
       [ ] BUG: KASAN: use-after-free in pskb_expand_head+0x86d/0xea0
       [ ] Call Trace:
       [ ]  dump_stack+0x7c/0xb0
       [ ]  print_address_description.constprop.7+0x1a/0x220
       [ ]  kasan_report.cold.10+0x37/0x7c
       [ ]  check_memory_region+0x183/0x1e0
       [ ]  pskb_expand_head+0x86d/0xea0
       [ ]  process_backlog+0x1df/0x660
       [ ]  net_rx_action+0x3b4/0xc90
       [ ]
       [ ] Allocated by task 1786:
       [ ]  kmem_cache_alloc+0xbf/0x220
       [ ]  skb_clone+0x10a/0x300
       [ ]  macvlan_broadcast+0x2f6/0x590 [macvlan]
       [ ]  macvlan_process_broadcast+0x37c/0x516 [macvlan]
       [ ]  process_one_work+0x66a/0x1060
       [ ]  worker_thread+0x87/0xb10
       [ ]
       [ ] Freed by task 3253:
       [ ]  kmem_cache_free+0x82/0x2a0
       [ ]  skb_release_data+0x2c3/0x6e0
       [ ]  kfree_skb+0x78/0x1d0
       [ ]  tipc_recvmsg+0x3be/0xa40 [tipc]
      
      So fix it by using skb_unshare() instead, which would create a new
      skb for the cloned frag and it'll be safe to change its frag_list.
      The similar things were also done in sctp_make_reassembled_event(),
      which is using skb_copy().
      Reported-by: NShuang Li <shuali@redhat.com>
      Fixes: 37e22164 ("tipc: rename and move message reassembly function")
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ff48b622
    • P
      tipc: Fix memory leak in tipc_group_create_member() · bb3a420d
      Peilin Ye 提交于
      tipc_group_add_to_tree() returns silently if `key` matches `nkey` of an
      existing node, causing tipc_group_create_member() to leak memory. Let
      tipc_group_add_to_tree() return an error in such a case, so that
      tipc_group_create_member() can handle it properly.
      
      Fixes: 75da2163 ("tipc: introduce communication groups")
      Reported-and-tested-by: syzbot+f95d90c454864b3b5bc9@syzkaller.appspotmail.com
      Cc: Hillf Danton <hdanton@sina.com>
      Link: https://syzkaller.appspot.com/bug?id=048390604fe1b60df34150265479202f10e13affSigned-off-by: NPeilin Ye <yepeilin.cs@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      bb3a420d
  10. 11 9月, 2020 1 次提交
    • T
      tipc: fix shutdown() of connection oriented socket · a4b5cc9e
      Tetsuo Handa 提交于
      I confirmed that the problem fixed by commit 2a63866c ("tipc: fix
      shutdown() of connectionless socket") also applies to stream socket.
      
      ----------
      #include <sys/socket.h>
      #include <unistd.h>
      #include <sys/wait.h>
      
      int main(int argc, char *argv[])
      {
              int fds[2] = { -1, -1 };
              socketpair(PF_TIPC, SOCK_STREAM /* or SOCK_DGRAM */, 0, fds);
              if (fork() == 0)
                      _exit(read(fds[0], NULL, 1));
              shutdown(fds[0], SHUT_RDWR); /* This must make read() return. */
              wait(NULL); /* To be woken up by _exit(). */
              return 0;
      }
      ----------
      
      Since shutdown(SHUT_RDWR) should affect all processes sharing that socket,
      unconditionally setting sk->sk_shutdown to SHUTDOWN_MASK will be the right
      behavior.
      Signed-off-by: NTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Acked-by: NYing Xue <ying.xue@windriver.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      a4b5cc9e
  11. 08 9月, 2020 1 次提交
    • H
      tipc: fix a deadlock when flushing scheduled work · d966ddcc
      Hoang Huu Le 提交于
      In the commit fdeba99b
      ("tipc: fix use-after-free in tipc_bcast_get_mode"), we're trying
      to make sure the tipc_net_finalize_work work item finished if it
      enqueued. But calling flush_scheduled_work() is not just affecting
      above work item but either any scheduled work. This has turned out
      to be overkill and caused to deadlock as syzbot reported:
      
      ======================================================
      WARNING: possible circular locking dependency detected
      5.9.0-rc2-next-20200828-syzkaller #0 Not tainted
      ------------------------------------------------------
      kworker/u4:6/349 is trying to acquire lock:
      ffff8880aa063d38 ((wq_completion)events){+.+.}-{0:0}, at: flush_workqueue+0xe1/0x13e0 kernel/workqueue.c:2777
      
      but task is already holding lock:
      ffffffff8a879430 (pernet_ops_rwsem){++++}-{3:3}, at: cleanup_net+0x9b/0xb10 net/core/net_namespace.c:565
      
      [...]
       Possible unsafe locking scenario:
      
             CPU0                    CPU1
             ----                    ----
        lock(pernet_ops_rwsem);
                                     lock(&sb->s_type->i_mutex_key#13);
                                     lock(pernet_ops_rwsem);
        lock((wq_completion)events);
      
       *** DEADLOCK ***
      [...]
      
      v1:
      To fix the original issue, we replace above calling by introducing
      a bit flag. When a namespace cleaned-up, bit flag is set to zero and:
      - tipc_net_finalize functionial just does return immediately.
      - tipc_net_finalize_work does not enqueue into the scheduled work queue.
      
      v2:
      Use cancel_work_sync() helper to make sure ONLY the
      tipc_net_finalize_work() stopped before releasing bcbase object.
      
      Reported-by: syzbot+d5aa7e0385f6a5d0f4fd@syzkaller.appspotmail.com
      Fixes: fdeba99b ("tipc: fix use-after-free in tipc_bcast_get_mode")
      Acked-by: NJon Maloy <jmaloy@redhat.com>
      Signed-off-by: NHoang Huu Le <hoang.h.le@dektech.com.au>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      d966ddcc
  12. 03 9月, 2020 1 次提交
    • T
      tipc: fix shutdown() of connectionless socket · 2a63866c
      Tetsuo Handa 提交于
      syzbot is reporting hung task at nbd_ioctl() [1], for there are two
      problems regarding TIPC's connectionless socket's shutdown() operation.
      
      ----------
      #include <fcntl.h>
      #include <sys/socket.h>
      #include <sys/ioctl.h>
      #include <linux/nbd.h>
      #include <unistd.h>
      
      int main(int argc, char *argv[])
      {
              const int fd = open("/dev/nbd0", 3);
              alarm(5);
              ioctl(fd, NBD_SET_SOCK, socket(PF_TIPC, SOCK_DGRAM, 0));
              ioctl(fd, NBD_DO_IT, 0); /* To be interrupted by SIGALRM. */
              return 0;
      }
      ----------
      
      One problem is that wait_for_completion() from flush_workqueue() from
      nbd_start_device_ioctl() from nbd_ioctl() cannot be completed when
      nbd_start_device_ioctl() received a signal at wait_event_interruptible(),
      for tipc_shutdown() from kernel_sock_shutdown(SHUT_RDWR) from
      nbd_mark_nsock_dead() from sock_shutdown() from nbd_start_device_ioctl()
      is failing to wake up a WQ thread sleeping at wait_woken() from
      tipc_wait_for_rcvmsg() from sock_recvmsg() from sock_xmit() from
      nbd_read_stat() from recv_work() scheduled by nbd_start_device() from
      nbd_start_device_ioctl(). Fix this problem by always invoking
      sk->sk_state_change() (like inet_shutdown() does) when tipc_shutdown() is
      called.
      
      The other problem is that tipc_wait_for_rcvmsg() cannot return when
      tipc_shutdown() is called, for tipc_shutdown() sets sk->sk_shutdown to
      SEND_SHUTDOWN (despite "how" is SHUT_RDWR) while tipc_wait_for_rcvmsg()
      needs sk->sk_shutdown set to RCV_SHUTDOWN or SHUTDOWN_MASK. Fix this
      problem by setting sk->sk_shutdown to SHUTDOWN_MASK (like inet_shutdown()
      does) when the socket is connectionless.
      
      [1] https://syzkaller.appspot.com/bug?id=3fe51d307c1f0a845485cf1798aa059d12bf18b2Reported-by: Nsyzbot <syzbot+e36f41d207137b5d12f7@syzkaller.appspotmail.com>
      Signed-off-by: NTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2a63866c
  13. 01 9月, 2020 2 次提交
  14. 31 8月, 2020 1 次提交
  15. 27 8月, 2020 1 次提交
    • H
      tipc: fix use-after-free in tipc_bcast_get_mode · fdeba99b
      Hoang Huu Le 提交于
      Syzbot has reported those issues as:
      
      ==================================================================
      BUG: KASAN: use-after-free in tipc_bcast_get_mode+0x3ab/0x400 net/tipc/bcast.c:759
      Read of size 1 at addr ffff88805e6b3571 by task kworker/0:6/3850
      
      CPU: 0 PID: 3850 Comm: kworker/0:6 Not tainted 5.8.0-rc7-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Workqueue: events tipc_net_finalize_work
      
      Thread 1's call trace:
      [...]
        kfree+0x103/0x2c0 mm/slab.c:3757 <- bcbase releasing
        tipc_bcast_stop+0x1b0/0x2f0 net/tipc/bcast.c:721
        tipc_exit_net+0x24/0x270 net/tipc/core.c:112
      [...]
      
      Thread 2's call trace:
      [...]
        tipc_bcast_get_mode+0x3ab/0x400 net/tipc/bcast.c:759 <- bcbase
      has already been freed by Thread 1
      
        tipc_node_broadcast+0x9e/0xcc0 net/tipc/node.c:1744
        tipc_nametbl_publish+0x60b/0x970 net/tipc/name_table.c:752
        tipc_net_finalize net/tipc/net.c:141 [inline]
        tipc_net_finalize+0x1fa/0x310 net/tipc/net.c:131
        tipc_net_finalize_work+0x55/0x80 net/tipc/net.c:150
      [...]
      
      ==================================================================
      BUG: KASAN: use-after-free in tipc_named_reinit+0xef/0x290 net/tipc/name_distr.c:344
      Read of size 8 at addr ffff888052ab2000 by task kworker/0:13/30628
      CPU: 0 PID: 30628 Comm: kworker/0:13 Not tainted 5.8.0-syzkaller #0
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
      Workqueue: events tipc_net_finalize_work
      Call Trace:
       __dump_stack lib/dump_stack.c:77 [inline]
       dump_stack+0x1f0/0x31e lib/dump_stack.c:118
       print_address_description+0x66/0x5a0 mm/kasan/report.c:383
       __kasan_report mm/kasan/report.c:513 [inline]
       kasan_report+0x132/0x1d0 mm/kasan/report.c:530
       tipc_named_reinit+0xef/0x290 net/tipc/name_distr.c:344
       tipc_net_finalize+0x85/0xe0 net/tipc/net.c:138
       tipc_net_finalize_work+0x50/0x70 net/tipc/net.c:150
       process_one_work+0x789/0xfc0 kernel/workqueue.c:2269
       worker_thread+0xaa4/0x1460 kernel/workqueue.c:2415
       kthread+0x37e/0x3a0 drivers/block/aoe/aoecmd.c:1234
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:293
      [...]
      Freed by task 14058:
       save_stack mm/kasan/common.c:48 [inline]
       set_track mm/kasan/common.c:56 [inline]
       kasan_set_free_info mm/kasan/common.c:316 [inline]
       __kasan_slab_free+0x114/0x170 mm/kasan/common.c:455
       __cache_free mm/slab.c:3426 [inline]
       kfree+0x10a/0x220 mm/slab.c:3757
       tipc_exit_net+0x29/0x50 net/tipc/core.c:113
       ops_exit_list net/core/net_namespace.c:186 [inline]
       cleanup_net+0x708/0xba0 net/core/net_namespace.c:603
       process_one_work+0x789/0xfc0 kernel/workqueue.c:2269
       worker_thread+0xaa4/0x1460 kernel/workqueue.c:2415
       kthread+0x37e/0x3a0 drivers/block/aoe/aoecmd.c:1234
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:293
      
      Fix it by calling flush_scheduled_work() to make sure the
      tipc_net_finalize_work() stopped before releasing bcbase object.
      
      Reported-by: syzbot+6ea1f7a8df64596ef4d7@syzkaller.appspotmail.com
      Reported-by: syzbot+e9cc557752ab126c1b99@syzkaller.appspotmail.com
      Acked-by: NJon Maloy <jmaloy@redhat.com>
      Signed-off-by: NHoang Huu Le <hoang.h.le@dektech.com.au>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      fdeba99b
  16. 24 8月, 2020 1 次提交
  17. 21 8月, 2020 1 次提交
    • X
      tipc: call rcu_read_lock() in tipc_aead_encrypt_done() · f6db9096
      Xin Long 提交于
      b->media->send_msg() requires rcu_read_lock(), as we can see
      elsewhere in tipc,  tipc_bearer_xmit, tipc_bearer_xmit_skb
      and tipc_bearer_bc_xmit().
      
      Syzbot has reported this issue as:
      
        net/tipc/bearer.c:466 suspicious rcu_dereference_check() usage!
        Workqueue: cryptd cryptd_queue_worker
        Call Trace:
         tipc_l2_send_msg+0x354/0x420 net/tipc/bearer.c:466
         tipc_aead_encrypt_done+0x204/0x3a0 net/tipc/crypto.c:761
         cryptd_aead_crypt+0xe8/0x1d0 crypto/cryptd.c:739
         cryptd_queue_worker+0x118/0x1b0 crypto/cryptd.c:181
         process_one_work+0x94c/0x1670 kernel/workqueue.c:2269
         worker_thread+0x64c/0x1120 kernel/workqueue.c:2415
         kthread+0x3b5/0x4a0 kernel/kthread.c:291
         ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:293
      
      So fix it by calling rcu_read_lock() in tipc_aead_encrypt_done()
      for b->media->send_msg().
      
      Fixes: fc1b6d6d ("tipc: introduce TIPC encryption & authentication")
      Reported-by: syzbot+47bbc6b678d317cccbe0@syzkaller.appspotmail.com
      Signed-off-by: NXin Long <lucien.xin@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      f6db9096
  18. 19 8月, 2020 2 次提交
  19. 17 8月, 2020 2 次提交
  20. 08 8月, 2020 1 次提交
    • W
      mm, treewide: rename kzfree() to kfree_sensitive() · 453431a5
      Waiman Long 提交于
      As said by Linus:
      
        A symmetric naming is only helpful if it implies symmetries in use.
        Otherwise it's actively misleading.
      
        In "kzalloc()", the z is meaningful and an important part of what the
        caller wants.
      
        In "kzfree()", the z is actively detrimental, because maybe in the
        future we really _might_ want to use that "memfill(0xdeadbeef)" or
        something. The "zero" part of the interface isn't even _relevant_.
      
      The main reason that kzfree() exists is to clear sensitive information
      that should not be leaked to other future users of the same memory
      objects.
      
      Rename kzfree() to kfree_sensitive() to follow the example of the recently
      added kvfree_sensitive() and make the intention of the API more explicit.
      In addition, memzero_explicit() is used to clear the memory to make sure
      that it won't get optimized away by the compiler.
      
      The renaming is done by using the command sequence:
      
        git grep -w --name-only kzfree |\
        xargs sed -i 's/kzfree/kfree_sensitive/'
      
      followed by some editing of the kfree_sensitive() kerneldoc and adding
      a kzfree backward compatibility macro in slab.h.
      
      [akpm@linux-foundation.org: fs/crypto/inline_crypt.c needs linux/slab.h]
      [akpm@linux-foundation.org: fix fs/crypto/inline_crypt.c some more]
      Suggested-by: NJoe Perches <joe@perches.com>
      Signed-off-by: NWaiman Long <longman@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Acked-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NMichal Hocko <mhocko@suse.com>
      Acked-by: NJohannes Weiner <hannes@cmpxchg.org>
      Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Cc: "Jason A . Donenfeld" <Jason@zx2c4.com>
      Link: http://lkml.kernel.org/r/20200616154311.12314-3-longman@redhat.comSigned-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      453431a5
  21. 06 8月, 2020 1 次提交
  22. 04 8月, 2020 1 次提交
  23. 25 7月, 2020 1 次提交
  24. 21 7月, 2020 1 次提交
  25. 14 7月, 2020 1 次提交