Skip to content

Commit 94fcae6

Browse files
Zong Jianggregkh
authored andcommitted
serial: qcom-geni: Fix off-by-one error in ida_alloc_range()
The ida_alloc_range() function expects an inclusive range, meaning both the start and end values are valid allocation targets. Passing nr_ports as the upper bound allows allocation of an ID equal to nr_ports, which is out of bounds when used as an index into the port array. Fix this by subtracting 1 from nr_ports in both calls to ida_alloc_range(), ensuring the allocated ID stays within the valid range [start, nr_ports - 1]. This prevents potential out-of-bounds access when the allocated ID is used as an index. Fixes: 9391ab1 ("serial: qcom-geni: Make UART port count configurable via Kconfig") Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/r/202508180815.R2nDyajs-lkp@intel.com/ Signed-off-by: Zong Jiang <quic_zongjian@quicinc.com> Link: https://lore.kernel.org/r/20250827120319.1682835-1-quic_zongjian@quicinc.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e3fa89f commit 94fcae6

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/tty/serial/qcom_geni_serial.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,11 @@ static struct qcom_geni_serial_port *get_port_from_line(int line, bool console,
271271
int max_alias_num = of_alias_get_highest_id("serial");
272272

273273
if (line < 0 || line >= nr_ports)
274-
line = ida_alloc_range(&port_ida, max_alias_num + 1, nr_ports, GFP_KERNEL);
274+
line = ida_alloc_range(&port_ida, max_alias_num + 1,
275+
nr_ports - 1, GFP_KERNEL);
275276
else
276-
line = ida_alloc_range(&port_ida, line, nr_ports, GFP_KERNEL);
277+
line = ida_alloc_range(&port_ida, line,
278+
nr_ports - 1, GFP_KERNEL);
277279

278280
if (line < 0)
279281
return ERR_PTR(-ENXIO);

0 commit comments

Comments
 (0)