mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Ludloff <ludloff@gmail.com>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alexandre <alexramos25.pt@gmail.com>,
	x86@kernel.org, tglx@kernel.org,  mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com,  linux-kernel@vger.kernel.org
Subject: Re: X86: Question about GDT loading
Date: Mon, 17 Aug 2026 02:15:37 -0700	[thread overview]
Message-ID: <CAKSQd8UcsHan18TdMuj9FNBqLyGre-ea7iFnZwt3wfjjnBzf3g@mail.gmail.com> (raw)

>> It is intended. Slot 0 in the GDT is not used, so it is a pretty common
>> convention to stuff the pointer to the GDT itself into that slot.
>>
>> For 32 bits that is perfectly safe. On 64 bits, it ends up taking up slot 1 as
>> well; this is *not* safe for a kernel address as it would be interpreted as a
>> user-space code descriptor for a single-byte code segment somewhere in the low
>> 16 MB of memory, addressable as 0x13:0. This could be used to derive bits
>> [55:32] of the kernel GDT base from user space.
>
> Corrected: addressable as 0xb:0.
>
>> Therefore this must NOT be done in 64-bit mode.
>
> Formally speaking: long mode.

A mixed-mode GDT can safely place a task gate descriptor
at GDT offset 8 though, because the first two bytes of it are
reserved/ignored (in legacy mode) and because task gates
are no longer used/supported (in long mode).

    https://www.sandpile.org/x86/desc.htm

So the technique still works... if GDTR base [63:32] is zero;
else two copies of the GDT end up being used (assuming a
LGDT in legacy mode, then a mode switch, then a LGDT in
long mode again [to load the upper base bits]).

The technique itself does go back at least to the early '90s:

    https://www.rcollins.org/Productivity/NullDescriptor.html

--
C.

             reply	other threads:[~2026-08-17  9:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  9:15 Christian Ludloff [this message]
     [not found] <CAKw2PKGZwJbK2=c+nYz1SgLsPCqF=r_UMK4vRWQ-ZDVW2HiKfw@mail.gmail.com>
2026-08-16 21:12 ` H. Peter Anvin
2026-08-16 21:15   ` H. Peter Anvin
  -- strict thread matches above, loose matches on Subject: below --
2026-08-16 20:58 Alexandre
2026-08-16 21:17 ` Brian Gerst

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=CAKSQd8UcsHan18TdMuj9FNBqLyGre-ea7iFnZwt3wfjjnBzf3g@mail.gmail.com \
    --to=ludloff@gmail.com \
    --cc=alexramos25.pt@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@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

all inboxes | Powered by JetHome®