In many core problems of signal processing and wireless communications, Karush-Kuhn-Tucker (KKT) conditions based optimization plays a fundamental role. Hence we investigate the KKT conditions in the context of optimizing positive semidefinite matrix variables under nonconvex rank constraints. More explicitly, based on the properties of KKT conditions, we optimize a reconfigurable intelligent surface (RIS) aided multi-user multi-input multi-output (MU-MIMO) network. Specifically, we consider the capacity maximization and sum mean square error (MSE) minimization problems of both the RIS-aided MU-MIMO uplink (UL) and downlink (DL) under multiple weighted power constraints and rank constraints. As for the RIS-aided MU-MIMO UL, the optimal structures of the signal covariance matrices are derived based on the KKT conditions. Furthermore, an efficient procedure is designed for solving the capacity maximization and sum mean square error (MSE) minimization problems. Then the UL-DL dualities are exploited for solving the capacity maximization and MSE minimization problems of the RIS-aided MU-MIMO DL based on the results of the UL optimization. Hence in the proposed framework, the phase shifting matrix of the RIS is jointly optimized with the signal covariance matrices for both the UL and DL. Our simulation results demonstrate the performance advantages of the proposed framework.