From: Gabriel Paubert <paubert@iram.es>
To: Chuck Ebbert <76306.1226@compuserve.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: desc v0.61 found a 2.5 kernel bug
Date: Wed, 30 Apr 2003 19:10:56 +0200 [thread overview]
Message-ID: <20030430171056.GA4475@iram.es> (raw)
In-Reply-To: <200304292234_MC3-1-369F-3000@compuserve.com>
On Tue, Apr 29, 2003 at 10:33:09PM -0400, Chuck Ebbert wrote:
> Gabriel Paubert wrote:
>
> >> And shouldn't CR3 be intitialized in case anyone actually wants to
> >> switch back to the kernel TSS?
> >
> > For now no, since the only task gate ever taken (double fault), never
> > returns (you don't want to update the TSS's CR3 field on every
> > switch_to() so you would have to do it in the task gate return
> > path, as well as having a correct LDT field).
>
> I want to write a TSS-based debug exception handler that just does
> an iret when it gets invoked. For now it looks easier to just keep
> CR3 up-to-date on every switch.
It seems cr3 is in the same cache line as esp0 for a 32 byte cache line,
so it's not that big a deal, but I'd still try to avoid this.
>
> > However, returning from a task gate is so much fraught with races wrt
> > segment registers that the best thing to do is to avoid it.
>
> Even with interrupts off?
Yes. Consider the following:
create an LDT entry
load the segment to %fs
clear the LDT entry (or mark it non present),
-> %fs is now stale but still marked valid
...(no task switch)
Interrupt handled through task gate
-> stale selector written to TSS
...(interrupt handler)
iret-> TS/NP/SF exception when loading segments in the
new task (I believe it can't be GP)
Of course on an SMP machine with shared LDT, there are even more
ways of triggering segment related exceptions.
Currently %fs and %gs are lazily cleaned up when switching processes
using the standard fixup mechanism, %ds and %es are cleaned up if
necessary when popping them off the stack in the return to user
mode path (the one which ends up in iret). There is no way to recover
from bad user %cs/%ss, the process simply exits in the iret fixup.
But this works only because you can put a specific fixup for each
instruction which loads a given segment register (or two for iret).
In an iret from a task gate, you don't have this fine grained control
(all registers are loaded at once and then checked one by one)
and the return address is unpredictable, so the fixup mechanism is out.
This does not mean that there is no way to safely return from an
interrupt handled through a task gate, but it's not simple (you
don't want to change the existing lazy cleanup mechanism which is
about as simple and low overhead as it gets for the common cases).
Gabriel
next prev parent reply other threads:[~2003-04-30 17:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-30 2:33 desc v0.61 found a 2.5 kernel bug Chuck Ebbert
2003-04-30 17:10 ` Gabriel Paubert [this message]
-- strict thread matches above, loose matches on Subject: below --
2003-05-11 3:50 Chuck Ebbert
2003-05-11 17:22 ` paubert
2003-05-09 8:58 Chuck Ebbert
2003-04-30 20:08 Chuck Ebbert
2003-05-08 22:54 ` paubert
2003-04-27 21:09 Chuck Ebbert
2003-04-28 10:34 ` Gabriel Paubert
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=20030430171056.GA4475@iram.es \
--to=paubert@iram.es \
--cc=76306.1226@compuserve.com \
--cc=linux-kernel@vger.kernel.org \
/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