From: "Michał Pecio" <michal.pecio@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org,
Catalin Marinas <catalin.marinas@arm.com>,
Linux kernel regressions list <regressions@lists.linux.dev>,
Kees Cook <kees@kernel.org>
Subject: Re: cacheflush completely broken, suspecting PAN+LPAE
Date: Tue, 12 Nov 2024 11:16:29 +0100 [thread overview]
Message-ID: <20241112111629.18a6e464@foxbook> (raw)
In-Reply-To: <20241112103229.566b1ff3@foxbook>
Regarding test programs, I also wrote and tried this one yesterday.
It's based on a similar demo released by ARM, but much simplified.
It both triggers the bug and confirms the necessity of cacheflush in
JIT compilers on my CPU when it works normally (prints: 1, 1, 2).
On the buggy kernel, it usually segfaults on the first attempt to call
*code, but sometimes both __clear_cache() appear to take effect despite
the syscall returning EFAULT (according to strace), not sure why.
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
int f1() {
return 1;
}
int f2() {
return 2;
}
int main() {
puts("start");
char *code = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
int x;
memcpy(code, f1, 0x100);
__builtin___clear_cache(code, code + 0x100);
x = ((int(*)())code)();
printf("%x\n", x);
memcpy(code, f2, 0x100);
x = ((int(*)())code)();
printf("%x\n", x);
__builtin___clear_cache(code, code + 0x100);
x = ((int(*)())code)();
printf("%x\n", x);
}
next prev parent reply other threads:[~2024-11-12 10:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-11 22:38 cacheflush completely broken, suspecting PAN+LPAE Michał Pecio
2024-11-12 1:15 ` Linus Walleij
2024-11-12 6:41 ` Arnd Bergmann
2024-11-12 9:46 ` Michał Pecio
2024-11-12 9:32 ` Michał Pecio
2024-11-12 10:16 ` Michał Pecio [this message]
2024-11-12 10:21 ` Russell King (Oracle)
2024-11-12 10:45 ` Michał Pecio
2024-11-12 13:58 ` Linus Walleij
2024-11-12 17:10 ` Michał Pecio
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=20241112111629.18a6e464@foxbook \
--to=michal.pecio@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=kees@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=regressions@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).