Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sycl/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ if (SYCL_ENABLE_XPTI_TRACING)
endif()
endif()

add_subdirectory(fuzzers)
1 change: 1 addition & 0 deletions sycl/tools/fuzzers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(sycl-config-fuzzer)
53 changes: 53 additions & 0 deletions sycl/tools/fuzzers/sycl-config-fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
add_executable(sycl-config-fuzzer
EXCLUDE_FROM_ALL
main.cpp
# ${SYCL_SOURCE_DIR}/source/detail/config.cpp
# ${SYCL_SOURCE_DIR}/source/exception.cpp
# ${SYCL_SOURCE_DIR}/source/detail/os_util.cpp
)

if (TARGET sycl-config-fuzzer)
target_compile_options(
sycl-config-fuzzer
PRIVATE
-fsanitize=fuzzer
#-fsanitize=address
-fprofile-instr-generate -fcoverage-mapping
-g
)

target_link_libraries(sycl-config-fuzzer
PRIVATE
$<TARGET_OBJECTS:sycl_object>
$<GENEX_EVAL:$<TARGET_PROPERTY:sycl,LINK_LIBRARIES>>
)

target_link_options(
sycl-config-fuzzer
PRIVATE
-fsanitize=fuzzer
-fprofile-instr-generate -fcoverage-mapping
#-fsanitize=address
)

set_target_properties(sycl-config-fuzzer PROPERTIES FOLDER "SYCL/Fuzzers")
target_include_directories(sycl-config-fuzzer
PRIVATE SYSTEM
${SYCL_SOURCE_DIR}/source/
)

set(CORPUS_BINARY_DIR ${CMAKE_BINARY_DIR}/fuzzer-artifacts/sycl-config-corpus)

add_custom_command(TARGET sycl-config-fuzzer PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/fuzzer-artifacts/sycl-config-artifacts
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/corpus ${CORPUS_BINARY_DIR}
)

add_custom_target(fuzz-sycl-config
COMMENT "Running the SYCL config fuzzer for a minute..."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/fuzzer-artifacts/sycl-config-artifacts
COMMAND $<TARGET_FILE:sycl-config-fuzzer> ${CORPUS_BINARY_DIR} -artifact_prefix=config- -max_total_time=600
USES_TERMINAL
)
set_target_properties(fuzz-sycl-config PROPERTIES FOLDER "SYCL/Fuzzers")
endif()
35 changes: 35 additions & 0 deletions sycl/tools/fuzzers/sycl-config-fuzzer/corpus/all-options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
SYCL_PRINT_EXECUTION_GRAPH=1
SYCL_DISABLE_EXECUTION_GRAPH_CLEANUP=0
SYCL_DISABLE_POST_ENQUEUE_CLEANUP=1
SYCL_DEVICE_ALLOWLIST=a;b;c
SYCL_UR_TRACE=-1
SYCL_PARALLEL_FOR_RANGE_ROUNDING_TRACE=1
SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING=0
SYCL_PARALLEL_FOR_RANGE_ROUNDING_PARAMS=32;4;4
SYCL_DEVICELIB_NO_FALLBACK=1
SYCL_PROGRAM_LINK_OPTIONS="-ze-opt-disable"
SYCL_PROGRAM_COMPILE_OPTIONS="-ze-opt-level=2"
SYCL_PROGRAM_APPEND_LINK_OPTIONS=2
SYCL_PROGRAM_APPEND_COMPILE_OPTIONS=1
SYCL_HOST_UNIFIED_MEMORY=1
SYCL_CACHE_DIR="C:/path/to/some/dir with spaces"
SYCL_CACHE_TRACE=1
SYCL_IN_MEM_CACHE_EVICTION_THRESHOLD=32
SYCL_CACHE_DISABLE_PERSISTENT=1
SYCL_CACHE_PERSISTENT=1
SYCL_CACHE_EVICTION_DISABLE=0
SYCL_CACHE_MAX_SIZE=-1
SYCL_CACHE_THRESHOLD=64
SYCL_CACHE_MIN_DEVICE_IMAGE_SIZE=32
SYCL_CACHE_MAX_DEVICE_IMAGE_SIZE=128
INTEL_ENABLE_OFFLOAD_ANNOTATIONS=1
SYCL_ENABLE_DEFAULT_CONTEXTS=0
SYCL_QUEUE_THREAD_POOL_SIZE=16
SYCL_RT_WARNING_LEVEL=4
SYCL_REDUCTION_PREFERRED_WORKGROUP_SIZE=256
ONEAPI_DEVICE_SELECTOR="*:gpu;opencl:gpu"
SYCL_ENABLE_FUSION_CACHING=0
SYCL_CACHE_IN_MEM=1
SYCL_JIT_AMDGCN_PTX_KERNELS=1
SYCL_JIT_AMDGCN_PTX_TARGET_CPU=1
SYCL_JIT_AMDGCN_PTX_TARGET_FEATURES="+A,-B"
2 changes: 2 additions & 0 deletions sycl/tools/fuzzers/sycl-config-fuzzer/corpus/clrf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SYCL_CACHE_DIR=c:/path/to/dir
SYCL_QUEUE_THREAD_POOL_SIZE=23
4 changes: 4 additions & 0 deletions sycl/tools/fuzzers/sycl-config-fuzzer/corpus/comments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Comment
OPTION=value # comment
#comment
OPTION2=value #comment
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SYCL_UR_TRACE=1
SYCL_UR_TRACE=-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SYCL_UR_TRACE=-1
ONEAPI_DEVICE_SELECTOR=opencl:gpu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SYCL_CACHE_IN_MEM=1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UNKNOWN_OPTION=some-random-value
Empty file.
63 changes: 63 additions & 0 deletions sycl/tools/fuzzers/sycl-config-fuzzer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//===------- main.cpp - Fuzz SYCL config file parsing ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <detail/config.hpp>

#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>

bool contains(const std::string &haystack, const std::string &needle) {
return haystack.find(needle) != std::string::npos;
}

extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
// Create (or re-create) a temporary file which will store fuzzed config and
// write fuzzed data into it.
{
std::fstream file("sycl-config-temp.txt", std::ios::out | std::ios::binary);
if (!file.is_open()) {
std::cerr << "Failed to create sycl-config-temp.txt!" << std::endl;
return 1;
}

try {
file.write(reinterpret_cast<char *>(data), size);
} catch (std::exception &e) {
std::cerr
<< "Error happened during writing data into sycl-config-temp.txt: "
<< e.what() << std::endl;
return 2;
}

if (file.bad() || file.fail()) {
std::cerr << "Error happened during writing data into sycl-config-temp.txt!"
<< std::endl;
return 3;
}
}

// Make sure that the right config file will be read
setenv("SYCL_CONFIG_FILE_NAME", "sycl-config-temp.txt", 1);

try {
sycl::detail::readConfig(/* ForceInitialization = */ true);
} catch (sycl::exception &e) {
// There are format requirements for the config file. To make sure that no
// false positives are emitted if randomly-generated input looks _like_ a
// valid config, but violate format requirements, we ignore certain
// exceptions here.
if (!contains(e.what(), "SPACE found at the beginning/end") &&
!contains(e.what(), "The value contains more than") &&
!contains(e.what(), "Variable name is more than"))
throw e;
}

return 0;
}
Loading