Re: Using x86 segments against NULL pointer deference exploit

From: H. Peter Anvin
Date: Fri Nov 06 2009 - 17:54:42 EST


On 11/06/2009 04:59 AM, castet.matthieu@xxxxxxx wrote:
> Hi,
>
> I am wondering why we can't set the KERNEL_DS data segment to not contain the
> first page, ie changing it from R/W flat model to R/W expand down from
> 0xffffffff to 4096.
>
> The modification seems simple : change GDT_ENTRY_KERNEL_DS [1], and some
> modification for syscall entry point that doesn't support segment (sysenter).
>
> The drawback of this it that the kernel can't access anymore data in the first
> segment. Is it needed for application like wine or dosemu ?
>

Yes, it is. On 32 bits it is possible to switch around segments and do
this (in which case you want it to only cover the actual kernel area,
and use USER_DS for all user-space references.) This also lets you drop
nearly all pointer-range checks, since they are now redundant. However,
there is a cost -- it pretty much requires a segment register for
USER_DS (this used to be fs once upon a time, hence set_fs) and probably
would break Xen and possibly other virtualization solutions.

> PS : why x86_64 segment got access bit set and x86_32 doesn't ?

It is trivially faster to start out with the access bit set -- the
hardware will set the accessed bit anyway.

-hpa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/