lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 4 Jul 2023 11:55:03 +0300
From:   Tero Kristo <tero.kristo@...ux.intel.com>
To:     John Fastabend <john.fastabend@...il.com>, shuah@...nel.org,
        tglx@...utronix.de, x86@...nel.org, bp@...en8.de,
        dave.hansen@...ux.intel.com, mingo@...hat.com
Cc:     ast@...nel.org, linux-kselftest@...r.kernel.org,
        linux-kernel@...r.kernel.org, andrii@...nel.org,
        daniel@...earbox.net, bpf@...r.kernel.org
Subject: Re: [PATCH 2/2] selftests/bpf: Add test for bpf_rdtsc


On 04/07/2023 01:00, John Fastabend wrote:
> Tero Kristo wrote:
>> Add selftest for bpf_rdtsc() which reads the TSC (Time Stamp Counter) on
>> x86_64 architectures. The test reads the TSC from both userspace and the
>> BPF program, and verifies the TSC values are in incremental order as
>> expected. The test is automatically skipped on architectures that do not
>> support the feature.
>>
>> Signed-off-by: Tero Kristo <tero.kristo@...ux.intel.com>
>> ---
>>   .../selftests/bpf/prog_tests/test_rdtsc.c     | 67 +++++++++++++++++++
>>   .../testing/selftests/bpf/progs/test_rdtsc.c  | 21 ++++++
>>   2 files changed, 88 insertions(+)
>>   create mode 100644 tools/testing/selftests/bpf/prog_tests/test_rdtsc.c
>>   create mode 100644 tools/testing/selftests/bpf/progs/test_rdtsc.c
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/test_rdtsc.c b/tools/testing/selftests/bpf/prog_tests/test_rdtsc.c
>> new file mode 100644
>> index 000000000000..2b26deb5b35a
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/prog_tests/test_rdtsc.c
>> @@ -0,0 +1,67 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright(c) 2023 Intel Corporation */
>> +
>> +#include "test_progs.h"
>> +#include "test_rdtsc.skel.h"
>> +
>> +#ifdef __x86_64__
>> +
>> +static inline u64 _rdtsc(void)
>> +{
>> +	u32 low, high;
>> +
>> +	__asm__ __volatile__("rdtscp" : "=a" (low), "=d" (high));
> I think its ok but note this could fail if user doesn't have
> access to rdtscp and iirc that can be restricted?

It is possible to restrict RDTSC access from userspace by enabling the 
TSD bit in CR4 register, and it will cause the userspace process to trap 
with general protection fault.

However, the usage of RDTSC appears to be built-in to C standard 
libraries (probably some timer routines) and enabling the CR4 TSD makes 
the system near unusable. Things like sshd + systemd also start 
generating the same general protection faults if RDTSC is blocked. Also, 
attempting to run anything at all with the BPF selftest suite causes the 
same general protection fault; not only the rdtsc test.

I tried this with couple of setups, one system running a minimalistic 
buildroot and another one running a fedora37 installation and the 
results were similar.

-Tero

>
>> +	return ((u64)high << 32) | low;
>> +}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ