Commit c6e08d62 authored by Chris Lew's avatar Chris Lew Committed by David S. Miller

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: 0c2204a4 ("net: qrtr: Migrate nameservice to kernel from userspace")
Signed-off-by: default avatarChris Lew <clew@codeaurora.org>
Reviewed-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e237659c
...@@ -712,6 +712,10 @@ void qrtr_ns_init(void) ...@@ -712,6 +712,10 @@ void qrtr_ns_init(void)
goto err_sock; goto err_sock;
} }
qrtr_ns.workqueue = alloc_workqueue("qrtr_ns_handler", WQ_UNBOUND, 1);
if (!qrtr_ns.workqueue)
goto err_sock;
qrtr_ns.sock->sk->sk_data_ready = qrtr_ns_data_ready; qrtr_ns.sock->sk->sk_data_ready = qrtr_ns_data_ready;
sq.sq_port = QRTR_PORT_CTRL; sq.sq_port = QRTR_PORT_CTRL;
...@@ -720,17 +724,13 @@ void qrtr_ns_init(void) ...@@ -720,17 +724,13 @@ void qrtr_ns_init(void)
ret = kernel_bind(qrtr_ns.sock, (struct sockaddr *)&sq, sizeof(sq)); ret = kernel_bind(qrtr_ns.sock, (struct sockaddr *)&sq, sizeof(sq));
if (ret < 0) { if (ret < 0) {
pr_err("failed to bind to socket\n"); pr_err("failed to bind to socket\n");
goto err_sock; goto err_wq;
} }
qrtr_ns.bcast_sq.sq_family = AF_QIPCRTR; qrtr_ns.bcast_sq.sq_family = AF_QIPCRTR;
qrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST; qrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST;
qrtr_ns.bcast_sq.sq_port = QRTR_PORT_CTRL; qrtr_ns.bcast_sq.sq_port = QRTR_PORT_CTRL;
qrtr_ns.workqueue = alloc_workqueue("qrtr_ns_handler", WQ_UNBOUND, 1);
if (!qrtr_ns.workqueue)
goto err_sock;
ret = say_hello(&qrtr_ns.bcast_sq); ret = say_hello(&qrtr_ns.bcast_sq);
if (ret < 0) if (ret < 0)
goto err_wq; goto err_wq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment