If a cookie is set without specifying the domain property, the browser associates it with the domain from which it was set.
If you want to set a cookie -- including the cookie that's used to hold a session ID -- with all subdomains, you would need to set the domain property to ".domain.com" -- note the leading dot, which allows the browser to match any domain that ends with domain.com.
Having said that, a better solution is to force users to one domain or the other, and to not allow both (perhaps by redirecting from one to the other). If you do allow both, then the user can end up downloading cacheable objects more than once, instead of using them from cache.