Skip to content

Commit c6e08d6

Browse files
Chris Lewdavem330
authored andcommitted
net: qrtr: Allocate workqueue before kernel_bind
A null pointer dereference in qrtr_ns_data_ready() is seen if a client opens a qrtr socket before qrtr_ns_init() can bind to the control port. When the control port is bound, the ENETRESET error will be broadcasted and clients will close their sockets. This results in DEL_CLIENT packets being sent to the ns and qrtr_ns_data_ready() being called without the workqueue being allocated. Allocate the workqueue before setting sk_data_ready and binding to the control port. This ensures that the work and workqueue structs are allocated and initialized before qrtr_ns_data_ready can be called. Fixes: 0c2204a ("net: qrtr: Migrate nameservice to kernel from userspace") Signed-off-by: Chris Lew <[email protected]> Reviewed-by: Bjorn Andersson <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e237659 commit c6e08d6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

net/qrtr/ns.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,10 @@ void qrtr_ns_init(void)
712712
goto err_sock;
713713
}
714714

715+
qrtr_ns.workqueue = alloc_workqueue("qrtr_ns_handler", WQ_UNBOUND, 1);
716+
if (!qrtr_ns.workqueue)
717+
goto err_sock;
718+
715719
qrtr_ns.sock->sk->sk_data_ready = qrtr_ns_data_ready;
716720

717721
sq.sq_port = QRTR_PORT_CTRL;
@@ -720,17 +724,13 @@ void qrtr_ns_init(void)
720724
ret = kernel_bind(qrtr_ns.sock, (struct sockaddr *)&sq, sizeof(sq));
721725
if (ret < 0) {
722726
pr_err("failed to bind to socket\n");
723-
goto err_sock;
727+
goto err_wq;
724728
}
725729

726730
qrtr_ns.bcast_sq.sq_family = AF_QIPCRTR;
727731
qrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST;
728732
qrtr_ns.bcast_sq.sq_port = QRTR_PORT_CTRL;
729733

730-
qrtr_ns.workqueue = alloc_workqueue("qrtr_ns_handler", WQ_UNBOUND, 1);
731-
if (!qrtr_ns.workqueue)
732-
goto err_sock;
733-
734734
ret = say_hello(&qrtr_ns.bcast_sq);
735735
if (ret < 0)
736736
goto err_wq;

0 commit comments

Comments
 (0)