Skip to content

Commit 62209d1

Browse files
congwanggregkh
authored andcommitted
vsock: split dwork to avoid reinitializations
[ Upstream commit 455f05e ] syzbot reported that we reinitialize an active delayed work in vsock_stream_connect(): ODEBUG: init active (active state 0) object type: timer_list hint: delayed_work_timer_fn+0x0/0x90 kernel/workqueue.c:1414 WARNING: CPU: 1 PID: 11518 at lib/debugobjects.c:329 debug_print_object+0x16a/0x210 lib/debugobjects.c:326 The pattern is apparently wrong, we should only initialize the dealyed work once and could repeatly schedule it. So we have to move out the initializations to allocation side. And to avoid confusion, we can split the shared dwork into two, instead of re-using the same one. Fixes: d021c34 ("VSOCK: Introduce VM Sockets") Reported-by: <[email protected]> Cc: Andy king <[email protected]> Cc: Stefan Hajnoczi <[email protected]> Cc: Jorgen Hansen <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0adfdb9 commit 62209d1

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

include/net/af_vsock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ struct vsock_sock {
6262
struct list_head pending_links;
6363
struct list_head accept_queue;
6464
bool rejected;
65-
struct delayed_work dwork;
65+
struct delayed_work connect_work;
66+
struct delayed_work pending_work;
6667
u32 peer_shutdown;
6768
bool sent_request;
6869
bool ignore_connecting_rst;
@@ -73,7 +74,6 @@ struct vsock_sock {
7374

7475
s64 vsock_stream_has_data(struct vsock_sock *vsk);
7576
s64 vsock_stream_has_space(struct vsock_sock *vsk);
76-
void vsock_pending_work(struct work_struct *work);
7777
struct sock *__vsock_create(struct net *net,
7878
struct socket *sock,
7979
struct sock *parent,

net/vmw_vsock/af_vsock.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,14 @@ static int vsock_send_shutdown(struct sock *sk, int mode)
430430
return transport->shutdown(vsock_sk(sk), mode);
431431
}
432432

433-
void vsock_pending_work(struct work_struct *work)
433+
static void vsock_pending_work(struct work_struct *work)
434434
{
435435
struct sock *sk;
436436
struct sock *listener;
437437
struct vsock_sock *vsk;
438438
bool cleanup;
439439

440-
vsk = container_of(work, struct vsock_sock, dwork.work);
440+
vsk = container_of(work, struct vsock_sock, pending_work.work);
441441
sk = sk_vsock(vsk);
442442
listener = vsk->listener;
443443
cleanup = true;
@@ -477,7 +477,6 @@ void vsock_pending_work(struct work_struct *work)
477477
sock_put(sk);
478478
sock_put(listener);
479479
}
480-
EXPORT_SYMBOL_GPL(vsock_pending_work);
481480

482481
/**** SOCKET OPERATIONS ****/
483482

@@ -576,6 +575,8 @@ static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr)
576575
return retval;
577576
}
578577

578+
static void vsock_connect_timeout(struct work_struct *work);
579+
579580
struct sock *__vsock_create(struct net *net,
580581
struct socket *sock,
581582
struct sock *parent,
@@ -618,6 +619,8 @@ struct sock *__vsock_create(struct net *net,
618619
vsk->sent_request = false;
619620
vsk->ignore_connecting_rst = false;
620621
vsk->peer_shutdown = 0;
622+
INIT_DELAYED_WORK(&vsk->connect_work, vsock_connect_timeout);
623+
INIT_DELAYED_WORK(&vsk->pending_work, vsock_pending_work);
621624

622625
psk = parent ? vsock_sk(parent) : NULL;
623626
if (parent) {
@@ -1094,7 +1097,7 @@ static void vsock_connect_timeout(struct work_struct *work)
10941097
struct sock *sk;
10951098
struct vsock_sock *vsk;
10961099

1097-
vsk = container_of(work, struct vsock_sock, dwork.work);
1100+
vsk = container_of(work, struct vsock_sock, connect_work.work);
10981101
sk = sk_vsock(vsk);
10991102

11001103
lock_sock(sk);
@@ -1195,9 +1198,7 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
11951198
* timeout fires.
11961199
*/
11971200
sock_hold(sk);
1198-
INIT_DELAYED_WORK(&vsk->dwork,
1199-
vsock_connect_timeout);
1200-
schedule_delayed_work(&vsk->dwork, timeout);
1201+
schedule_delayed_work(&vsk->connect_work, timeout);
12011202

12021203
/* Skip ahead to preserve error code set above. */
12031204
goto out_wait;

net/vmw_vsock/vmci_transport.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,7 @@ static int vmci_transport_recv_listen(struct sock *sk,
10991099
vpending->listener = sk;
11001100
sock_hold(sk);
11011101
sock_hold(pending);
1102-
INIT_DELAYED_WORK(&vpending->dwork, vsock_pending_work);
1103-
schedule_delayed_work(&vpending->dwork, HZ);
1102+
schedule_delayed_work(&vpending->pending_work, HZ);
11041103

11051104
out:
11061105
return err;

0 commit comments

Comments
 (0)