linux-stable/net
Peilin Ye 8ff5db3c1b vsock: Fix memory leak in vsock_connect()
commit 7e97cfed99 upstream.

An O_NONBLOCK vsock_connect() request may try to reschedule
@connect_work.  Imagine the following sequence of vsock_connect()
requests:

  1. The 1st, non-blocking request schedules @connect_work, which will
     expire after 200 jiffies.  Socket state is now SS_CONNECTING;

  2. Later, the 2nd, blocking request gets interrupted by a signal after
     a few jiffies while waiting for the connection to be established.
     Socket state is back to SS_UNCONNECTED, but @connect_work is still
     pending, and will expire after 100 jiffies.

  3. Now, the 3rd, non-blocking request tries to schedule @connect_work
     again.  Since @connect_work is already scheduled,
     schedule_delayed_work() silently returns.  sock_hold() is called
     twice, but sock_put() will only be called once in
     vsock_connect_timeout(), causing a memory leak reported by syzbot:

  BUG: memory leak
  unreferenced object 0xffff88810ea56a40 (size 1232):
    comm "syz-executor756", pid 3604, jiffies 4294947681 (age 12.350s)
    hex dump (first 32 bytes):
      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
      28 00 07 40 00 00 00 00 00 00 00 00 00 00 00 00  (..@............
    backtrace:
      [<ffffffff837c830e>] sk_prot_alloc+0x3e/0x1b0 net/core/sock.c:1930
      [<ffffffff837cbe22>] sk_alloc+0x32/0x2e0 net/core/sock.c:1989
      [<ffffffff842ccf68>] __vsock_create.constprop.0+0x38/0x320 net/vmw_vsock/af_vsock.c:734
      [<ffffffff842ce8f1>] vsock_create+0xc1/0x2d0 net/vmw_vsock/af_vsock.c:2203
      [<ffffffff837c0cbb>] __sock_create+0x1ab/0x2b0 net/socket.c:1468
      [<ffffffff837c3acf>] sock_create net/socket.c:1519 [inline]
      [<ffffffff837c3acf>] __sys_socket+0x6f/0x140 net/socket.c:1561
      [<ffffffff837c3bba>] __do_sys_socket net/socket.c:1570 [inline]
      [<ffffffff837c3bba>] __se_sys_socket net/socket.c:1568 [inline]
      [<ffffffff837c3bba>] __x64_sys_socket+0x1a/0x20 net/socket.c:1568
      [<ffffffff84512815>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
      [<ffffffff84512815>] do_syscall_64+0x35/0x80 arch/x86/entry/common.c:80
      [<ffffffff84600068>] entry_SYSCALL_64_after_hwframe+0x44/0xae
  <...>

Use mod_delayed_work() instead: if @connect_work is already scheduled,
reschedule it, and undo sock_hold() to keep the reference count
balanced.

Reported-and-tested-by: syzbot+b03f55bf128f9a38f064@syzkaller.appspotmail.com
Fixes: d021c34405 ("VSOCK: Introduce VM Sockets")
Co-developed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-08-25 11:45:21 +02:00
..
6lowpan
9p net/9p: Initialize the iounit field during fid creation 2022-08-17 15:16:09 +02:00
802
8021q vlan: fix memory leak in vlan_newlink() 2022-07-09 12:26:59 +01:00
appletalk net: remove noblock parameter from skb_recv_datagram() 2022-04-06 13:45:26 +01:00
atm net: SO_RCVMARK socket option for SO_MARK with recvmsg() 2022-04-28 13:08:15 -07:00
ax25 ax25: fix incorrect dev_tracker usage 2022-08-17 15:14:57 +02:00
batman-adv batman-adv: tracing: Use the new __vstring() helper 2022-08-17 15:16:15 +02:00
bluetooth Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression 2022-08-17 15:16:21 +02:00
bpf Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2022-05-23 16:07:14 -07:00
bpfilter
bridge bridge: Do not send empty IFLA_AF_SPEC attribute 2022-07-26 15:35:53 +02:00
caif caif: Fix bitmap data type in "struct caifsock" 2022-07-22 12:51:45 +01:00
can can: j1939: j1939_session_destroy(): fix memory leak of skbs 2022-08-25 11:45:14 +02:00
ceph libceph: use swap() macro instead of taking tmp variable 2022-05-25 20:45:13 +02:00
core devlink: Fix use-after-free after a failed reload 2022-08-25 11:45:16 +02:00
dcb
dccp dccp: put dccp_qpolicy_full() and dccp_qpolicy_push() in the same lock 2022-08-17 15:14:59 +02:00
decnet net: Fix data-races around sysctl_[rw]mem(_offset)?. 2022-07-25 12:42:09 +01:00
dns_resolver
dsa net: dsa: fix reference counting for LAG FDBs 2022-07-25 19:37:06 -07:00
ethernet net: ethernet: set default assignment identifier to NET_NAME_ENUM 2022-04-07 21:04:03 -07:00
ethtool ethtool: Fix get module eeprom fallback 2022-06-17 20:22:16 -07:00
hsr
ieee802154 net: SO_RCVMARK socket option for SO_MARK with recvmsg() 2022-04-28 13:08:15 -07:00
ife
ipv4 raw: fix a typo in raw_icmp_error() 2022-08-17 15:16:19 +02:00
ipv6 ipv6: do not use RT_TOS for IPv6 flowlabel 2022-08-25 11:45:21 +02:00
iucv net: remove noblock parameter from skb_recv_datagram() 2022-04-06 13:45:26 +01:00
kcm
key Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec 2022-06-01 17:44:04 -07:00
l2tp ipv6: Fix signed integer overflow in l2tp_ip6_sendmsg 2022-06-08 10:56:43 -07:00
l3mdev l3mdev: l3mdev_master_upper_ifindex_by_index_rcu should be using netdev_master_upper_dev_get_rcu 2022-04-15 14:27:24 -07:00
lapb
llc llc: only change llc->dev when bind() succeeds 2022-03-25 16:55:41 -07:00
mac80211 wifi: mac80211: move some future per-link data to bss_conf 2022-08-17 15:14:46 +02:00
mac802154 net: mac802154: Fix symbol durations 2022-04-30 20:29:47 +02:00
mctp Networking changes for 5.19. 2022-05-25 12:22:58 -07:00
mpls net: mpls: fix memdup.cocci warning 2022-04-07 21:06:41 -07:00
mptcp mptcp: do not queue data on closed subflows 2022-08-25 11:45:13 +02:00
ncsi net/ncsi: use proper "mellanox" DT vendor prefix 2022-06-23 20:51:06 -07:00
netfilter netfilter: nf_tables: fix crash when nf_trace is enabled 2022-08-25 11:45:12 +02:00
netlabel netlabel: fix out-of-bounds memory accesses 2022-03-21 10:59:11 +00:00
netlink Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2022-05-12 16:15:30 -07:00
netrom net: remove noblock parameter from skb_recv_datagram() 2022-04-06 13:45:26 +01:00
nfc net: nfc: Directly use ida_alloc()/free() 2022-05-28 15:28:47 +01:00
nsh
openvswitch net: openvswitch: fix parsing of nw_proto for IPv6 fragments 2022-06-23 11:44:01 +02:00
packet net/af_packet: make sure to pull mac header 2022-06-02 10:15:05 -07:00
phonet net: remove noblock parameter from recvmsg() entities 2022-04-12 15:00:25 +02:00
psample
qrtr net: remove noblock parameter from skb_recv_datagram() 2022-04-06 13:45:26 +01:00
rds rds: add missing barrier to release_refill 2022-08-25 11:45:05 +02:00
rfkill rfkill: make new event layout opt-in 2022-03-18 13:09:17 +02:00
rose net: rose: fix netdev reference changes 2022-08-17 15:14:59 +02:00
rxrpc Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2022-05-23 21:19:17 -07:00
sched net_sched: cls_route: disallow handle of 0 2022-08-21 15:20:08 +02:00
sctp sctp: leave the err path free in sctp_stream_init to sctp_stream_free 2022-07-27 18:23:22 -07:00
smc tcp: Fix data-races around keepalive sysctl knobs. 2022-07-18 12:21:54 +01:00
strparser
sunrpc SUNRPC: Don't reuse bvec on retransmission of the request 2022-08-25 11:45:15 +02:00
switchdev
tipc net: Fix data-races around sysctl_[rw]mem(_offset)?. 2022-07-25 12:42:09 +01:00
tls net/tls: Remove the context from the list in tls_device_down 2022-07-24 21:40:56 +01:00
unix af_unix: Fix a data-race in unix_dgram_peer_wake_me(). 2022-06-07 12:07:46 +02:00
vmw_vsock vsock: Fix memory leak in vsock_connect() 2022-08-25 11:45:21 +02:00
wireless wifi: cfg80211: remove chandef check in cfg80211_cac_event() 2022-08-17 15:16:20 +02:00
x25 x25: remove redundant pointer dev 2022-05-10 11:59:22 +02:00
xdp xsk: Clear page contiguity bit when unmapping pool 2022-06-28 22:49:04 +02:00
xfrm Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec 2022-07-20 10:11:58 +01:00
compat.c
devres.c
Kconfig
Kconfig.debug net: CONFIG_DEBUG_NET depends on CONFIG_NET 2022-06-02 10:15:05 -07:00
Makefile
socket.c net: clear msg_get_inq in __sys_recvfrom() and __copy_msghdr_from_user() 2022-06-23 20:56:23 -07:00
sysctl_net.c