Re: Zenbleed

Jung-uk Kim <[email protected]> Thu, 27 Jul 2023 12:09:53 -0400
Newsgroups gmane.os.freebsd.security.general
Organization FreeBSD.org
Message-ID <[email protected]>
On 23. 7. 26., Shawn Webb wrote:
> On Wed, Jul 26, 2023 at 08:34:56PM +0000, 0x1eef wrote:
>> Hello,
>>
>> I was curious if there are plans to apply the "chicken bit"
>> workaround for the Ryzen line of processors. A firmware
>> update is not scheduled to be released until Nov or Dec
>> at the earliest. Thanks.
> 
> For those that would like to test if their systems are affected, this
> proof-of-concept was reported to work on at least one system:
> 
> https://git.hardenedbsd.org/shawn.webb/zenbleed/-/tree/shawn.webb/bsd/main
> 
> Building it depends on gmake and nasm. You'll want to be on the
> shawn.webb/bsd/main branch.
> 
> Note that this code is simply Tavis' original PoC, just modified
> enough to get it to build on FreeBSD and OpenBSD.

FYI, the attached patch should reduce the diff and do the right thing.

Jung-uk Kim
zenbleed.diff (text/x-patch, 823 B)
diff --git a/Makefile b/Makefile
index 7b969d4..ac72213 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,6 @@ CFLAGS=-O0 -ggdb3 -march=znver2
 LDFLAGS=-pthread -Wl,-z,noexecstack
 NFLAGS=
 
-NCPUS!=	sysctl -n kern.smp.cores
-CFLAGS+= -DNCPUS=$(NCPUS)
-
 .PHONY: clean dist
 
 all: zenbleed
diff --git a/zenbleed.c b/zenbleed.c
index d341b23..9359e3b 100644
--- a/zenbleed.c
+++ b/zenbleed.c
@@ -323,13 +323,7 @@ int main(int argc, char **argv) {
     }
 
     // We spawn a thread on every evailable core and start leaking to see what we get.
-#ifdef __BSD_NOTYET
-    ncpus   = get_nprocs();
-#elif defined(NCPUS)
-    ncpus = NCPUS;
-#else
-    ncpus = 4;
-#endif
+    ncpus = sysconf(_SC_NPROCESSORS_ONLN);
     thread_arg_t* args = calloc(sizeof(thread_arg_t), ncpus);
     threads = calloc(sizeof(pthread_t), ncpus);
OpenPGP_signature (application/pgp-signature, 495 B) - not displayed