Go to file
Petr Tesarik db27ad8b02 mm/rodata_test: use READ_ONCE() to read const variable
Patch series "Fix mm/rodata_test", v2.

Make sure that the test actually reads the read-only memory location.
Verify that the variable contains the expected value rather than any
non-zero value.


This patch (of 2):

The C compiler may optimize away the memory read of a const variable if
its value is known at compile time.

In particular, GCC14 with -O2 generates no code at all for test 1, and it
generates the following x86_64 instructions for test 3:

	cmpl	$195, 4(%rsp)
	je	.L14

That is, it replaces the read of rodata_test_data with an immediate value
and compares it to the value of the local variable "zero".

Use READ_ONCE() to undo any such compiler optimizations and enforce a
memory read.

Link: https://lkml.kernel.org/r/cover.1732016064.git.ptesarik@suse.com
Link: https://lkml.kernel.org/r/2a66dee010151b25cb143efb39091ef7530aa00a.1732016064.git.ptesarik@suse.com
Fixes: 2959a5f726 ("mm: add arch-independent testcases for RODATA")
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Cc: Jinbum Park <jinb.park7@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2025-01-13 22:40:37 -08:00
Documentation docs: tmpfs: drop 'fadvise()' from the documentation 2025-01-13 22:40:37 -08:00
LICENSES
arch x86/execmem: fix ROX cache usage in Xen PV guests 2025-01-12 19:03:35 -08:00
block
certs
crypto
drivers zram: fix potential UAF of zram table 2025-01-12 19:03:37 -08:00
fs fs/proc: fix softlockup in __read_vmcore (part 2) 2025-01-12 19:03:38 -08:00
include mm: factor out the order calculation into a new helper 2025-01-13 22:40:36 -08:00
init
io_uring
ipc
kernel kasan: make kasan_record_aux_stack_noalloc() the default behaviour 2025-01-13 22:40:36 -08:00
lib maple_tree: use mas_next_slot() directly 2025-01-13 22:40:30 -08:00
mm mm/rodata_test: use READ_ONCE() to read const variable 2025-01-13 22:40:37 -08:00
net
rust
samples
scripts scripts/decode_stacktrace.sh: fix decoding of lines with an additional info 2025-01-12 19:03:34 -08:00
security
sound
tools selftests/mm: add a few missing gitignore files 2025-01-13 22:40:35 -08:00
usr
virt
.clang-format
.clippy.toml
.cocciconfig
.editorconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
.rustfmt.toml
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README

README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the reStructuredText markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.