In the recent years, there has been an explosive growth of smart devices applications with high computational demands and critical latency. The Internet of Things (IoT) multi-access edge computing (MEC) framework offers a lower latency and a higher speed to the users, by offloading the cloud computing capabilities at the nearest edge of the mobile network. In this operating scenario, the proper allocation of limited resources is one of the biggest challenges, and security is becoming vital as the number of devices in an IoT network tends to billions. According to recent studies, even authorized edge devices may be a significant threat for IoT networks (i.e., selfish behavior), as a result of mixed service structures with a wide range of different requirements. Thus, this work proposes a novel two-fold method to allocate resources and then identify attackers (selfish IoT malicious devices) by means of a reputation-based stable matching policy. The devices are categorized in three different states, namely honest, suspicious, and malicious states, according to their reputation indices. Our algorithm allows to move the devices between the three states, in order to exclude malicious devices and to rehabilitate users identified as unintentional attackers (due to bad propagation conditions). Theoretical and simulation results confirm the validity and effectiveness of such approach for identifying malicious IoT devices in MEC networks.