Skip to contentSkip to conversation

hte: fix off by one in hte_push_ts_ns()

PATCH In review Dan Carpenter 2 participants 4 messages May 6, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 hte: fix off by one in hte_push_ts_ns()

The &chip->gdev->ei[] array has chip->nlines elements so this > comparison needs to be >= to prevent an out of bounds access. The gdev->ei[] array is allocated in hte_register_chip().

Fixes 31ab09b42188 ("drivers: Add hardware timestamp engine (HTE) subsystem")
---
 drivers/hte/hte.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hte/hte.c +1 -1
index 891b98ad609e..a14c5bf290ff 100644
@@ -811,7 +811,7 @@ int hte_push_ts_ns(const struct hte_chip *chip, u32 xlated_id,
 	if (!chip || !data || !chip->gdev)
 		return -EINVAL;
 
-	if (xlated_id > chip->nlines)
+	if (xlated_id >= chip->nlines)
 		return -EINVAL;
 
 	ei = &chip->gdev->ei[xlated_id];
Signature · 1 line
2.35.1
#1 lore raw

PATCH 2/2 hte: uninitialized variable in hte_ts_get()

The "free_name" variable is sometimes used without being initialized.

31ab09b42188 ("drivers: Add hardware timestamp engine (HTE) subsystem")

---
 drivers/hte/hte.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hte/hte.c +1 -1
index a14c5bf290ff..7c3b4476f890 100644
@@ -572,7 +572,7 @@ int hte_ts_get(struct device *dev, struct hte_ts_desc *desc, int index)
 	struct of_phandle_args args;
 	u32 xlated_id;
 	int ret;
-	bool free_name;
+	bool free_name = false;
 
 	if (!desc)
 		return -EINVAL;
Signature · 1 line
2.35.1
maintainer Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] hte: uninitialized variable in hte_ts_get()

Acked-by Dipen Patel
Quoted 21 lines · Dan Carpenter

The "free_name" variable is sometimes used without being initialized.

31ab09b42188 ("drivers: Add hardware timestamp engine (HTE) subsystem")

---
 drivers/hte/hte.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hte/hte.c +1 -1
index a14c5bf290ff..7c3b4476f890 100644
@@ -572,7 +572,7 @@ int hte_ts_get(struct device *dev, struct hte_ts_desc *desc, int index)
 	struct of_phandle_args args;
 	u32 xlated_id;
 	int ret;
-	bool free_name;
+	bool free_name = false;
 
 	if (!desc)
 		return -EINVAL;
maintainer Reviewed-by Acked-by on v1 1/2
#3 lore raw
In reply to Dan Carpenter

good catch. Thanks.

Reviewed-by Dipen Patel
Acked-by Dipen Patel
Quoted 23 lines · Dan Carpenter

The &chip->gdev->ei[] array has chip->nlines elements so this > comparison needs to be >= to prevent an out of bounds access. The gdev->ei[] array is allocated in hte_register_chip().

Fixes 31ab09b42188 ("drivers: Add hardware timestamp engine (HTE) subsystem")
---
 drivers/hte/hte.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hte/hte.c +1 -1
index 891b98ad609e..a14c5bf290ff 100644
@@ -811,7 +811,7 @@ int hte_push_ts_ns(const struct hte_chip *chip, u32 xlated_id,
 	if (!chip || !data || !chip->gdev)
 		return -EINVAL;
 
-	if (xlated_id > chip->nlines)
+	if (xlated_id >= chip->nlines)
 		return -EINVAL;
 
 	ei = &chip->gdev->ei[xlated_id];