If your passport is going to expire while you are in Canada, you should apply to extend it at the embassy or consulate of your home country in Canada no later than six months before  expiry.  The expiry of your study permit and Temporary Resident Visa (TRV) would not exceed the expiry of your passport; therefore, it is very important that you plan ahead.  Click here for a list of embassies or consular offices in Canada.  You will need to call, check the website, or visit the office (if applicable) for instructions on how to extend your passport.