mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] bugfix: invalid use of cb in io_thread after suspension of the thread
@ 2013-06-16  9:55 Jens Gustedt
  2013-06-16 14:38 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Jens Gustedt @ 2013-06-16  9:55 UTC (permalink / raw)
  To: musl

It seems that the buffer variable to which cb is pointing can be recycled
since long when the thread returns from the previous call to wake. At
least valgrind found that the address that cb was pointing to at line in
question hasn't been returned by malloc since long time before.

The fix is easy: the event structure has been copied onto the stack of
the thread, anyhow, so just use that copy.
---
 src/aio/aio_readwrite.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/aio/aio_readwrite.c b/src/aio/aio_readwrite.c
index e4c95aa..666372d 100644
--- a/src/aio/aio_readwrite.c
+++ b/src/aio/aio_readwrite.c
@@ -51,7 +51,7 @@ static void *io_thread(void *p)
 
 	__aio_wake();
 
-	switch (cb->aio_sigevent.sigev_notify) {
+	switch (sev.sigev_notify) {
 	case SIGEV_SIGNAL:
 		notify_signal(&sev);
 		break;
-- 
1.7.9.5



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] bugfix: invalid use of cb in io_thread after suspension of the thread
  2013-06-16  9:55 [PATCH] bugfix: invalid use of cb in io_thread after suspension of the thread Jens Gustedt
@ 2013-06-16 14:38 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2013-06-16 14:38 UTC (permalink / raw)
  To: musl

On Sun, Jun 16, 2013 at 11:55:22AM +0200, Jens Gustedt wrote:
> It seems that the buffer variable to which cb is pointing can be recycled
> since long when the thread returns from the previous call to wake. At

It's not just the call to wake. Accessing cb is invalid immediately
after the a_store to cb->__err.

> The fix is easy: the event structure has been copied onto the stack of
> the thread, anyhow, so just use that copy.

Agreed. I'm applying the fix.

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-06-16 14:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-16  9:55 [PATCH] bugfix: invalid use of cb in io_thread after suspension of the thread Jens Gustedt
2013-06-16 14:38 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).