Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/signal/64: Add a comment about sigcontext->fs and gs

These fields have a strange history. This tries to document it.

This borrows from 9a036b93a344 ("x86/signal/64: Remove 'fs' and 'gs'
from sigcontext"), which was reverted by ed596cde9425 ("Revert x86
sigcontext cleanups").

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Borislav Petkov <bp@alien8.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stas Sergeev <stsp@list.ru>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/baa78f3c84106fa5acbc319377b1850602f5deec.1455664054.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Andy Lutomirski and committed by
Ingo Molnar
e54fdcca f2cc8e07

+25
+25
arch/x86/include/uapi/asm/sigcontext.h
··· 341 341 __u64 rip; 342 342 __u64 eflags; /* RFLAGS */ 343 343 __u16 cs; 344 + 345 + /* 346 + * Prior to 2.5.64 ("[PATCH] x86-64 updates for 2.5.64-bk3"), 347 + * Linux saved and restored fs and gs in these slots. This 348 + * was counterproductive, as fsbase and gsbase were never 349 + * saved, so arch_prctl was presumably unreliable. 350 + * 351 + * These slots should never be reused without extreme caution: 352 + * 353 + * - Some DOSEMU versions stash fs and gs in these slots manually, 354 + * thus overwriting anything the kernel expects to be preserved 355 + * in these slots. 356 + * 357 + * - If these slots are ever needed for any other purpose, 358 + * there is some risk that very old 64-bit binaries could get 359 + * confused. I doubt that many such binaries still work, 360 + * though, since the same patch in 2.5.64 also removed the 361 + * 64-bit set_thread_area syscall, so it appears that there 362 + * is no TLS API beyond modify_ldt that works in both pre- 363 + * and post-2.5.64 kernels. 364 + * 365 + * If the kernel ever adds explicit fs, gs, fsbase, and gsbase 366 + * save/restore, it will most likely need to be opt-in and use 367 + * different context slots. 368 + */ 344 369 __u16 gs; 345 370 __u16 fs; 346 371 __u16 __pad0;