x86/boot: Wrap literal addresses in absolute_pointer()
authorKees Cook <keescook@chromium.org>
Sun, 27 Feb 2022 19:59:18 +0000 (11:59 -0800)
committerBorislav Petkov <bp@suse.de>
Thu, 19 May 2022 10:47:30 +0000 (12:47 +0200)
commitaeb84412037b89e06f45e382f044da6f200e12f8
tree36d2cb929b460f9c5badb5b9d739bddbf0c8d9e0
parent9b5a7f4a2a8dcda461f9c7a6671150f4a8a902e8
x86/boot: Wrap literal addresses in absolute_pointer()

GCC 11 (incorrectly[1]) assumes that literal values cast to (void *)
should be treated like a NULL pointer with an offset, and raises
diagnostics when doing bounds checking under -Warray-bounds. GCC 12
got "smarter" about finding these:

  In function 'rdfs8',
      inlined from 'vga_recalc_vertical' at /srv/code/arch/x86/boot/video-mode.c:124:29,
      inlined from 'set_mode' at /srv/code/arch/x86/boot/video-mode.c:163:3:
  /srv/code/arch/x86/boot/boot.h:114:9: warning: array subscript 0 is outside array bounds of 'u8[0]' {aka 'unsigned char[]'} [-Warray-bounds]
    114 |         asm volatile("movb %%fs:%1,%0" : "=q" (v) : "m" (*(u8 *)addr));
        |         ^~~

This has been solved in other places[2] already by using the recently
added absolute_pointer() macro. Do the same here.

  [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
  [2] https://lore.kernel.org/all/20210912160149.2227137-1-linux@roeck-us.net/

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20220227195918.705219-1-keescook@chromium.org
arch/x86/boot/boot.h
arch/x86/boot/main.c