From 06809f9816f227d6622cb8697ddf7c2c11ed7349 Mon Sep 17 00:00:00 2001 From: Chris Lew Date: Fri, 7 Sep 2018 12:27:00 -0700 Subject: [PATCH] net: qrtr: Change port allocation to use cyclic idr There is a race for clients that open sockets before the control port is bound. If a client gets an idr that was allocated before the control port is bound, there is a chance the previous address owner sent lookup packets to the control port. The new address owner will get residual responses to this the lookup packets. Change the idr_alloc to idr_alloc_cyclic so new idr's are allocated instead of trying to reuse the freed idrs. Change-Id: Ie1bda7a818309503f80542e739bac646327296f7 Signed-off-by: Chris Lew --- net/qrtr/qrtr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index bba9972abd75..258c7a10ef0a 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -759,9 +759,8 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) mutex_lock(&qrtr_port_lock); if (!*port) { - rc = idr_alloc(&qrtr_ports, ipc, - QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET + 1, - GFP_ATOMIC); + rc = idr_alloc_cyclic(&qrtr_ports, ipc, QRTR_MIN_EPH_SOCKET, + QRTR_MAX_EPH_SOCKET + 1, GFP_ATOMIC); if (rc >= 0) *port = rc; } else if (*port < QRTR_MIN_EPH_SOCKET && !capable(CAP_NET_ADMIN)) { @@ -769,7 +768,8 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) } else if (*port == QRTR_PORT_CTRL) { rc = idr_alloc(&qrtr_ports, ipc, 0, 1, GFP_ATOMIC); } else { - rc = idr_alloc(&qrtr_ports, ipc, *port, *port + 1, GFP_ATOMIC); + rc = idr_alloc_cyclic(&qrtr_ports, ipc, *port, *port + 1, + GFP_ATOMIC); if (rc >= 0) *port = rc; }