Considering the influence of slope sections and random degradation of the communication function of cooperative adaptive cruise control vehicles and the effect of the cooperative adaptive cruise control vehicle group driving, a linear stability criterion for heterogeneous traffic flow composed of cooperative adaptive cruise control vehicles and humanly-driven vehicles on slopes is derived, and a parameter sensitivity analysis is carried out. On this foundation, the safety of traffic flow on two-lane roads up and down hills is simulated while considering the lane-changing behavior of automobiles. The stability study shows increased cooperative adaptive cruise control vehicle penetration and uphill gradient will help improve traffic flow stability. In contrast, the increase in the downhill slope will intensify the transmission amplitude of the disturbance. When vehicle starting sensitivity is 2.5, and the gradient is 60, the minimum cooperative adaptive cruise control vehicle penetration required for mixed traffic flow to maintain stability on a downhill at any initial equilibrium speed is 85%, and the minimum penetration required on an uphill is 73%, and this proportion decreases with the increase in the uphill gradient and increases with the rise in the downhill slope. According to the safety study, increasing cooperative adaptive cruise control vehicle penetration and implementing lane-changing rules will improve traffic flow safety. Compared with the straight section, under the same conditions, the traffic flow safety of the uphill section is the best, and the safety of the downhill section is poor, which is consistent with the stability analysis results. This study is of great significance for future traffic control strategies for mountain roads.