Skip to contentSkip to conversation

Add libfuzzer target to fuzz/x86_instruction_emulator

PATCH Superseded Tamas K Lengyel 3 participants 26 messages Jun 21, 2024 – Jun 26, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add libfuzzer target to fuzz/x86_instruction_emulator

This target enables integration into oss-fuzz.

---
 tools/fuzz/x86_instruction_emulator/Makefile    | 10 ++++++++--
 tools/fuzz/x86_instruction_emulator/fuzz-emul.c |  6 ++----
 2 files changed, 10 insertions(+), 6 deletions(-)
tools/fuzz/x86_instruction_emulator/Makefile +8 -2
index 1e4c6b37f5..de5f1e7e30 100644
@@ -3,7 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 .PHONY: x86-insn-fuzz-all
 ifeq ($(CONFIG_X86_64),y)
-x86-insn-fuzz-all: x86-insn-fuzzer.a fuzz-emul.o afl
+x86-insn-fuzz-all: x86-insn-fuzzer.a fuzz-emul.o afl libfuzzer
 else
 x86-insn-fuzz-all:
 endif
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
 	$(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+	$(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@
+
 # Common targets
 .PHONY: all
 all: x86-insn-fuzz-all
@@ -67,7 +70,7 @@ distclean: clean
 
 .PHONY: clean
 clean:
-	rm -f *.a *.o $(DEPS_RM) afl-harness afl-harness-cov *.gcda *.gcno *.gcov
+	rm -f *.a *.o $(DEPS_RM) afl-harness afl-harness-cov *.gcda *.gcno *.gcov libfuzzer-harness
 	rm -rf x86_emulate x86-emulate.c x86-emulate.h wrappers.c cpuid.c
 
 .PHONY: install
@@ -81,4 +84,7 @@ afl: afl-harness
 .PHONY: afl-cov
 afl-cov: afl-harness-cov
 
+.PHONY: libfuzzer
+libfuzzer: libfuzzer-harness
+
 -include $(DEPS_INCLUDE)
tools/fuzz/x86_instruction_emulator/fuzz-emul.c +2 -4
index eeeb6931f4..2ba9ca9e0b 100644
@@ -906,14 +906,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
 
     if ( size <= DATA_OFFSET )
     {
-        printf("Input too small\n");
-        return 1;
+        return -1;
     }
 
     if ( size > FUZZ_CORPUS_SIZE )
     {
-        printf("Input too large\n");
-        return 1;
+        return -1;
     }
 
     memcpy(&input, data_p, size);
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 Add scripts/oss-fuzz/build.sh

The build integration script for oss-fuzz targets.

---
 scripts/oss-fuzz/build.sh | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100755 scripts/oss-fuzz/build.sh
scripts/oss-fuzz/build.sh new file +22 -0
new file mode 100755
index 0000000000..48528bbfc2
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Hi,

Quoted 1 line · Tamas K Lengyel

The build integration script for oss-fuzz targets.

Do you have any details how this is meant and/or will be used?

I also couldn't find a cover letter. For series with more than one patch, it is recommended to have one as it help threading and could also give some insight on what you are aiming to do.

scripts/oss-fuzz/build.sh

Quoted 12 lines
---
  scripts/oss-fuzz/build.sh | 22 ++++++++++++++++++++++
  1 file changed, 22 insertions(+)

create mode 100755 scripts/oss-fuzz/build.sh

scripts/oss-fuzz/build.sh new file +0 -0
new file mode 100755
index 0000000000..48528bbfc2

Depending on the answer above, we may want to consider to create the directory oss-fuzz under automation or maybe tools/fuzz/.

scripts/oss-fuzz/build.sh line 2

Quoted 3 lines
scripts/oss-fuzz/build.sh new file +2 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC

I am a bit confused with this copyright. Is this script taken from somewhere?

Quoted 7 lines
scripts/oss-fuzz/build.sh new file +7 -0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#

scripts/oss-fuzz/build.sh line 19

Quoted 10 lines
scripts/oss-fuzz/build.sh new file +10 -0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen

Looking at the help from ./configure, 'clang=y' is not mentioned and it doesn't make any difference in the config.log. Can you clarify why this was added?

scripts/oss-fuzz/build.sh line 22

Quoted 3 lines
scripts/oss-fuzz/build.sh new file +3 -0
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

Who will be defining $OUT?

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Quoted 7 lines · Julien Grall

Hi,

Quoted 1 line · Tamas K Lengyel

The build integration script for oss-fuzz targets.

Do you have any details how this is meant and/or will be used?

https://google.github.io/oss-fuzz/getting-started/new-project-guide/#buildsh

Quoted 12 lines

I also couldn't find a cover letter. For series with more than one patch, it is recommended to have one as it help threading and could also give some insight on what you are aiming to do.

Quoted 7 lines
---
  scripts/oss-fuzz/build.sh | 22 ++++++++++++++++++++++
  1 file changed, 22 insertions(+)

create mode 100755 scripts/oss-fuzz/build.sh

Quoted 8 lines

scripts/oss-fuzz/build.sh

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +0 -0
new file mode 100755
index 0000000000..48528bbfc2

Depending on the answer above, we may want to consider to create the directory oss-fuzz under automation or maybe tools/fuzz/.

I'm fine with moving it wherever.

Quoted 7 lines

scripts/oss-fuzz/build.sh line 2

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +2 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC

I am a bit confused with this copyright. Is this script taken from somewhere?

Yes, I took an existing build.sh from oss-fuzz, it is recommended to have the more complex part of build.sh as part of the upstream repository so that additional targets/fixes can be merged there instead of opening PRs on oss-fuzz directly. With this setup the build.sh I merge to oss-fuzz will just just this build.sh in the Xen repository. See
https://github.com/tklengyel/oss-fuzz/commit/552317ae9d24ef1c00d87595516cc364bc33b662.

Quoted 14 lines
Quoted 14 lines
scripts/oss-fuzz/build.sh new file +13 -0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
Quoted 8 lines

scripts/oss-fuzz/build.sh line 19

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +4 -0
+################################################################################
+
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen

Looking at the help from ./configure, 'clang=y' is not mentioned and it doesn't make any difference in the config.log. Can you clarify why this was added?

Just throwing stuff at the wall till I was able to get a clang build. If it's indeed not needed I can remove it.

Quoted 6 lines

scripts/oss-fuzz/build.sh line 22

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +3 -0
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

Who will be defining $OUT?

oss-fuzz

Tamas

#4 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Hi Tamas,

Quoted 32 lines · Tamas K Lengyel
Quoted 7 lines · Julien Grall

Hi,

Quoted 1 line · Tamas K Lengyel

The build integration script for oss-fuzz targets.

Do you have any details how this is meant and/or will be used?

https://google.github.io/oss-fuzz/getting-started/new-project-guide/#buildsh

Quoted 12 lines

I also couldn't find a cover letter. For series with more than one patch, it is recommended to have one as it help threading and could also give some insight on what you are aiming to do.

Quoted 7 lines
---
   scripts/oss-fuzz/build.sh | 22 ++++++++++++++++++++++
   1 file changed, 22 insertions(+)

create mode 100755 scripts/oss-fuzz/build.sh

Quoted 8 lines

scripts/oss-fuzz/build.sh

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +0 -0
new file mode 100755
index 0000000000..48528bbfc2

Depending on the answer above, we may want to consider to create the directory oss-fuzz under automation or maybe tools/fuzz/.

Quoted 1 line

I'm fine with moving it wherever.

What about tools/fuzz then? This is where are all the tooling for the fuzzing.

Quoted 10 lines
Quoted 8 lines

scripts/oss-fuzz/build.sh line 2

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +2 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC

I am a bit confused with this copyright. Is this script taken from somewhere?

Yes, I took an existing build.sh from oss-fuzz,

It is unclear to me what is left from that "existing" build.sh. At least everything below seems to be Xen specific.

Anyway, if you want to give the copyright to Google then fair enough, but I think you want to use an Origin tag (or similar) to indicate the original copy.

Quoted 35 lines

it is recommended to
have the more complex part of build.sh as part of the upstream repository so that additional targets/fixes can be merged there instead of opening PRs on oss-fuzz directly. With this setup the build.sh I merge to oss-fuzz will just just this build.sh in the Xen repository. See
https://github.com/tklengyel/oss-fuzz/commit/552317ae9d24ef1c00d87595516cc364bc33b662.

Quoted 14 lines
Quoted 14 lines
scripts/oss-fuzz/build.sh new file +13 -0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
Quoted 8 lines

scripts/oss-fuzz/build.sh line 19

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +4 -0
+################################################################################
+
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen

Looking at the help from ./configure, 'clang=y' is not mentioned and it doesn't make any difference in the config.log. Can you clarify why this was added?

Just throwing stuff at the wall till I was able to get a clang build. If it's indeed not needed I can remove it.

Quoted 1 line
Quoted 7 lines
Quoted 5 lines

scripts/oss-fuzz/build.sh line 22

Quoted 3 lines
scripts/oss-fuzz/build.sh new file +3 -0
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

Who will be defining $OUT?

oss-fuzz

Ok. Can you add a link to the documentation in build.sh? This would be helpful for the future reader to understand what's $OUT really mean.

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Quoted 100 lines · Julien Grall

Hi Tamas,

Quoted 32 lines · Tamas K Lengyel
Quoted 7 lines · Julien Grall

Hi,

Quoted 1 line · Tamas K Lengyel

The build integration script for oss-fuzz targets.

Do you have any details how this is meant and/or will be used?

https://google.github.io/oss-fuzz/getting-started/new-project-guide/#buildsh

Quoted 12 lines

I also couldn't find a cover letter. For series with more than one patch, it is recommended to have one as it help threading and could also give some insight on what you are aiming to do.

Quoted 7 lines
---
   scripts/oss-fuzz/build.sh | 22 ++++++++++++++++++++++
   1 file changed, 22 insertions(+)

create mode 100755 scripts/oss-fuzz/build.sh

Quoted 8 lines

scripts/oss-fuzz/build.sh

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +0 -0
new file mode 100755
index 0000000000..48528bbfc2

Depending on the answer above, we may want to consider to create the directory oss-fuzz under automation or maybe tools/fuzz/.

Quoted 1 line

I'm fine with moving it wherever.

What about tools/fuzz then? This is where are all the tooling for the fuzzing.

Quoted 10 lines
Quoted 8 lines

scripts/oss-fuzz/build.sh line 2

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +2 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC

I am a bit confused with this copyright. Is this script taken from somewhere?

Yes, I took an existing build.sh from oss-fuzz,

It is unclear to me what is left from that "existing" build.sh. At least everything below seems to be Xen specific.

Anyway, if you want to give the copyright to Google then fair enough, but I think you want to use an Origin tag (or similar) to indicate the original copy.

Quoted 41 lines

it is recommended to
have the more complex part of build.sh as part of the upstream repository so that additional targets/fixes can be merged there instead of opening PRs on oss-fuzz directly. With this setup the build.sh I merge to oss-fuzz will just just this build.sh in the Xen repository. See
https://github.com/tklengyel/oss-fuzz/commit/552317ae9d24ef1c00d87595516cc364bc33b662.

Quoted 14 lines
Quoted 14 lines
scripts/oss-fuzz/build.sh new file +13 -0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
Quoted 8 lines

scripts/oss-fuzz/build.sh line 19

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +4 -0
+################################################################################
+
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen

Looking at the help from ./configure, 'clang=y' is not mentioned and it doesn't make any difference in the config.log. Can you clarify why this was added?

Just throwing stuff at the wall till I was able to get a clang build. If it's indeed not needed I can remove it.

Quoted 6 lines

scripts/oss-fuzz/build.sh line 22

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +3 -0
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

Who will be defining $OUT?

Quoted 4 lines
Quoted 1 line

oss-fuzz

Ok. Can you add a link to the documentation in build.sh? This would be helpful for the future reader to understand what's $OUT really mean.

Sure, it turns out there is already a README.oss-fuzz in tools/fuzz that points to the oss-fuzz so I don't think there is anything else needed here, we can just move the build script there.

Tamas

#6 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Hi Tamas,

Quoted 101 lines · Tamas K Lengyel
Quoted 100 lines · Julien Grall

Hi Tamas,

Quoted 32 lines · Tamas K Lengyel
Quoted 7 lines · Julien Grall

Hi,

Quoted 1 line · Tamas K Lengyel

The build integration script for oss-fuzz targets.

Do you have any details how this is meant and/or will be used?

https://google.github.io/oss-fuzz/getting-started/new-project-guide/#buildsh

Quoted 12 lines

I also couldn't find a cover letter. For series with more than one patch, it is recommended to have one as it help threading and could also give some insight on what you are aiming to do.

Quoted 7 lines
---
    scripts/oss-fuzz/build.sh | 22 ++++++++++++++++++++++
    1 file changed, 22 insertions(+)

create mode 100755 scripts/oss-fuzz/build.sh

Quoted 8 lines

scripts/oss-fuzz/build.sh

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +0 -0
new file mode 100755
index 0000000000..48528bbfc2

Depending on the answer above, we may want to consider to create the directory oss-fuzz under automation or maybe tools/fuzz/.

Quoted 1 line

I'm fine with moving it wherever.

What about tools/fuzz then? This is where are all the tooling for the fuzzing.

Quoted 10 lines
Quoted 8 lines

scripts/oss-fuzz/build.sh line 2

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +2 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC

I am a bit confused with this copyright. Is this script taken from somewhere?

Yes, I took an existing build.sh from oss-fuzz,

It is unclear to me what is left from that "existing" build.sh. At least everything below seems to be Xen specific.

Anyway, if you want to give the copyright to Google then fair enough, but I think you want to use an Origin tag (or similar) to indicate the original copy.

Quoted 41 lines

it is recommended to
have the more complex part of build.sh as part of the upstream repository so that additional targets/fixes can be merged there instead of opening PRs on oss-fuzz directly. With this setup the build.sh I merge to oss-fuzz will just just this build.sh in the Xen repository. See
https://github.com/tklengyel/oss-fuzz/commit/552317ae9d24ef1c00d87595516cc364bc33b662.

Quoted 14 lines
Quoted 14 lines
scripts/oss-fuzz/build.sh new file +13 -0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
Quoted 8 lines

scripts/oss-fuzz/build.sh line 19

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +4 -0
+################################################################################
+
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen

Looking at the help from ./configure, 'clang=y' is not mentioned and it doesn't make any difference in the config.log. Can you clarify why this was added?

Just throwing stuff at the wall till I was able to get a clang build. If it's indeed not needed I can remove it.

Quoted 6 lines

scripts/oss-fuzz/build.sh line 22

Quoted 4 lines
scripts/oss-fuzz/build.sh new file +3 -0
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

Who will be defining $OUT?

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

oss-fuzz

Ok. Can you add a link to the documentation in build.sh? This would be helpful for the future reader to understand what's $OUT really mean.

Sure, it turns out there is already a README.oss-fuzz in tools/fuzz that points to the oss-fuzz so I don't think there is anything else needed here,

Perfect. I am fine with that.

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

In reply to Tamas K Lengyel
Quoted 9 lines · Tamas K Lengyel
scripts/oss-fuzz/build.sh new file +6 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at

scripts/oss-fuzz/build.sh line 16

Quoted 10 lines
scripts/oss-fuzz/build.sh new file +10 -0
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################

I'm a little concerned here, but maybe I shouldn't be. According to what I'm reading, the Apache 2.0 license is at least not entirely compatible with GPLv2. While apparently the issue is solely with linking in Apache- licensed code, I wonder whether us not having a respective file under ./LICENSES/ (and no pre-cooked SPDX identifier to use) actually has a reason possibly excluding the use of such code in the project.

scripts/oss-fuzz/build.sh line 22

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +5 -0
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

In addition to what Julien said, I further think that filename / directory name are too generic for a file with this pretty specific contents.

Jan

#8 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Quoted 29 lines · Jan Beulich
Quoted 9 lines · Tamas K Lengyel
scripts/oss-fuzz/build.sh new file +6 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at

scripts/oss-fuzz/build.sh line 16

Quoted 10 lines
scripts/oss-fuzz/build.sh new file +10 -0
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################

I'm a little concerned here, but maybe I shouldn't be. According to what I'm reading, the Apache 2.0 license is at least not entirely compatible with GPLv2. While apparently the issue is solely with linking in Apache- licensed code, I wonder whether us not having a respective file under ./LICENSES/ (and no pre-cooked SPDX identifier to use) actually has a reason possibly excluding the use of such code in the project.

Quoted 8 lines

scripts/oss-fuzz/build.sh line 22

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +5 -0
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

In addition to what Julien said, I further think that filename / directory name are too generic for a file with this pretty specific contents.

I don't really get your concern here?

Tamas

#9 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Quoted 39 lines · Tamas K Lengyel
Quoted 29 lines · Jan Beulich
Quoted 9 lines · Tamas K Lengyel
scripts/oss-fuzz/build.sh new file +6 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at

scripts/oss-fuzz/build.sh line 16

Quoted 10 lines
scripts/oss-fuzz/build.sh new file +10 -0
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################

I'm a little concerned here, but maybe I shouldn't be. According to what I'm reading, the Apache 2.0 license is at least not entirely compatible with GPLv2. While apparently the issue is solely with linking in Apache- licensed code, I wonder whether us not having a respective file under ./LICENSES/ (and no pre-cooked SPDX identifier to use) actually has a reason possibly excluding the use of such code in the project.

Quoted 8 lines

scripts/oss-fuzz/build.sh line 22

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +5 -0
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

In addition to what Julien said, I further think that filename / directory name are too generic for a file with this pretty specific contents.

Quoted 1 line

I don't really get your concern here?

The thing that is built is specifically a x86 emulator piece of fuzzing binary. Neither the directory name nor the file name contain either x86 or (at least) emul.

Jan

#10 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Quoted 41 lines · Jan Beulich
Quoted 39 lines · Tamas K Lengyel
Quoted 37 lines · Jan Beulich
Quoted 9 lines · Tamas K Lengyel
scripts/oss-fuzz/build.sh new file +6 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at

scripts/oss-fuzz/build.sh line 16

Quoted 10 lines
scripts/oss-fuzz/build.sh new file +10 -0
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################

I'm a little concerned here, but maybe I shouldn't be. According to what I'm reading, the Apache 2.0 license is at least not entirely compatible with GPLv2. While apparently the issue is solely with linking in Apache- licensed code, I wonder whether us not having a respective file under ./LICENSES/ (and no pre-cooked SPDX identifier to use) actually has a reason possibly excluding the use of such code in the project.

scripts/oss-fuzz/build.sh line 22

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +5 -0
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

In addition to what Julien said, I further think that filename / directory name are too generic for a file with this pretty specific contents.

Quoted 5 lines
Quoted 1 line

I don't really get your concern here?

The thing that is built is specifically a x86 emulator piece of fuzzing binary. Neither the directory name nor the file name contain either x86 or (at least) emul.

Because this build script is not necessarily restricted to build only this one harness in the future. Right now that's the only one that has a suitable libfuzzer harness, but the reason this build script is here is to be easily able to add additional fuzzing binaries without the need to open PRs on the oss-fuzz repo, which as I understand no one was willing to do in the xen community due to the CLA. Now that the integration is going to be in oss-fuzz, the only thing you have to do in the future is add more stuff to this script to get fuzzed. Anything that's compiled with libfuzzer and copied to $OUT will be picked up by oss-fuzz automatically. Makes sense?

Tamas

#11 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Quoted 48 lines · Tamas K Lengyel
Quoted 41 lines · Jan Beulich
Quoted 39 lines · Tamas K Lengyel
Quoted 37 lines · Jan Beulich
Quoted 9 lines · Tamas K Lengyel
scripts/oss-fuzz/build.sh new file +6 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at

scripts/oss-fuzz/build.sh line 16

Quoted 10 lines
scripts/oss-fuzz/build.sh new file +10 -0
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################

I'm a little concerned here, but maybe I shouldn't be. According to what I'm reading, the Apache 2.0 license is at least not entirely compatible with GPLv2. While apparently the issue is solely with linking in Apache- licensed code, I wonder whether us not having a respective file under ./LICENSES/ (and no pre-cooked SPDX identifier to use) actually has a reason possibly excluding the use of such code in the project.

scripts/oss-fuzz/build.sh line 22

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +5 -0
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

In addition to what Julien said, I further think that filename / directory name are too generic for a file with this pretty specific contents.

Quoted 5 lines
Quoted 1 line

I don't really get your concern here?

The thing that is built is specifically a x86 emulator piece of fuzzing binary. Neither the directory name nor the file name contain either x86 or (at least) emul.

Quoted 10 lines

Because this build script is not necessarily restricted to build only this one harness in the future. Right now that's the only one that has a suitable libfuzzer harness, but the reason this build script is here is to be easily able to add additional fuzzing binaries without the need to open PRs on the oss-fuzz repo, which as I understand no one was willing to do in the xen community due to the CLA. Now that the integration is going to be in oss-fuzz, the only thing you have to do in the future is add more stuff to this script to get fuzzed. Anything that's compiled with libfuzzer and copied to $OUT will be picked up by oss-fuzz automatically. Makes sense?

It does, yes. Yet nothing like that was said in the description. How should anyone have known there are future possibilities with this script?

Jan

#12 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Quoted 61 lines · Jan Beulich
Quoted 48 lines · Tamas K Lengyel
Quoted 41 lines · Jan Beulich
Quoted 39 lines · Tamas K Lengyel
Quoted 37 lines · Jan Beulich
Quoted 9 lines · Tamas K Lengyel
scripts/oss-fuzz/build.sh new file +6 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at

scripts/oss-fuzz/build.sh line 16

Quoted 10 lines
scripts/oss-fuzz/build.sh new file +10 -0
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################

I'm a little concerned here, but maybe I shouldn't be. According to what I'm reading, the Apache 2.0 license is at least not entirely compatible with GPLv2. While apparently the issue is solely with linking in Apache- licensed code, I wonder whether us not having a respective file under ./LICENSES/ (and no pre-cooked SPDX identifier to use) actually has a reason possibly excluding the use of such code in the project.

scripts/oss-fuzz/build.sh line 22

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +5 -0
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

In addition to what Julien said, I further think that filename / directory name are too generic for a file with this pretty specific contents.

Quoted 5 lines
Quoted 1 line

I don't really get your concern here?

The thing that is built is specifically a x86 emulator piece of fuzzing binary. Neither the directory name nor the file name contain either x86 or (at least) emul.

Quoted 10 lines

Because this build script is not necessarily restricted to build only this one harness in the future. Right now that's the only one that has a suitable libfuzzer harness, but the reason this build script is here is to be easily able to add additional fuzzing binaries without the need to open PRs on the oss-fuzz repo, which as I understand no one was willing to do in the xen community due to the CLA. Now that the integration is going to be in oss-fuzz, the only thing you have to do in the future is add more stuff to this script to get fuzzed. Anything that's compiled with libfuzzer and copied to $OUT will be picked up by oss-fuzz automatically. Makes sense?

Quoted 2 lines

It does, yes. Yet nothing like that was said in the description. How should anyone have known there are future possibilities with this script?

Apologies, to me "The build integration script for oss-fuzz targets." was sufficiently descriptive but it may require some familiarity with oss-fuzz to get. I can certainly add the above text to the commit message if that helps.

Tamas

#13 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

Quoted 62 lines · Tamas K Lengyel
Quoted 61 lines · Jan Beulich
Quoted 58 lines · Tamas K Lengyel
Quoted 41 lines · Jan Beulich
Quoted 39 lines · Tamas K Lengyel
Quoted 37 lines · Jan Beulich
Quoted 9 lines · Tamas K Lengyel
scripts/oss-fuzz/build.sh new file +6 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at

scripts/oss-fuzz/build.sh line 16

Quoted 10 lines
scripts/oss-fuzz/build.sh new file +10 -0
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################

I'm a little concerned here, but maybe I shouldn't be. According to what I'm reading, the Apache 2.0 license is at least not entirely compatible with GPLv2. While apparently the issue is solely with linking in Apache- licensed code, I wonder whether us not having a respective file under ./LICENSES/ (and no pre-cooked SPDX identifier to use) actually has a reason possibly excluding the use of such code in the project.

scripts/oss-fuzz/build.sh line 21

Quoted 5 lines
scripts/oss-fuzz/build.sh new file +5 -0
+cd xen
+./configure clang=y --disable-stubdom --disable-pvshim --disable-docs --disable-xen
+make clang=y -C tools/include
+make clang=y -C tools/fuzz/x86_instruction_emulator libfuzzer-harness
+cp tools/fuzz/x86_instruction_emulator/libfuzzer-harness $OUT/x86_instruction_emulator

In addition to what Julien said, I further think that filename / directory name are too generic for a file with this pretty specific contents.

Quoted 5 lines
Quoted 1 line

I don't really get your concern here?

The thing that is built is specifically a x86 emulator piece of fuzzing binary. Neither the directory name nor the file name contain either x86 or (at least) emul.

Because this build script is not necessarily restricted to build only this one harness in the future. Right now that's the only one that has a suitable libfuzzer harness, but the reason this build script is here is to be easily able to add additional fuzzing binaries without the need to open PRs on the oss-fuzz repo, which as I understand no one was willing to do in the xen community due to the CLA. Now that the integration is going to be in oss-fuzz, the only thing you have to do in the future is add more stuff to this script to get fuzzed. Anything that's compiled with libfuzzer and copied to $OUT will be picked up by oss-fuzz automatically. Makes sense?

Quoted 7 lines
Quoted 2 lines

It does, yes. Yet nothing like that was said in the description. How should anyone have known there are future possibilities with this script?

Apologies, to me "The build integration script for oss-fuzz targets." was sufficiently descriptive but it may require some familiarity with oss-fuzz to get. I can certainly add the above text to the commit message if that helps.

Yes please, or and abridged variant thereof.

Jan

#14 lore raw

Re: [PATCH 2/2] Add scripts/oss-fuzz/build.sh

In reply to Jan Beulich
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Tamas K Lengyel
scripts/oss-fuzz/build.sh new file +15 -0
@@ -0,0 +1,22 @@
+#!/bin/bash -eu
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
Quoted 8 lines

scripts/oss-fuzz/build.sh line 16

Quoted 1 line
scripts/oss-fuzz/build.sh new file +1 -0
+################################################################################

I'm a little concerned here, but maybe I shouldn't be. According to what I'm reading, the Apache 2.0 license is at least not entirely compatible with GPLv2. While apparently the issue is solely with linking in Apache- licensed code, I wonder whether us not having a respective file under ./LICENSES/ (and no pre-cooked SPDX identifier to use) actually has a reason possibly excluding the use of such code in the project.

The script is standalone in a clearly separate folder, not linking with anything else in the project so there is no license mixing. Adding an SPDX tag to the file would be fine.

Tamas

#15 lore raw
In reply to Tamas K Lengyel

tools/fuzz/x86_instruction_emulator/Makefile afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
tools/fuzz/x86_instruction_emulator/Makefile +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
 	$(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+	$(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

I'm further surprised you get away here without wrappers.o.

Finally, despite its base name the lack of an extension suggest to me this isn't actually a library. Can you help me bring both aspects together?

tools/fuzz/x86_instruction_emulator/Makefile distclean: clean · line 73

Quoted 6 lines
tools/fuzz/x86_instruction_emulator/Makefile +1 -1
@@ -67,7 +70,7 @@ distclean: clean
 
 .PHONY: clean
 clean:
-	rm -f *.a *.o $(DEPS_RM) afl-harness afl-harness-cov *.gcda *.gcno *.gcov
+	rm -f *.a *.o $(DEPS_RM) afl-harness afl-harness-cov *.gcda *.gcno *.gcov libfuzzer-harness

I'm inclined to suggest it's time to split this line (e.g. keeping all the wildcard patterns together and moving the rest to a new rm invocation).

Quoted 9 lines
tools/fuzz/x86_instruction_emulator/fuzz-emul.c +1 -2
@@ -906,14 +906,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
 
     if ( size <= DATA_OFFSET )
     {
-        printf("Input too small\n");
-        return 1;
+        return -1;

tools/fuzz/x86_instruction_emulator/fuzz-emul.c int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size) · line 917

Quoted 10 lines
tools/fuzz/x86_instruction_emulator/fuzz-emul.c +1 -2
     }
 
     if ( size > FUZZ_CORPUS_SIZE )
     {
-        printf("Input too large\n");
-        return 1;
+        return -1;
     }
 
     memcpy(&input, data_p, size);

This part of the change clearly needs explaining in the description. It's not even clear to me in how far this is related to the purpose of the patch here (iow it may want to be a separate change, depending on why the change is needed).

Jan

#16 lore raw
Quoted 11 lines · Jan Beulich

tools/fuzz/x86_instruction_emulator/Makefile afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
tools/fuzz/x86_instruction_emulator/Makefile +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

Quoted 3 lines

Finally, despite its base name the lack of an extension suggest to me this isn't actually a library. Can you help me bring both aspects together?

Libfuzzer is the the name of the fuzzing engine, like afl:
https://llvm.org/docs/LibFuzzer.html

Quoted 10 lines

tools/fuzz/x86_instruction_emulator/Makefile distclean: clean · line 73

Quoted 7 lines
tools/fuzz/x86_instruction_emulator/Makefile +1 -1
@@ -67,7 +70,7 @@ distclean: clean
 
 .PHONY: clean
 clean:
-     rm -f *.a *.o $(DEPS_RM) afl-harness afl-harness-cov *.gcda *.gcno *.gcov
+     rm -f *.a *.o $(DEPS_RM) afl-harness afl-harness-cov *.gcda *.gcno *.gcov libfuzzer-harness

I'm inclined to suggest it's time to split this line (e.g. keeping all the wildcard patterns together and moving the rest to a new rm invocation).

Sure.

Quoted 19 lines
Quoted 19 lines
tools/fuzz/x86_instruction_emulator/fuzz-emul.c +2 -4
@@ -906,14 +906,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
 
     if ( size <= DATA_OFFSET )
     {
-        printf("Input too small\n");
-        return 1;
+        return -1;
     }
 
     if ( size > FUZZ_CORPUS_SIZE )
     {
-        printf("Input too large\n");
-        return 1;
+        return -1;
     }
 
Quoted 6 lines

tools/fuzz/x86_instruction_emulator/fuzz-emul.c int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size) · line 917

Quoted 1 line
tools/fuzz/x86_instruction_emulator/fuzz-emul.c +0 -0
     memcpy(&input, data_p, size);

This part of the change clearly needs explaining in the description. It's not even clear to me in how far this is related to the purpose of the patch here (iow it may want to be a separate change, depending on why the change is needed).

The printf simply produces a ton of unnecessary output while the fuzzer is running, slowing it down. It's also not useful at all, even for debugging. Switching the return -1 is necessary because beside 0/-1 values are reserved by libfuzzer for "future use". No issue about putting this info into the commit message.

Tamas

#17 lore raw
Quoted 13 lines · Tamas K Lengyel
Quoted 11 lines · Jan Beulich

tools/fuzz/x86_instruction_emulator/Makefile afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
tools/fuzz/x86_instruction_emulator/Makefile +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

Quoted 7 lines

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

I'm worried here, to be honest. The wrappers serve a pretty important role, and I'm having a hard time seeing why they shouldn't be needed here when they're needed both for the test and afl harnesses. Could you add some more detail on the build issues you encountered?

Jan

#18 lore raw
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Tamas K Lengyel
Quoted 11 lines · Jan Beulich

tools/fuzz/x86_instruction_emulator/Makefile afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
tools/fuzz/x86_instruction_emulator/Makefile +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Quoted 7 lines
Quoted 2 lines

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

I'm worried here, to be honest. The wrappers serve a pretty important role, and I'm having a hard time seeing why they shouldn't be needed here when they're needed both for the test and afl harnesses. Could you add some more detail on the build issues you encountered?

With wrappers.o included doing the build in the oss-fuzz docker (ubuntu 20.04 base) fails with:

...
clang -O1 -fno-omit-frame-pointer -gline-tables-only
-Wno-error=enum-constexpr-conversion
-Wno-error=incompatible-function-pointer-types
-Wno-error=int-conversion -Wno-error=deprecated-declarations
-Wno-error=implicit-function-declaration -Wno-error=implicit-int
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -m64
-DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-but-set-variable -Wno-unused-local-typedefs -g3 -Werror
-Og -fno-omit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MP
-MF .libfuzzer-harness.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -I/src/xen/tools/fuzz/x86_instruction_emulator/../../../tools/include
-D__XEN_TOOLS__ -iquote . -fsanitize=fuzzer -fsanitize=fuzzer
-Wl,--wrap=fwrite -Wl,--wrap=memcmp -Wl,--wrap=memcpy
-Wl,--wrap=memset -Wl,--wrap=printf -Wl,--wrap=putchar -Wl,--wrap=puts
-Wl,--wrap=snprintf -Wl,--wrap=strstr -Wl,--wrap=vprintf
-Wl,--wrap=vsnprintf fuzz-emul.o x86-emulate.o x86_emulate/0f01.o
x86_emulate/0fae.o x86_emulate/0fc7.o x86_emulate/decode.o
x86_emulate/fpu.o cpuid.o wrappers.o -o libfuzzer-harness
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25 /usr/local/lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer.a(fuzzer.o):
in function `std::__Fuzzer::__libcpp_snprintf_l(char*, unsigned long,
__locale_struct*, char const*, ...)':
cxa_noexception.cpp:(.text._ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz[_ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz]+0x9a):
undefined reference to `__wrap_vsnprintf'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:62: libfuzzer-harness] Error 1
rm x86-emulate.c wrappers.c cpuid.c
make: Leaving directory '/src/xen/tools/fuzz/x86_instruction_emulator'
ERROR:__main__:Building fuzzers failed.

#19 lore raw
Quoted 56 lines · Tamas K Lengyel
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Tamas K Lengyel
Quoted 11 lines · Jan Beulich

tools/fuzz/x86_instruction_emulator/Makefile afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
tools/fuzz/x86_instruction_emulator/Makefile +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Quoted 7 lines
Quoted 2 lines

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

I'm worried here, to be honest. The wrappers serve a pretty important role, and I'm having a hard time seeing why they shouldn't be needed here when they're needed both for the test and afl harnesses. Could you add some more detail on the build issues you encountered?

With wrappers.o included doing the build in the oss-fuzz docker (ubuntu 20.04 base) fails with:

...
clang -O1 -fno-omit-frame-pointer -gline-tables-only

(quoted diff) +0 -17
-Wno-error=enum-constexpr-conversion
-Wno-error=incompatible-function-pointer-types
-Wno-error=int-conversion -Wno-error=deprecated-declarations
-Wno-error=implicit-function-declaration -Wno-error=implicit-int
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -m64
-DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -g3 -Werror
-Og -fno-omit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MP
-MF .libfuzzer-harness.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-I/src/xen/tools/fuzz/x86_instruction_emulator/../../../tools/include
-D__XEN_TOOLS__ -iquote . -fsanitize=fuzzer -fsanitize=fuzzer
-Wl,--wrap=fwrite -Wl,--wrap=memcmp -Wl,--wrap=memcpy
-Wl,--wrap=memset -Wl,--wrap=printf -Wl,--wrap=putchar -Wl,--wrap=puts
-Wl,--wrap=snprintf -Wl,--wrap=strstr -Wl,--wrap=vprintf
-Wl,--wrap=vsnprintf fuzz-emul.o x86-emulate.o x86_emulate/0f01.o

x86_emulate/0fae.o x86_emulate/0fc7.o x86_emulate/decode.o x86_emulate/fpu.o cpuid.o wrappers.o -o libfuzzer-harness
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25 /usr/local/lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer.a(fuzzer.o):
in function `std::__Fuzzer::__libcpp_snprintf_l(char*, unsigned long,

Quoted 8 lines

__locale_struct*, char const*, ...)':
cxa_noexception.cpp:(.text._ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz[_ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz]+0x9a):
undefined reference to `__wrap_vsnprintf'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:62: libfuzzer-harness] Error 1
rm x86-emulate.c wrappers.c cpuid.c
make: Leaving directory '/src/xen/tools/fuzz/x86_instruction_emulator'
ERROR:__main__:Building fuzzers failed.

Hmm, yes, means we'll need an actual vsnprintf() wrapper, not just a declaration thereof.

Jan

#20 lore raw
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Tamas K Lengyel
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Tamas K Lengyel
Quoted 11 lines · Jan Beulich

tools/fuzz/x86_instruction_emulator/Makefile afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
tools/fuzz/x86_instruction_emulator/Makefile +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Quoted 7 lines
Quoted 2 lines

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

I'm worried here, to be honest. The wrappers serve a pretty important role, and I'm having a hard time seeing why they shouldn't be needed here when they're needed both for the test and afl harnesses. Could you add some more detail on the build issues you encountered?

With wrappers.o included doing the build in the oss-fuzz docker (ubuntu 20.04 base) fails with:

...
clang -O1 -fno-omit-frame-pointer -gline-tables-only

(quoted diff) +0 -17
-Wno-error=enum-constexpr-conversion
-Wno-error=incompatible-function-pointer-types
-Wno-error=int-conversion -Wno-error=deprecated-declarations
-Wno-error=implicit-function-declaration -Wno-error=implicit-int
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -m64
-DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -g3 -Werror
-Og -fno-omit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MP
-MF .libfuzzer-harness.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-I/src/xen/tools/fuzz/x86_instruction_emulator/../../../tools/include
-D__XEN_TOOLS__ -iquote . -fsanitize=fuzzer -fsanitize=fuzzer
-Wl,--wrap=fwrite -Wl,--wrap=memcmp -Wl,--wrap=memcpy
-Wl,--wrap=memset -Wl,--wrap=printf -Wl,--wrap=putchar -Wl,--wrap=puts
-Wl,--wrap=snprintf -Wl,--wrap=strstr -Wl,--wrap=vprintf
-Wl,--wrap=vsnprintf fuzz-emul.o x86-emulate.o x86_emulate/0f01.o

x86_emulate/0fae.o x86_emulate/0fc7.o x86_emulate/decode.o
x86_emulate/fpu.o cpuid.o wrappers.o -o libfuzzer-harness
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25 /usr/local/lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer.a(fuzzer.o):
in function `std::__Fuzzer::__libcpp_snprintf_l(char*, unsigned long,
__locale_struct*, char const*, ...)':
cxa_noexception.cpp:(.text._ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz[_ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz]+0x9a):
undefined reference to `__wrap_vsnprintf'

Quoted 8 lines
Quoted 5 lines

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:62: libfuzzer-harness] Error 1
rm x86-emulate.c wrappers.c cpuid.c
make: Leaving directory '/src/xen/tools/fuzz/x86_instruction_emulator' ERROR:__main__:Building fuzzers failed.

Hmm, yes, means we'll need an actual vsnprintf() wrapper, not just a declaration thereof.

I don't really get what this wrapper accomplishes and as I said, fuzzing works with oss-fuzz just fine without it.

Tamas

#21 lore raw
Quoted 71 lines · Tamas K Lengyel
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Tamas K Lengyel
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Tamas K Lengyel
Quoted 11 lines · Jan Beulich

Review afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
(quoted diff) +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Quoted 7 lines
Quoted 2 lines

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

I'm worried here, to be honest. The wrappers serve a pretty important role, and I'm having a hard time seeing why they shouldn't be needed here when they're needed both for the test and afl harnesses. Could you add some more detail on the build issues you encountered?

With wrappers.o included doing the build in the oss-fuzz docker (ubuntu 20.04 base) fails with:

...
clang -O1 -fno-omit-frame-pointer -gline-tables-only

(quoted diff) +0 -17
-Wno-error=enum-constexpr-conversion
-Wno-error=incompatible-function-pointer-types
-Wno-error=int-conversion -Wno-error=deprecated-declarations
-Wno-error=implicit-function-declaration -Wno-error=implicit-int
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -m64
-DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -g3 -Werror
-Og -fno-omit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MP
-MF .libfuzzer-harness.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-I/src/xen/tools/fuzz/x86_instruction_emulator/../../../tools/include
-D__XEN_TOOLS__ -iquote . -fsanitize=fuzzer -fsanitize=fuzzer
-Wl,--wrap=fwrite -Wl,--wrap=memcmp -Wl,--wrap=memcpy
-Wl,--wrap=memset -Wl,--wrap=printf -Wl,--wrap=putchar -Wl,--wrap=puts
-Wl,--wrap=snprintf -Wl,--wrap=strstr -Wl,--wrap=vprintf
-Wl,--wrap=vsnprintf fuzz-emul.o x86-emulate.o x86_emulate/0f01.o

x86_emulate/0fae.o x86_emulate/0fc7.o x86_emulate/decode.o
x86_emulate/fpu.o cpuid.o wrappers.o -o libfuzzer-harness
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25 /usr/local/lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer.a(fuzzer.o):
in function `std::__Fuzzer::__libcpp_snprintf_l(char*, unsigned long,
__locale_struct*, char const*, ...)':
cxa_noexception.cpp:(.text._ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz[_ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz]+0x9a):
undefined reference to `__wrap_vsnprintf'

Quoted 8 lines
Quoted 5 lines

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:62: libfuzzer-harness] Error 1
rm x86-emulate.c wrappers.c cpuid.c
make: Leaving directory '/src/xen/tools/fuzz/x86_instruction_emulator' ERROR:__main__:Building fuzzers failed.

Hmm, yes, means we'll need an actual vsnprintf() wrapper, not just a declaration thereof.

Quoted 1 line

I don't really get what this wrapper accomplishes

They guard against clobbering of in-register state (SIMD registers in particular, but going forward maybe also eGRP-s as introduced by APX) by library functions called between emulation of individual insns (or, especially possible for fuzzing instrumented code, I think) even from in the middle of emulating an insn. (Something as simple as the compiler inserting a call to memcpy() or memset() somewhere in the translation of the emulator source code could also clobber state.)

Quoted 1 line

and as I said, fuzzing works with oss-fuzz just fine without it.

I'm inclined to take this as "it appears to work just fine". Fuzzed input register state may be lost by doing a library call somewhere, rendering the fuzzing results less useful. This would pretty certainly stop being tolerable the moment you compared results of native execution of a sequence of instructions with the emulated counterpart.

Jan

#22 lore raw
Quoted 83 lines · Jan Beulich
Quoted 71 lines · Tamas K Lengyel
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Tamas K Lengyel
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Tamas K Lengyel
Quoted 11 lines · Jan Beulich

Review afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
(quoted diff) +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Quoted 7 lines
Quoted 2 lines

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

I'm worried here, to be honest. The wrappers serve a pretty important role, and I'm having a hard time seeing why they shouldn't be needed here when they're needed both for the test and afl harnesses. Could you add some more detail on the build issues you encountered?

With wrappers.o included doing the build in the oss-fuzz docker (ubuntu 20.04 base) fails with:

...
clang -O1 -fno-omit-frame-pointer -gline-tables-only

(quoted diff) +0 -17
-Wno-error=enum-constexpr-conversion
-Wno-error=incompatible-function-pointer-types
-Wno-error=int-conversion -Wno-error=deprecated-declarations
-Wno-error=implicit-function-declaration -Wno-error=implicit-int
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -m64
-DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -g3 -Werror
-Og -fno-omit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MP
-MF .libfuzzer-harness.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-I/src/xen/tools/fuzz/x86_instruction_emulator/../../../tools/include
-D__XEN_TOOLS__ -iquote . -fsanitize=fuzzer -fsanitize=fuzzer
-Wl,--wrap=fwrite -Wl,--wrap=memcmp -Wl,--wrap=memcpy
-Wl,--wrap=memset -Wl,--wrap=printf -Wl,--wrap=putchar -Wl,--wrap=puts
-Wl,--wrap=snprintf -Wl,--wrap=strstr -Wl,--wrap=vprintf
-Wl,--wrap=vsnprintf fuzz-emul.o x86-emulate.o x86_emulate/0f01.o

x86_emulate/0fae.o x86_emulate/0fc7.o x86_emulate/decode.o
x86_emulate/fpu.o cpuid.o wrappers.o -o libfuzzer-harness
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25 /usr/local/lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer.a(fuzzer.o):
in function `std::__Fuzzer::__libcpp_snprintf_l(char*, unsigned long,
__locale_struct*, char const*, ...)':
cxa_noexception.cpp:(.text._ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz[_ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz]+0x9a):
undefined reference to `__wrap_vsnprintf'

Quoted 8 lines
Quoted 5 lines

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:62: libfuzzer-harness] Error 1
rm x86-emulate.c wrappers.c cpuid.c
make: Leaving directory '/src/xen/tools/fuzz/x86_instruction_emulator' ERROR:__main__:Building fuzzers failed.

Hmm, yes, means we'll need an actual vsnprintf() wrapper, not just a declaration thereof.

Quoted 1 line

I don't really get what this wrapper accomplishes

They guard against clobbering of in-register state (SIMD registers in particular, but going forward maybe also eGRP-s as introduced by APX) by library functions called between emulation of individual insns (or, especially possible for fuzzing instrumented code, I think) even from in the middle of emulating an insn. (Something as simple as the compiler inserting a call to memcpy() or memset() somewhere in the translation of the emulator source code could also clobber state.)

Quoted 8 lines
Quoted 1 line

and as I said, fuzzing works with oss-fuzz just fine without it.

I'm inclined to take this as "it appears to work just fine". Fuzzed input register state may be lost by doing a library call somewhere, rendering the fuzzing results less useful. This would pretty certainly stop being tolerable the moment you compared results of native execution of a sequence of instructions with the emulated counterpart.

Yea, that may be. Any suggested way to fix the linking issue though? I'm not even sure why the problem only appears in the oss-fuzz build, when I just run make normally it seems to work.

Tamas

#23 lore raw
Quoted 86 lines · Tamas K Lengyel
Quoted 85 lines · Jan Beulich
Quoted 71 lines · Tamas K Lengyel
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Tamas K Lengyel
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Tamas K Lengyel
Quoted 11 lines · Jan Beulich

Review afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
(quoted diff) +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Quoted 7 lines
Quoted 2 lines

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

I'm worried here, to be honest. The wrappers serve a pretty important role, and I'm having a hard time seeing why they shouldn't be needed here when they're needed both for the test and afl harnesses. Could you add some more detail on the build issues you encountered?

With wrappers.o included doing the build in the oss-fuzz docker (ubuntu 20.04 base) fails with:

...
clang -O1 -fno-omit-frame-pointer -gline-tables-only

(quoted diff) +0 -17
-Wno-error=enum-constexpr-conversion
-Wno-error=incompatible-function-pointer-types
-Wno-error=int-conversion -Wno-error=deprecated-declarations
-Wno-error=implicit-function-declaration -Wno-error=implicit-int
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -m64
-DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -g3 -Werror
-Og -fno-omit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MP
-MF .libfuzzer-harness.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-I/src/xen/tools/fuzz/x86_instruction_emulator/../../../tools/include
-D__XEN_TOOLS__ -iquote . -fsanitize=fuzzer -fsanitize=fuzzer
-Wl,--wrap=fwrite -Wl,--wrap=memcmp -Wl,--wrap=memcpy
-Wl,--wrap=memset -Wl,--wrap=printf -Wl,--wrap=putchar -Wl,--wrap=puts
-Wl,--wrap=snprintf -Wl,--wrap=strstr -Wl,--wrap=vprintf
-Wl,--wrap=vsnprintf fuzz-emul.o x86-emulate.o x86_emulate/0f01.o

x86_emulate/0fae.o x86_emulate/0fc7.o x86_emulate/decode.o
x86_emulate/fpu.o cpuid.o wrappers.o -o libfuzzer-harness
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25 /usr/local/lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer.a(fuzzer.o):
in function `std::__Fuzzer::__libcpp_snprintf_l(char*, unsigned long,
__locale_struct*, char const*, ...)':
cxa_noexception.cpp:(.text._ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz[_ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz]+0x9a):
undefined reference to `__wrap_vsnprintf'

Quoted 8 lines
Quoted 5 lines

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:62: libfuzzer-harness] Error 1
rm x86-emulate.c wrappers.c cpuid.c
make: Leaving directory '/src/xen/tools/fuzz/x86_instruction_emulator' ERROR:__main__:Building fuzzers failed.

Hmm, yes, means we'll need an actual vsnprintf() wrapper, not just a declaration thereof.

Quoted 1 line

I don't really get what this wrapper accomplishes

They guard against clobbering of in-register state (SIMD registers in particular, but going forward maybe also eGRP-s as introduced by APX) by library functions called between emulation of individual insns (or, especially possible for fuzzing instrumented code, I think) even from in the middle of emulating an insn. (Something as simple as the compiler inserting a call to memcpy() or memset() somewhere in the translation of the emulator source code could also clobber state.)

Quoted 1 line

and as I said, fuzzing works with oss-fuzz just fine without it.

Quoted 8 lines
Quoted 6 lines

I'm inclined to take this as "it appears to work just fine". Fuzzed input register state may be lost by doing a library call somewhere, rendering the fuzzing results less useful. This would pretty certainly stop being tolerable the moment you compared results of native execution of a sequence of instructions with the emulated counterpart.

Yea, that may be. Any suggested way to fix the linking issue though?

As said before, we need to gain a real wrapper for vsnprintf(). Right now we only have a declaration thereof, for use by the wrapper for snprintf().

Quoted 2 lines

I'm not even sure why the problem only appears in the oss-fuzz build, when I just run make normally it seems to work.

Sounds a little odd indeed. Yet I have no idea towards the differences between the two.

Jan

#24 lore raw
Quoted 95 lines · Jan Beulich
Quoted 93 lines · Tamas K Lengyel
Quoted 91 lines · Jan Beulich
Quoted 71 lines · Tamas K Lengyel
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Tamas K Lengyel
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Tamas K Lengyel
Quoted 11 lines · Jan Beulich

Review afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
(quoted diff) +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Quoted 7 lines
Quoted 2 lines

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

I'm worried here, to be honest. The wrappers serve a pretty important role, and I'm having a hard time seeing why they shouldn't be needed here when they're needed both for the test and afl harnesses. Could you add some more detail on the build issues you encountered?

With wrappers.o included doing the build in the oss-fuzz docker (ubuntu 20.04 base) fails with:

...
clang -O1 -fno-omit-frame-pointer -gline-tables-only

(quoted diff) +0 -17
-Wno-error=enum-constexpr-conversion
-Wno-error=incompatible-function-pointer-types
-Wno-error=int-conversion -Wno-error=deprecated-declarations
-Wno-error=implicit-function-declaration -Wno-error=implicit-int
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -m64
-DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -g3 -Werror
-Og -fno-omit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MP
-MF .libfuzzer-harness.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-I/src/xen/tools/fuzz/x86_instruction_emulator/../../../tools/include
-D__XEN_TOOLS__ -iquote . -fsanitize=fuzzer -fsanitize=fuzzer
-Wl,--wrap=fwrite -Wl,--wrap=memcmp -Wl,--wrap=memcpy
-Wl,--wrap=memset -Wl,--wrap=printf -Wl,--wrap=putchar -Wl,--wrap=puts
-Wl,--wrap=snprintf -Wl,--wrap=strstr -Wl,--wrap=vprintf
-Wl,--wrap=vsnprintf fuzz-emul.o x86-emulate.o x86_emulate/0f01.o

x86_emulate/0fae.o x86_emulate/0fc7.o x86_emulate/decode.o
x86_emulate/fpu.o cpuid.o wrappers.o -o libfuzzer-harness
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25 /usr/local/lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer.a(fuzzer.o):
in function `std::__Fuzzer::__libcpp_snprintf_l(char*, unsigned long,
__locale_struct*, char const*, ...)':
cxa_noexception.cpp:(.text._ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz[_ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz]+0x9a):
undefined reference to `__wrap_vsnprintf'

Quoted 8 lines
Quoted 5 lines

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:62: libfuzzer-harness] Error 1
rm x86-emulate.c wrappers.c cpuid.c
make: Leaving directory '/src/xen/tools/fuzz/x86_instruction_emulator' ERROR:__main__:Building fuzzers failed.

Hmm, yes, means we'll need an actual vsnprintf() wrapper, not just a declaration thereof.

Quoted 1 line

I don't really get what this wrapper accomplishes

They guard against clobbering of in-register state (SIMD registers in particular, but going forward maybe also eGRP-s as introduced by APX) by library functions called between emulation of individual insns (or, especially possible for fuzzing instrumented code, I think) even from in the middle of emulating an insn. (Something as simple as the compiler inserting a call to memcpy() or memset() somewhere in the translation of the emulator source code could also clobber state.)

Quoted 1 line

and as I said, fuzzing works with oss-fuzz just fine without it.

I'm inclined to take this as "it appears to work just fine". Fuzzed input register state may be lost by doing a library call somewhere, rendering the fuzzing results less useful. This would pretty certainly stop being tolerable the moment you compared results of native execution of a sequence of instructions with the emulated counterpart.

Quoted 5 lines
Quoted 1 line

Yea, that may be. Any suggested way to fix the linking issue though?

As said before, we need to gain a real wrapper for vsnprintf(). Right now we only have a declaration thereof, for use by the wrapper for snprintf().

Where is this wrapper for snprintf? I can't find anything in fuzz/x86_instruction_emulator. If I can see an example for one that's implemented already I may be able to decipher what's needed here. At the moment I don't really know what "a real wrapper" would look like.

Tamas

#25 lore raw
Quoted 96 lines · Tamas K Lengyel
Quoted 95 lines · Jan Beulich
Quoted 93 lines · Tamas K Lengyel
Quoted 91 lines · Jan Beulich
Quoted 71 lines · Tamas K Lengyel
Quoted 61 lines · Jan Beulich
Quoted 59 lines · Tamas K Lengyel
Quoted 20 lines · Jan Beulich
Quoted 18 lines · Tamas K Lengyel
Quoted 11 lines · Jan Beulich

Review afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o · line 62

Quoted 6 lines · Tamas K Lengyel
(quoted diff) +2 -0
@@ -58,6 +58,9 @@ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o
 afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o
      $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@
 
+libfuzzer-harness: $(OBJS) cpuid.o
+     $(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $^ -o $@

What is LIB_FUZZING_ENGINE? I don't think we have any use of that in the tree anywhere.

It's used by oss-fuzz, otherwise it's not doing anything.

Quoted 2 lines

I'm further surprised you get away here without wrappers.o.

Quoted 7 lines
Quoted 2 lines

Wrappers.o was actually breaking the build for oss-fuzz at the linking stage. It works just fine without it.

I'm worried here, to be honest. The wrappers serve a pretty important role, and I'm having a hard time seeing why they shouldn't be needed here when they're needed both for the test and afl harnesses. Could you add some more detail on the build issues you encountered?

With wrappers.o included doing the build in the oss-fuzz docker (ubuntu 20.04 base) fails with:

...
clang -O1 -fno-omit-frame-pointer -gline-tables-only

(quoted diff) +0 -17
-Wno-error=enum-constexpr-conversion
-Wno-error=incompatible-function-pointer-types
-Wno-error=int-conversion -Wno-error=deprecated-declarations
-Wno-error=implicit-function-declaration -Wno-error=implicit-int
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address
-fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link -m64
-DBUILD_ID -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-but-set-variable -Wno-unused-local-typedefs   -g3 -Werror
-Og -fno-omit-frame-pointer
-D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__ -MMD -MP
-MF .libfuzzer-harness.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-I/src/xen/tools/fuzz/x86_instruction_emulator/../../../tools/include
-D__XEN_TOOLS__ -iquote . -fsanitize=fuzzer -fsanitize=fuzzer
-Wl,--wrap=fwrite -Wl,--wrap=memcmp -Wl,--wrap=memcpy
-Wl,--wrap=memset -Wl,--wrap=printf -Wl,--wrap=putchar -Wl,--wrap=puts
-Wl,--wrap=snprintf -Wl,--wrap=strstr -Wl,--wrap=vprintf
-Wl,--wrap=vsnprintf fuzz-emul.o x86-emulate.o x86_emulate/0f01.o

x86_emulate/0fae.o x86_emulate/0fc7.o x86_emulate/decode.o
x86_emulate/fpu.o cpuid.o wrappers.o -o libfuzzer-harness
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25 /usr/local/lib/clang/18/lib/x86_64-unknown-linux-gnu/libclang_rt.fuzzer.a(fuzzer.o):
in function `std::__Fuzzer::__libcpp_snprintf_l(char*, unsigned long,
__locale_struct*, char const*, ...)':
cxa_noexception.cpp:(.text._ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz[_ZNSt8__Fuzzer19__libcpp_snprintf_lEPcmP15__locale_structPKcz]+0x9a):
undefined reference to `__wrap_vsnprintf'

Quoted 8 lines
Quoted 5 lines

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:62: libfuzzer-harness] Error 1
rm x86-emulate.c wrappers.c cpuid.c
make: Leaving directory '/src/xen/tools/fuzz/x86_instruction_emulator' ERROR:__main__:Building fuzzers failed.

Hmm, yes, means we'll need an actual vsnprintf() wrapper, not just a declaration thereof.

Quoted 1 line

I don't really get what this wrapper accomplishes

They guard against clobbering of in-register state (SIMD registers in particular, but going forward maybe also eGRP-s as introduced by APX) by library functions called between emulation of individual insns (or, especially possible for fuzzing instrumented code, I think) even from in the middle of emulating an insn. (Something as simple as the compiler inserting a call to memcpy() or memset() somewhere in the translation of the emulator source code could also clobber state.)

Quoted 1 line

and as I said, fuzzing works with oss-fuzz just fine without it.

I'm inclined to take this as "it appears to work just fine". Fuzzed input register state may be lost by doing a library call somewhere, rendering the fuzzing results less useful. This would pretty certainly stop being tolerable the moment you compared results of native execution of a sequence of instructions with the emulated counterpart.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Yea, that may be. Any suggested way to fix the linking issue though?

As said before, we need to gain a real wrapper for vsnprintf(). Right now we only have a declaration thereof, for use by the wrapper for snprintf().

Where is this wrapper for snprintf? I can't find anything in fuzz/x86_instruction_emulator.

The fuzzing stuff reuses files from the test harness, i.e. tools/tests/x86_emulator/wrappers.c in this case. Much like cpuid.c is coming from elsewhere, too.

Jan