1. 08 9月, 2021 9 次提交
  2. 04 9月, 2021 2 次提交
  3. 01 9月, 2021 1 次提交
    • W
      Bluetooth: fix use-after-free error in lock_sock_nested() · 1bff51ea
      Wang ShaoBo 提交于
      use-after-free error in lock_sock_nested is reported:
      
      [  179.140137][ T3731] =====================================================
      [  179.142675][ T3731] BUG: KMSAN: use-after-free in lock_sock_nested+0x280/0x2c0
      [  179.145494][ T3731] CPU: 4 PID: 3731 Comm: kworker/4:2 Not tainted 5.12.0-rc6+ #54
      [  179.148432][ T3731] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
      [  179.151806][ T3731] Workqueue: events l2cap_chan_timeout
      [  179.152730][ T3731] Call Trace:
      [  179.153301][ T3731]  dump_stack+0x24c/0x2e0
      [  179.154063][ T3731]  kmsan_report+0xfb/0x1e0
      [  179.154855][ T3731]  __msan_warning+0x5c/0xa0
      [  179.155579][ T3731]  lock_sock_nested+0x280/0x2c0
      [  179.156436][ T3731]  ? kmsan_get_metadata+0x116/0x180
      [  179.157257][ T3731]  l2cap_sock_teardown_cb+0xb8/0x890
      [  179.158154][ T3731]  ? __msan_metadata_ptr_for_load_8+0x10/0x20
      [  179.159141][ T3731]  ? kmsan_get_metadata+0x116/0x180
      [  179.159994][ T3731]  ? kmsan_get_shadow_origin_ptr+0x84/0xb0
      [  179.160959][ T3731]  ? l2cap_sock_recv_cb+0x420/0x420
      [  179.161834][ T3731]  l2cap_chan_del+0x3e1/0x1d50
      [  179.162608][ T3731]  ? kmsan_get_metadata+0x116/0x180
      [  179.163435][ T3731]  ? kmsan_get_shadow_origin_ptr+0x84/0xb0
      [  179.164406][ T3731]  l2cap_chan_close+0xeea/0x1050
      [  179.165189][ T3731]  ? kmsan_internal_unpoison_shadow+0x42/0x70
      [  179.166180][ T3731]  l2cap_chan_timeout+0x1da/0x590
      [  179.167066][ T3731]  ? __msan_metadata_ptr_for_load_8+0x10/0x20
      [  179.168023][ T3731]  ? l2cap_chan_create+0x560/0x560
      [  179.168818][ T3731]  process_one_work+0x121d/0x1ff0
      [  179.169598][ T3731]  worker_thread+0x121b/0x2370
      [  179.170346][ T3731]  kthread+0x4ef/0x610
      [  179.171010][ T3731]  ? process_one_work+0x1ff0/0x1ff0
      [  179.171828][ T3731]  ? kthread_blkcg+0x110/0x110
      [  179.172587][ T3731]  ret_from_fork+0x1f/0x30
      [  179.173348][ T3731]
      [  179.173752][ T3731] Uninit was created at:
      [  179.174409][ T3731]  kmsan_internal_poison_shadow+0x5c/0xf0
      [  179.175373][ T3731]  kmsan_slab_free+0x76/0xc0
      [  179.176060][ T3731]  kfree+0x3a5/0x1180
      [  179.176664][ T3731]  __sk_destruct+0x8af/0xb80
      [  179.177375][ T3731]  __sk_free+0x812/0x8c0
      [  179.178032][ T3731]  sk_free+0x97/0x130
      [  179.178686][ T3731]  l2cap_sock_release+0x3d5/0x4d0
      [  179.179457][ T3731]  sock_close+0x150/0x450
      [  179.180117][ T3731]  __fput+0x6bd/0xf00
      [  179.180787][ T3731]  ____fput+0x37/0x40
      [  179.181481][ T3731]  task_work_run+0x140/0x280
      [  179.182219][ T3731]  do_exit+0xe51/0x3e60
      [  179.182930][ T3731]  do_group_exit+0x20e/0x450
      [  179.183656][ T3731]  get_signal+0x2dfb/0x38f0
      [  179.184344][ T3731]  arch_do_signal_or_restart+0xaa/0xe10
      [  179.185266][ T3731]  exit_to_user_mode_prepare+0x2d2/0x560
      [  179.186136][ T3731]  syscall_exit_to_user_mode+0x35/0x60
      [  179.186984][ T3731]  do_syscall_64+0xc5/0x140
      [  179.187681][ T3731]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  179.188604][ T3731] =====================================================
      
      In our case, there are two Thread A and B:
      
      Context: Thread A:              Context: Thread B:
      
      l2cap_chan_timeout()            __se_sys_shutdown()
        l2cap_chan_close()              l2cap_sock_shutdown()
          l2cap_chan_del()                l2cap_chan_close()
            l2cap_sock_teardown_cb()        l2cap_sock_teardown_cb()
      
      Once l2cap_sock_teardown_cb() excuted, this sock will be marked as SOCK_ZAPPED,
      and can be treated as killable in l2cap_sock_kill() if sock_orphan() has
      excuted, at this time we close sock through sock_close() which end to call
      l2cap_sock_kill() like Thread C:
      
      Context: Thread C:
      
      sock_close()
        l2cap_sock_release()
          sock_orphan()
          l2cap_sock_kill()  #free sock if refcnt is 1
      
      If C completed, Once A or B reaches l2cap_sock_teardown_cb() again,
      use-after-free happened.
      
      We should set chan->data to NULL if sock is destructed, for telling teardown
      operation is not allowed in l2cap_sock_teardown_cb(), and also we should
      avoid killing an already killed socket in l2cap_sock_close_cb().
      Signed-off-by: NWang ShaoBo <bobo.shaobowang@huawei.com>
      Signed-off-by: NLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      1bff51ea
  4. 31 8月, 2021 2 次提交
  5. 30 8月, 2021 13 次提交
  6. 28 8月, 2021 1 次提交
    • R
      ipv6: add IFLA_INET6_RA_MTU to expose mtu value · 49b99da2
      Rocco Yue 提交于
      The kernel provides a "/proc/sys/net/ipv6/conf/<iface>/mtu"
      file, which can temporarily record the mtu value of the last
      received RA message when the RA mtu value is lower than the
      interface mtu, but this proc has following limitations:
      
      (1) when the interface mtu (/sys/class/net/<iface>/mtu) is
      updeated, mtu6 (/proc/sys/net/ipv6/conf/<iface>/mtu) will
      be updated to the value of interface mtu;
      (2) mtu6 (/proc/sys/net/ipv6/conf/<iface>/mtu) only affect
      ipv6 connection, and not affect ipv4.
      
      Therefore, when the mtu option is carried in the RA message,
      there will be a problem that the user sometimes cannot obtain
      RA mtu value correctly by reading mtu6.
      
      After this patch set, if a RA message carries the mtu option,
      you can send a netlink msg which nlmsg_type is RTM_GETLINK,
      and then by parsing the attribute of IFLA_INET6_RA_MTU to
      get the mtu value carried in the RA message received on the
      inet6 device. In addition, you can also get a link notification
      when ra_mtu is updated so it doesn't have to poll.
      
      In this way, if the MTU values that the device receives from
      the network in the PCO IPv4 and the RA IPv6 procedures are
      different, the user can obtain the correct ipv6 ra_mtu value
      and compare the value of ra_mtu and ipv4 mtu, then the device
      can use the lower MTU value for both IPv4 and IPv6.
      Signed-off-by: NRocco Yue <rocco.yue@mediatek.com>
      Reviewed-by: NDavid Ahern <dsahern@kernel.org>
      Link: https://lore.kernel.org/r/20210827150412.9267-1-rocco.yue@mediatek.comSigned-off-by: NJakub Kicinski <kuba@kernel.org>
      49b99da2
  7. 27 8月, 2021 7 次提交
  8. 26 8月, 2021 5 次提交
    • net: fix NULL pointer reference in cipso_v4_doi_free · 733c99ee
      王贇 提交于
      In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc
      failed, we sometime observe panic:
      
        BUG: kernel NULL pointer dereference, address:
        ...
        RIP: 0010:cipso_v4_doi_free+0x3a/0x80
        ...
        Call Trace:
         netlbl_cipsov4_add_std+0xf4/0x8c0
         netlbl_cipsov4_add+0x13f/0x1b0
         genl_family_rcv_msg_doit.isra.15+0x132/0x170
         genl_rcv_msg+0x125/0x240
      
      This is because in cipso_v4_doi_free() there is no check
      on 'doi_def->map.std' when 'doi_def->type' equal 1, which
      is possibe, since netlbl_cipsov4_add_std() haven't initialize
      it before alloc 'doi_def->map.std'.
      
      This patch just add the check to prevent panic happen for similar
      cases.
      Reported-by: NAbaci <abaci@linux.alibaba.com>
      Signed-off-by: NMichael Wang <yun.wang@linux.alibaba.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      733c99ee
    • A
      rtnetlink: Return correct error on changing device netns · 96a6b93b
      Andrey Ignatov 提交于
      Currently when device is moved between network namespaces using
      RTM_NEWLINK message type and one of netns attributes (FLA_NET_NS_PID,
      IFLA_NET_NS_FD, IFLA_TARGET_NETNSID) but w/o specifying IFLA_IFNAME, and
      target namespace already has device with same name, userspace will get
      EINVAL what is confusing and makes debugging harder.
      
      Fix it so that userspace gets more appropriate EEXIST instead what makes
      debugging much easier.
      
      Before:
      
        # ./ifname.sh
        + ip netns add ns0
        + ip netns exec ns0 ip link add l0 type dummy
        + ip netns exec ns0 ip link show l0
        8: l0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
            link/ether 66:90:b5:d5:78:69 brd ff:ff:ff:ff:ff:ff
        + ip link add l0 type dummy
        + ip link show l0
        10: l0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
            link/ether 6e:c6:1f:15:20:8d brd ff:ff:ff:ff:ff:ff
        + ip link set l0 netns ns0
        RTNETLINK answers: Invalid argument
      
      After:
      
        # ./ifname.sh
        + ip netns add ns0
        + ip netns exec ns0 ip link add l0 type dummy
        + ip netns exec ns0 ip link show l0
        8: l0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
            link/ether 1e:4a:72:e3:e3:8f brd ff:ff:ff:ff:ff:ff
        + ip link add l0 type dummy
        + ip link show l0
        10: l0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
            link/ether f2:fc:fe:2b:7d:a6 brd ff:ff:ff:ff:ff:ff
        + ip link set l0 netns ns0
        RTNETLINK answers: File exists
      
      The problem is that do_setlink() passes its `char *ifname` argument,
      that it gets from a caller, to __dev_change_net_namespace() as is (as
      `const char *pat`), but semantics of ifname and pat can be different.
      
      For example, __rtnl_newlink() does this:
      
      net/core/rtnetlink.c
          3270	char ifname[IFNAMSIZ];
           ...
          3286	if (tb[IFLA_IFNAME])
          3287		nla_strscpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
          3288	else
          3289		ifname[0] = '\0';
           ...
          3364	if (dev) {
           ...
          3394		return do_setlink(skb, dev, ifm, extack, tb, ifname, status);
          3395	}
      
      , i.e. do_setlink() gets ifname pointer that is always valid no matter
      if user specified IFLA_IFNAME or not and then do_setlink() passes this
      ifname pointer as is to __dev_change_net_namespace() as pat argument.
      
      But the pat (pattern) in __dev_change_net_namespace() is used as:
      
      net/core/dev.c
         11198	err = -EEXIST;
         11199	if (__dev_get_by_name(net, dev->name)) {
         11200		/* We get here if we can't use the current device name */
         11201		if (!pat)
         11202			goto out;
         11203		err = dev_get_valid_name(net, dev, pat);
         11204		if (err < 0)
         11205			goto out;
         11206	}
      
      As the result the `goto out` path on line 11202 is neven taken and
      instead of returning EEXIST defined on line 11198,
      __dev_change_net_namespace() returns an error from dev_get_valid_name()
      and this, in turn, will be EINVAL for ifname[0] = '\0' set earlier.
      
      Fixes: d8a5ec67 ("[NET]: netlink support for moving devices between network namespaces.")
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      96a6b93b
    • Y
      sock: remove one redundant SKB_FRAG_PAGE_ORDER macro · 723783d0
      Yunsheng Lin 提交于
      Both SKB_FRAG_PAGE_ORDER are defined to the same value in
      net/core/sock.c and drivers/vhost/net.c.
      
      Move the SKB_FRAG_PAGE_ORDER definition to net/core/sock.h,
      as both net/core/sock.c and drivers/vhost/net.c include it,
      and it seems a reasonable file to put the macro.
      Signed-off-by: NYunsheng Lin <linyunsheng@huawei.com>
      Acked-by: NJason Wang <jasowang@redhat.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      723783d0
    • E
      ipv4: use siphash instead of Jenkins in fnhe_hashfun() · 6457378f
      Eric Dumazet 提交于
      A group of security researchers brought to our attention
      the weakness of hash function used in fnhe_hashfun().
      
      Lets use siphash instead of Jenkins Hash, to considerably
      reduce security risks.
      
      Also remove the inline keyword, this really is distracting.
      
      Fixes: d546c621 ("ipv4: harden fnhe_hashfun()")
      Signed-off-by: NEric Dumazet <edumazet@google.com>
      Reported-by: NKeyu Man <kman001@ucr.edu>
      Cc: Willy Tarreau <w@1wt.eu>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      6457378f
    • E
      ipv6: use siphash in rt6_exception_hash() · 4785305c
      Eric Dumazet 提交于
      A group of security researchers brought to our attention
      the weakness of hash function used in rt6_exception_hash()
      
      Lets use siphash instead of Jenkins Hash, to considerably
      reduce security risks.
      
      Following patch deals with IPv4.
      
      Fixes: 35732d01 ("ipv6: introduce a hash table to store dst cache")
      Signed-off-by: NEric Dumazet <edumazet@google.com>
      Reported-by: NKeyu Man <kman001@ucr.edu>
      Cc: Wei Wang <weiwan@google.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Acked-by: NWei Wang <weiwan@google.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4785305c