Skip to content

Commit 8dfddfb

Browse files
necipfazildavem330
authored andcommitted
net: qrtr: fix usage of idr in port assignment to socket
Passing large uint32 sockaddr_qrtr.port numbers for port allocation triggers a warning within idr_alloc() since the port number is cast to int, and thus interpreted as a negative number. This leads to the rejection of such valid port numbers in qrtr_port_assign() as idr_alloc() fails. To avoid the problem, switch to idr_alloc_u32() instead. Fixes: bdabad3 ("net: Add Qualcomm IPC router") Reported-by: [email protected] Signed-off-by: Necip Fazil Yildiran <[email protected]> Reviewed-by: Dmitry Vyukov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bcf7ddb commit 8dfddfb

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

net/qrtr/qrtr.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -692,23 +692,25 @@ static void qrtr_port_remove(struct qrtr_sock *ipc)
692692
*/
693693
static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)
694694
{
695+
u32 min_port;
695696
int rc;
696697

697698
mutex_lock(&qrtr_port_lock);
698699
if (!*port) {
699-
rc = idr_alloc(&qrtr_ports, ipc,
700-
QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET + 1,
701-
GFP_ATOMIC);
702-
if (rc >= 0)
703-
*port = rc;
700+
min_port = QRTR_MIN_EPH_SOCKET;
701+
rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, QRTR_MAX_EPH_SOCKET, GFP_ATOMIC);
702+
if (!rc)
703+
*port = min_port;
704704
} else if (*port < QRTR_MIN_EPH_SOCKET && !capable(CAP_NET_ADMIN)) {
705705
rc = -EACCES;
706706
} else if (*port == QRTR_PORT_CTRL) {
707-
rc = idr_alloc(&qrtr_ports, ipc, 0, 1, GFP_ATOMIC);
707+
min_port = 0;
708+
rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, 0, GFP_ATOMIC);
708709
} else {
709-
rc = idr_alloc(&qrtr_ports, ipc, *port, *port + 1, GFP_ATOMIC);
710-
if (rc >= 0)
711-
*port = rc;
710+
min_port = *port;
711+
rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, *port, GFP_ATOMIC);
712+
if (!rc)
713+
*port = min_port;
712714
}
713715
mutex_unlock(&qrtr_port_lock);
714716

0 commit comments

Comments
 (0)