nfp: Fix a potential out-of-bound access

Message ID 1630633435-39085-1-git-send-email-yinjun.zhang@corigine.com
State New
Headers show
Series
  • nfp: Fix a potential out-of-bound access
Related show

Commit Message

Yinjun Zhang Sept. 3, 2021, 1:43 a.m.
Add necessary sanity check.

Reported-by: Alan Modra <amodra@gmail.com>
Signed-off-by: Yinjun Zhang <yinjun.zhang@corigine.com>

Signed-off-by: Simon Horman <simon.horman@corigine.com>

---
 opcodes/nfp-dis.c | 3 +++
 1 file changed, 3 insertions(+)

-- 
2.27.0

Comments

H.J. Lu via Binutils Sept. 6, 2021, 9:45 a.m. | #1
Hi Yinjun Zhang,

> Add necessary sanity check.


Patch approved and applied.

Cheers
   Nick

Patch

diff --git a/opcodes/nfp-dis.c b/opcodes/nfp-dis.c
index 170f6a2d63e..88db34cac10 100644
--- a/opcodes/nfp-dis.c
+++ b/opcodes/nfp-dis.c
@@ -2644,6 +2644,9 @@  init_nfp6000_mecsr_sec (nfp_priv_data * priv, Elf_Internal_Shdr * sec,
       menum = _BF (ireg.cpp_offset_lo, 13, 10) - 4;
       csr_off = _BF (ireg.cpp_offset_lo, 9, 0);
 
+      if (menum >= _NFP_ME_MAX)
+	return false;
+
       mecfg = &priv->mecfgs[isl][menum][is_for_text];
       switch (csr_off)
 	{