From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,kees@kernel.org,jinb.park7@gmail.com,ptesarik@suse.com,akpm@linux-foundation.org
Subject: + mm-rodata_test-use-read_once-to-read-const-variable.patch added to mm-unstable branch
Date: Fri, 29 Nov 2024 02:56:32 -0800 [thread overview]
Message-ID: <20241129105632.F3CF0C4CECF@smtp.kernel.org> (raw)
The patch titled
Subject: mm/rodata_test: use READ_ONCE() to read const variable
has been added to the -mm mm-unstable branch. Its filename is
mm-rodata_test-use-read_once-to-read-const-variable.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-rodata_test-use-read_once-to-read-const-variable.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: Petr Tesarik <ptesarik@suse.com>
Subject: mm/rodata_test: use READ_ONCE() to read const variable
Date: Tue, 19 Nov 2024 12:37:38 +0100
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: 2959a5f726f6 ("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>
---
mm/rodata_test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--- a/mm/rodata_test.c~mm-rodata_test-use-read_once-to-read-const-variable
+++ a/mm/rodata_test.c
@@ -20,7 +20,7 @@ void rodata_test(void)
/* test 1: read the value */
/* If this test fails, some previous testrun has clobbered the state */
- if (!rodata_test_data) {
+ if (!READ_ONCE(rodata_test_data)) {
pr_err("test 1 fails (start data)\n");
return;
}
@@ -33,7 +33,7 @@ void rodata_test(void)
}
/* test 3: check the value hasn't changed */
- if (rodata_test_data == zero) {
+ if (READ_ONCE(rodata_test_data) == zero) {
pr_err("test data was changed\n");
return;
}
_
Patches currently in -mm which might be from ptesarik@suse.com are
mm-rodata_test-use-read_once-to-read-const-variable.patch
mm-rodata_test-verify-test-data-is-unchanged-rather-than-non-zero.patch
reply other threads:[~2024-11-29 10:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20241129105632.F3CF0C4CECF@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=jinb.park7@gmail.com \
--cc=kees@kernel.org \
--cc=mm-commits@vger.kernel.org \
--cc=ptesarik@suse.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.