diff options
author | Steven Luo <steven+qemu@steven676.net> | 2016-04-06 22:04:32 -0700 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2016-04-07 10:27:42 +0200 |
commit | bfb1ac14029ee72b19296109fba880c0551755d5 (patch) | |
tree | 270d62cb3221dc7f5353f8e7d5198ec1d98fb295 /slirp/slirp.c | |
parent | b5ab677189b93efa4eaa921f42b21dc008247184 (diff) | |
download | qemu-bfb1ac14029ee72b19296109fba880c0551755d5.tar.gz qemu-bfb1ac14029ee72b19296109fba880c0551755d5.tar.bz2 qemu-bfb1ac14029ee72b19296109fba880c0551755d5.zip |
slirp: avoid use-after-free in slirp_pollfds_poll() if soread() returns an error
Samuel Thibault pointed out that it's possible that slirp_pollfds_poll()
will try to use a socket even after soread() returns an error, resulting
in an use-after-free if the socket was removed while handling the error.
Avoid this by refusing to continue to work with the socket in this case.
Signed-off-by: Steven Luo <steven+qemu@steven676.net>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'slirp/slirp.c')
-rw-r--r-- | slirp/slirp.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/slirp/slirp.c b/slirp/slirp.c index fef526c5ad..9f4bea3d3b 100644 --- a/slirp/slirp.c +++ b/slirp/slirp.c @@ -534,7 +534,12 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error) * test for G_IO_IN below if this succeeds */ if (revents & G_IO_PRI) { - sorecvoob(so); + ret = sorecvoob(so); + if (ret < 0) { + /* Socket error might have resulted in the socket being + * removed, do not try to do anything more with it. */ + continue; + } } /* * Check sockets for reading @@ -553,6 +558,11 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error) if (ret > 0) { tcp_output(sototcpcb(so)); } + if (ret < 0) { + /* Socket error might have resulted in the socket being + * removed, do not try to do anything more with it. */ + continue; + } } /* |