Crowdsensing has emerged as a promising data collection paradigm for utilizing embedded sensors in mobile devices to monitor the real world. However, due to the existence of malicious users, data quality problem has become a critical issue in the crowdsensing system. To address this problem, many mechanisms have been proposed to improve the quality of submitted observations, which are either not cost-efficient enough to be widely applied or only compatible with limited applications. In this paper, we propose an efficient malicious user detection method based on the Hidden Markov Model. It takes users’ observations as input and reports malicious users with the assistance of a pre-detection phase. We further incorporate the proposed detection method into task allocation, presenting an anti-malicious task allocation mechanism. The experimental results reveal that the proposed detection algorithm can identify malicious users with high accuracy and F1-Score. The proposed allocation algorithm also can significantly prevent malicious users from taking assignments, which eventually improves data quality.