Re: a question on i386 copy_thread()

Bryn Paul Arnold Jones (bpaj@gytha.demon.co.uk)
Sun, 6 Apr 1997 19:03:09 +0100 (BST)


On Sun, 6 Apr 1997, Ray Lehtiniemi wrote:

>
> hi all
>
> i'm still working my way through sys_fork() here. i have a question about
> the following code in arch/i386/kernel/process.c:copy_thread().
>
> if (p->ldt) {
> p->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE);
> if (p->ldt != NULL)
> memcpy(p->ldt, current->ldt, LDT_ENTRIES*LDT_ENTRY_SIZE);
> }
>
> i assume the fact we're overwriting p->ldt is because the pointer was
> copied from our parent earlier in the fork, and we're now creating our own
> ldt instead of pointing to the parents ldt.
>
> my question is:
>
> what happens if the vmalloc fails?
>
> the code appears to use &default_ldt if p->ldt is NULL. however, my
> understanding of LDT is that it tells you the base and size of all your
> memory segments. if we're a duplicate of our parent, except our ldts are
> completely different, really bad things will happen, no?
>

Nope, if the vmalloc fails, p->ldt would be NULL (hence the test that it
isn't), and the next time we try to do anything with it, we'll have a NULL
pointer dereferance.

> Ray Lehtiniemi <rayl@crosskeys.com>
>
Bryn

--
PGP key pass phrase forgotten,   \ Overload -- core meltdown sequence 
again :( and I don't care ;)      |            initiated.
                                 / This space is intentionally left   
                                |  blank, apart from this text ;-)
                                 \____________________________________