How is the search-and-rescue system for civil aviation over waters agreed and funded?
Search and Rescue is under the ICAO umbrella, but also with the IMO. 

Annex 12 to the Convention on International Civil Aviation gives the international standards and recommended practices (SARPS) on Search and Rescue. 
The annex is supplemented by the International Aeronautical and Maritime Search and Rescue (IAMSAR) Manual, which is published by the International Maritime Organisation (IMO)

Together the documents describe:


The organisational structure of the worldwide SAR system concept,
including cooperation between states. (ICAO Annex 12, chapter 2, 3 &amp;
4, IAMSAR volume 1)
The operating procedures for organising and coordinating a SAR
mission (ICAO Annex 12, chapter 5, IAMSAR volume 2)
The operating procedures for those carrying participating in the SAR
mission (Appendix to ICAO Annex 12,  IAMSAR volume 3/ ICAO doc. 9731)


The details of implementing the SARPS are left to the states themselves.