public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Don Dugger <n0ano@valinux.com>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: [PATCH] Bug in kernel/fork.c in 2.4.4 kernel
Date: Wed, 2 May 2001 15:37:01 -0600	[thread overview]
Message-ID: <20010502153701.A6830@tlaloc.n0ano.com> (raw)

In working on thread core dumps I've stumbled across a minor bug in the
generic `fork' code.  The problem code is in routine `copy_mm' in
`kernel/fork.c':

	/* Copy the current MM stuff.. */
        memcpy(mm, oldmm, sizeof(*mm));
	  .
	  .
	  .
        if (retval)
                goto free_pt;

        /*
         * child gets a private LDT (if there was an LDT in the parent)
         */
        copy_segments(tsk, mm);
	  .
	  .
	  .
free_pt:
	mmput(mm);

The new `mm' doesn't get it's own private version of it's `context'
field until after the call to `copy_segments'.  At the `goto' the pointer
`mm' points to a copy of the old `mm_struct', including a copy of the
`context' field.  `mmput' will call `release_segments' which will free
the memory pointed to by the `context' field.  Later, when `oldmm' is
freed, the kernel will try to free the same memory twice - very bad.

Admittedly, this will only occur on an obscure error condition but
it should be fixed.  The attached patch fixes the problem by zeroing
out the `context' field immediately after the `mm' structure is
copied.
-- 
Don Dugger
"Censeo Toto nos in Kansa esse decisse." - D. Gale
n0ano@valinux.com
Ph: 303/938-9838


--- linux-2.4.4-ref/kernel/fork.c	Thu Apr 26 07:11:17 2001
+++ linux/kernel/fork.c	Wed May  2 14:39:38 2001
@@ -311,6 +311,10 @@
 
 	/* Copy the current MM stuff.. */
 	memcpy(mm, oldmm, sizeof(*mm));
+
+	/* Clear new context for now */
+	memset(&mm->context, 0, sizeof(mm->context));
+
 	if (!mm_init(mm))
 		goto fail_nomem;
 

                 reply	other threads:[~2001-05-02 21:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20010502153701.A6830@tlaloc.n0ano.com \
    --to=n0ano@valinux.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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