net: qrtr: Change port allocation to use cyclic xa

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 these lookup packets.

Change the xa_alloc to xa_alloc_cyclic so new ids are allocated
instead of trying to reuse the freed ids.

Change-Id: Ie1bda7a818309503f80542e739bac646327296f7
Signed-off-by: Chris Lew <quic_clew@quicinc.com>
This commit is contained in:
Chris Lew 2022-10-03 09:57:42 -07:00
parent 20cca07151
commit 9edfe6657f

View File

@ -117,6 +117,7 @@ static DECLARE_RWSEM(qrtr_node_lock);
/* local port allocation management */
static DEFINE_XARRAY_ALLOC(qrtr_ports);
u32 qrtr_ports_next = QRTR_MIN_EPH_SOCKET;
/**
* struct qrtr_node - endpoint node
@ -802,8 +803,9 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)
int rc;
if (!*port) {
rc = xa_alloc(&qrtr_ports, port, ipc, QRTR_EPH_PORT_RANGE,
GFP_KERNEL);
rc = xa_alloc_cyclic(&qrtr_ports, port, ipc,
QRTR_EPH_PORT_RANGE, &qrtr_ports_next,
GFP_KERNEL);
} else if (*port < QRTR_MIN_EPH_SOCKET && !capable(CAP_NET_ADMIN)) {
rc = -EACCES;
} else if (*port == QRTR_PORT_CTRL) {