[][Add hnat entry index sanity check]

[Description]
Add sanity check for hnat entry index

[Release-log]
N/A

Change-Id: I6826a8449c311e8304b0bb09d51ae594a6d115b3
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/4734416
diff --git a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c
index 6b04570..8f395f8 100644
--- a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c
+++ b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c
@@ -340,6 +340,11 @@
 	if (ppe_id >= CFG_PPE_NUM)
 		return -EINVAL;
 
+	if (index < 0 || index >= h->foe_etry_num) {
+		pr_info("Invalid entry index\n");
+		return -EINVAL;
+	}
+
 	entry = h->foe_table_cpu[ppe_id] + index;
 	saddr = htonl(entry->ipv4_hnapt.sip);
 	daddr = htonl(entry->ipv4_hnapt.dip);
@@ -522,6 +527,11 @@
 	if (ppe_id >= CFG_PPE_NUM)
 		return -EINVAL;
 
+	if (index < 0 || index >= h->foe_etry_num) {
+		pr_info("Invalid entry index\n");
+		return -EINVAL;
+	}
+
 	entry = h->foe_table_cpu[ppe_id] + index;
 	memset(entry, 0, sizeof(struct foe_entry));
 
@@ -1929,6 +1939,11 @@
 	if (ppe_id >= CFG_PPE_NUM)
 		return -1;
 
+	if (index < 0 || index >= h->foe_etry_num) {
+		pr_info("Invalid entry index\n");
+		return -EINVAL;
+	}
+
 	acount = hnat_get_count(h, ppe_id, index);
 	entry = hnat_priv->foe_table_cpu[ppe_id] + index;
 
@@ -1952,6 +1967,11 @@
 	if (ppe_id >= CFG_PPE_NUM)
 		return -1;
 
+	if (index < 0 || index >= h->foe_etry_num) {
+		pr_info("Invalid entry index\n");
+		return -EINVAL;
+	}
+
 	entry = hnat_priv->foe_table_cpu[ppe_id] + index;
 
 	return entry->bfib1.state == BIND;