9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Yoann Padioleau <pad@fb.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: [9fans] kernel possible double free
Date: Mon,  9 Jun 2014 07:40:27 +0000	[thread overview]
Message-ID: <2D698F12-5C4C-4F49-A976-46592D9592CE@fb.com> (raw)

Hi,

I think I've found a possible situation where we call two times free on the same pointer.
in sysexec() there is essentially

sysexec(...) {
 … 
	if(waserror()){
		free(file0);
		free(elem);
		nexterror();
	}

	for(;;){
		tc = namec(file, Aopen, OEXEC, 0);
		if(waserror()){
			cclose(tc);
			nexterror();
		}

        …
       }
	qlock(&up->seglock);
	if(waserror()){
		qunlock(&up->seglock);
		nexterror();
	}

     …
	free(file0);
+      file0 = nil; <------------------------- we should add that, for the same reason we do elem = nil below
	free(up->text);
	up->text = elem;
	elem = nil;	/* so waserror() won't free elem */
	USED(elem);

    …
	qunlock(&up->seglock);
	poperror();	/* seglock */
-	poperror();	/* elem */ <----------------------- actually this is not the poperror of elem, but of tc

        …
	poperror();
	cclose(tc);
+      poperror(); /* elem and file0 */ <----------- this is where the poperror of elem should be.


}


             reply	other threads:[~2014-06-09  7:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09  7:40 Yoann Padioleau [this message]
2014-06-09  8:18 ` Charles Forsyth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2D698F12-5C4C-4F49-A976-46592D9592CE@fb.com \
    --to=pad@fb.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).