* [PATCH] serial: qcom-geni: Fix off-by-one error in ida_alloc_range()
@ 2025-08-22 3:35 Zong Jiang
2025-08-22 4:46 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Zong Jiang @ 2025-08-22 3:35 UTC (permalink / raw)
To: gregkh, linux-serial, dan.carpenter
Cc: quic_ztu, quic_msavaliy, quic_vdadhani, quic_anupkulk,
quic_haixcui, Zong Jiang
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.
| 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>
---
drivers/tty/serial/qcom_geni_serial.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
index 9c7b1cea7cfe..0b474d349531 100644
--- a/drivers/tty/serial/qcom_geni_serial.c
+++ b/drivers/tty/serial/qcom_geni_serial.c
@@ -271,9 +271,11 @@ static struct qcom_geni_serial_port *get_port_from_line(int line, bool console,
int max_alias_num = of_alias_get_highest_id("serial");
if (line < 0 || line >= nr_ports)
- line = ida_alloc_range(&port_ida, max_alias_num + 1, nr_ports, GFP_KERNEL);
+ line = ida_alloc_range(&port_ida, max_alias_num + 1,
+ nr_ports - 1, GFP_KERNEL);
else
- line = ida_alloc_range(&port_ida, line, nr_ports, GFP_KERNEL);
+ line = ida_alloc_range(&port_ida, line,
+ nr_ports - 1, GFP_KERNEL);
if (line < 0)
return ERR_PTR(-ENXIO);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] serial: qcom-geni: Fix off-by-one error in ida_alloc_range()
2025-08-22 3:35 [PATCH] serial: qcom-geni: Fix off-by-one error in ida_alloc_range() Zong Jiang
@ 2025-08-22 4:46 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2025-08-22 4:46 UTC (permalink / raw)
To: Zong Jiang
Cc: linux-serial, dan.carpenter, quic_ztu, quic_msavaliy,
quic_vdadhani, quic_anupkulk, quic_haixcui
On Fri, Aug 22, 2025 at 11:35:32AM +0800, Zong Jiang wrote:
> 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.
>
> | 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/
Why do you have "| " here? Have you ever seen that in other kernel
commits?
> Signed-off-by: Zong Jiang <quic_zongjian@quicinc.com>
What commit id does this fix?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-22 4:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22 3:35 [PATCH] serial: qcom-geni: Fix off-by-one error in ida_alloc_range() Zong Jiang
2025-08-22 4:46 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).