]> xenbits.xensource.com Git - people/royger/linux-2.6.18-xen.git/commit
netfront: plug a theoretical leak on setup_device()'s error path
authorLaszlo Ersek <lersek@redhat.com>
Thu, 26 May 2011 07:07:05 +0000 (08:07 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Thu, 26 May 2011 07:07:05 +0000 (08:07 +0100)
commit13cdcd12a2feb7704c1baa8e3825aa7df6e090e1
treeb2ae648e4fc1dc6409b0cbbc404ac4d2377ca1af
parent140c5ce272c6a9f1324a0cb90d6a3b732df86d62
netfront: plug a theoretical leak on setup_device()'s error path

Suppose the frontend is in XenbusStateInitialising and the backend
advances to XenbusStateInitWait. backend_changed() will call
network_connect() -> talk_to_backend() -> setup_device().

If bind_listening_port_to_irqhandler() fails (due to event channel
allocation failure, dynamic IRQ allocation failure etc), then the
grant references and the shared ring pages remain allocated. The error
percolates back to backend_changed() without any cleanup.
backend_changed() will not change the frontend state; it will stay in
XenbusStateInitialising. If the backend retries XenbusStateInitWait
(possibly through a fake, no-op mediate state, like
XenbusStateClosed), then the frontend repeats the above call chain and
leaks the previously unreleased ring pages and grant references.

If setup_device() fails to grant access to the RX page before it tries
to call bind_listening_port_to_irqhandler(), then only the TX page /
grant reference are leaked in the next round.

I'm not sure what happens when the RX page allocation fails:
xenbus_dev_fatal() is called then, which changes the frontend's state
and seems to preclude a second immediate call to network_connect(). I
think this patch shouldn't hurt in that case either (or after
earlier failures in setup_device() for that matter).

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
drivers/xen/netfront/netfront.c