Skip to content

Commit 1a4e22d

Browse files
authored
Merge pull request #1070 from intel/syncing_msft_30_4_2026
Backmerging PR
2 parents c01cf58 + 53de33a commit 1a4e22d

97 files changed

Lines changed: 5220 additions & 269 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
name: python-kwargs-setattr-security
3+
description: When reviewing or fixing Python code that uses setattr() with user-controlled kwargs to configure C++ extension objects (SessionOptions, RunOptions, etc.) in ONNX Runtime. Use this to apply the allowlist pattern that prevents arbitrary file writes and other attacks via reflected property access.
4+
---
5+
6+
## Problem Pattern
7+
8+
Using `hasattr(obj, k) / setattr(obj, k, v)` with user-controlled kwargs is insecure. The `hasattr` check is NOT a security guard — it returns True for ALL exposed properties including dangerous ones.
9+
10+
```python
11+
# INSECURE — do not use
12+
for k, v in kwargs.items():
13+
if hasattr(options, k):
14+
setattr(options, k, v)
15+
```
16+
17+
## Fix: Explicit Allowlist
18+
19+
Define a module-level frozenset of safe attribute names. Raise RuntimeError for known-but-blocked attrs; silently ignore unknown keys.
20+
21+
```python
22+
# Define at module level, before the class
23+
_ALLOWED_SESSION_OPTIONS = frozenset({
24+
"enable_cpu_mem_arena",
25+
"enable_mem_pattern",
26+
# ... only explicitly reviewed safe attrs
27+
})
28+
29+
# In the method
30+
for k, v in kwargs.items():
31+
if k in _ALLOWED_SESSION_OPTIONS:
32+
setattr(options, k, v)
33+
elif hasattr(options, k): # reuse the existing instance, don't create new
34+
raise RuntimeError(
35+
f"SessionOptions attribute '{k}' is not permitted via the backend API. "
36+
f"Allowed attributes: {', '.join(sorted(_ALLOWED_SESSION_OPTIONS))}"
37+
)
38+
# else: silently ignore (may be kwargs for a different config object)
39+
```
40+
41+
## Key Rules
42+
43+
1. **Use the existing object** in `hasattr(options, k)` — never `hasattr(ClassName(), k)` (creates throwaway C++ objects per iteration)
44+
2. **RuntimeError** is the ORT convention for API misuse errors (not ValueError)
45+
3. **Silent ignore for one path is OK when kwargs are forwarded to both paths**: `run_model()` passes the same kwargs dict to both `prepare()` (validates SessionOptions) and `rep.run()` (validates RunOptions). A RunOptions kwarg unknown to SessionOptions is silently ignored by `prepare()` — this is correct because `rep.run()` will validate it. Only raise RuntimeError when the attr exists on the target object but is blocked.
46+
4. **Frozenset constant naming**: `_ALLOWED_<CLASSNAME>` — ALL_CAPS, Google Style
47+
5. **No type annotations** on module-level constants (ORT Python convention)
48+
49+
## Dangerous SessionOptions Properties (never allowlist)
50+
51+
- `optimized_model_filepath` — triggers Model::Save(), overwrites arbitrary files
52+
- `profile_file_prefix` + `enable_profiling` — writes profiling JSON to arbitrary path
53+
- `register_custom_ops_library` — loads arbitrary shared libraries (method, not property)
54+
55+
## Files in ONNX Runtime
56+
57+
- `onnxruntime/python/backend/backend.py``_ALLOWED_SESSION_OPTIONS`
58+
- `onnxruntime/python/backend/backend_rep.py``_ALLOWED_RUN_OPTIONS`
59+
- Tests: `onnxruntime/test/python/onnxruntime_test_python_backend.py``TestBackendKwargsAllowlist`

.github/workflows/windows_openvino.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ jobs:
5151
with:
5252
architecture: x64
5353

54-
- name: Download OpenVINO Toolkit v2025.4.1
54+
- name: Download OpenVINO Toolkit v2026.1.0
5555
env:
56-
OpenVINOVersion: 2025.4.1
56+
OpenVINOVersion: 2026.1.0
5757
shell: pwsh
5858
run: |
59-
$Url ="https://storage.openvinotoolkit.org/repositories/openvino/packages/2025.4.1/windows/openvino_toolkit_windows_2025.4.1.20426.82bbf0292c5_x86_64.zip"
59+
$Url ="https://storage.openvinotoolkit.org/repositories/openvino/packages/2026.1/windows_vc_mt/openvino_toolkit_windows_vc_mt_2026.1.0.21367.63e31528c62_x86_64.zip"
6060
$OutputPath = "$env:RUNNER_TEMP\openvino.zip"
6161
$ExtractPath = "$env:RUNNER_TEMP\openvino-v$env:OpenVINOVersion"
6262
$TempExtractPath = "$env:RUNNER_TEMP\openvino_temp"
@@ -99,7 +99,7 @@ jobs:
9999
shell: pwsh
100100
# Use $GITHUB_ENV to set the variable for subsequent steps
101101
run: |
102-
$openVinoRootDir = Join-Path $env:RUNNER_TEMP "openvino-v2025.4.1"
102+
$openVinoRootDir = Join-Path $env:RUNNER_TEMP "openvino-v2026.1.0"
103103
echo "OpenVINORootDir=$openVinoRootDir" >> $env:GITHUB_ENV
104104
105105
- name: Print OpenVINORootDir after downloading OpenVINO

cmake/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ option(onnxruntime_USE_RKNPU "Build with RKNPU support" OFF)
8989
option(onnxruntime_USE_DNNL "Build with DNNL support" OFF)
9090
option(onnxruntime_USE_JSEP "Build with JavaScript implemented kernels support" OFF)
9191
option(onnxruntime_USE_SVE "Build with SVE support in MLAS" OFF)
92+
option(onnxruntime_USE_RVV "Build with RISC-V Vector support in MLAS" OFF)
9293
option(onnxruntime_USE_ARM_NEON_NCHWC "Build with ARM Neon NCHWc kernels in MLAS" OFF)
9394

9495
option(onnxruntime_USE_KLEIDIAI "Build with KleidiAI integration in MLAS" OFF)

cmake/deps.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pytorch_cpuinfo;https://github.com/pytorch/cpuinfo/archive/403d652dca4c1046e8145
5151
re2;https://github.com/google/re2/archive/refs/tags/2024-07-02.zip;646e1728269cde7fcef990bf4a8e87b047882e88
5252
safeint;https://github.com/dcleblanc/SafeInt/archive/refs/tags/3.0.28.zip;23f252040ff6cb9f1fd18575b32fa8fb5928daac
5353
tensorboard;https://github.com/tensorflow/tensorboard/archive/373eb09e4c5d2b3cc2493f0949dc4be6b6a45e81.zip;67b833913605a4f3f499894ab11528a702c2b381
54-
cutlass;https://github.com/NVIDIA/cutlass/archive/refs/tags/v4.2.1.zip;5d2b21b10478556c5e209dd7229e298a5c9f0b02
54+
cutlass;https://github.com/NVIDIA/cutlass/archive/refs/tags/v4.4.2.zip;4b0bae4428b84370407c0a71778b13dc2eee5be1
5555
extensions;https://github.com/microsoft/onnxruntime-extensions/archive/c24b7bab0c12f53da76d0c31b03b9f0f8ec8f3b4.zip;239063aee4946a9af147b473a4c3da78ba7413b4
5656
directx_headers;https://github.com/microsoft/DirectX-Headers/archive/refs/tags/v1.613.1.zip;47653509a3371eabb156360f42faf582f314bf2e
5757
cudnn_frontend;https://github.com/NVIDIA/cudnn-frontend/archive/refs/tags/v1.12.0.zip;7e733cfdc410d777b76122d64232499205589a96

cmake/external/cutlass.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ onnxruntime_fetchcontent_declare(
44
URL ${DEP_URL_cutlass}
55
URL_HASH SHA1=${DEP_SHA1_cutlass}
66
EXCLUDE_FROM_ALL
7-
PATCH_COMMAND ${Patch_EXECUTABLE} --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/cutlass/cutlass_4.2.1.patch
7+
PATCH_COMMAND ${Patch_EXECUTABLE} --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/cutlass/cutlass_4.4.2.patch
88
)
99

1010
FetchContent_GetProperties(cutlass)

cmake/external/onnxruntime_external_deps.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,18 @@ if (CPUINFO_SUPPORTED)
376376
${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/win_arm_fp16_detection_fallback.patch
377377
FIND_PACKAGE_ARGS NAMES cpuinfo
378378
)
379+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
380+
message(STATUS "Applying sysfs fallback patch for cpuinfo on Linux")
381+
onnxruntime_fetchcontent_declare(
382+
pytorch_cpuinfo
383+
URL ${DEP_URL_pytorch_cpuinfo}
384+
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
385+
EXCLUDE_FROM_ALL
386+
PATCH_COMMAND
387+
# https://github.com/microsoft/onnxruntime/issues/10038
388+
${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/fix_missing_sysfs_fallback.patch
389+
FIND_PACKAGE_ARGS NAMES cpuinfo
390+
)
379391
else()
380392
onnxruntime_fetchcontent_declare(
381393
pytorch_cpuinfo

cmake/onnxruntime_mlas.cmake

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ else()
435435
set(X86 TRUE)
436436
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$")
437437
set(X86_64 TRUE)
438+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^riscv64.*")
439+
set(RISCV64 TRUE)
438440
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^loongarch64.*")
439441
set(LOONGARCH64 TRUE)
440442
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390x$")
@@ -903,6 +905,48 @@ endif()
903905
set(MLAS_SOURCE_IS_NOT_SET 0)
904906
endif()
905907
endif()
908+
if(RISCV64 AND MLAS_SOURCE_IS_NOT_SET)
909+
file(GLOB_RECURSE mlas_platform_srcs CONFIGURE_DEPENDS
910+
"${MLAS_SRC_DIR}/scalar/*.cpp")
911+
912+
if(onnxruntime_USE_RVV)
913+
set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
914+
set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS} -march=rv64gcv -mabi=lp64d")
915+
check_cxx_source_compiles("
916+
#include <stddef.h>
917+
#include <riscv_vector.h>
918+
int main() {
919+
size_t vl = __riscv_vsetvl_e32m1(4);
920+
return static_cast<int>(vl == 0);
921+
}"
922+
HAS_RISCV64_RVV
923+
)
924+
set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
925+
unset(OLD_CMAKE_REQUIRED_FLAGS)
926+
927+
if(HAS_RISCV64_RVV)
928+
list(APPEND mlas_platform_srcs
929+
${MLAS_SRC_DIR}/riscv64/sgemm_pack_b_rvv.cpp
930+
${MLAS_SRC_DIR}/riscv64/sgemm_kernel_rvv.cpp
931+
${MLAS_SRC_DIR}/riscv64/softmax_kernel_rvv.cpp
932+
)
933+
set_source_files_properties(
934+
${MLAS_SRC_DIR}/riscv64/sgemm_pack_b_rvv.cpp
935+
${MLAS_SRC_DIR}/riscv64/sgemm_kernel_rvv.cpp
936+
${MLAS_SRC_DIR}/riscv64/softmax_kernel_rvv.cpp
937+
PROPERTIES COMPILE_FLAGS "-march=rv64gcv -mabi=lp64d")
938+
list(APPEND mlas_private_compile_definitions MLAS_USE_RVV=1)
939+
else()
940+
message(
941+
WARNING
942+
"onnxruntime_USE_RVV was requested, but the compiler does not support rv64gcv RVV intrinsics. Falling back to scalar MLAS kernels.")
943+
endif()
944+
endif()
945+
946+
if(NOT ONNXRUNTIME_MLAS_MULTI_ARCH)
947+
set(MLAS_SOURCE_IS_NOT_SET 0)
948+
endif()
949+
endif()
906950
if(NOT ONNXRUNTIME_MLAS_MULTI_ARCH AND MLAS_SOURCE_IS_NOT_SET)
907951
file(GLOB_RECURSE mlas_platform_srcs
908952
"${MLAS_SRC_DIR}/scalar/*.cpp")
@@ -997,4 +1041,4 @@ if (NOT onnxruntime_ORT_MINIMAL_BUILD)
9971041
endif()
9981042
endif()
9991043

1000-
endif()
1044+
endif()

cmake/onnxruntime_unittests.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
14001400

14011401
SET(MLAS_BENCH_DIR ${TEST_SRC_DIR}/mlas/bench)
14021402
file(GLOB_RECURSE MLAS_BENCH_SOURCE_FILES "${MLAS_BENCH_DIR}/*.cpp" "${MLAS_BENCH_DIR}/*.h")
1403+
list(FILTER MLAS_BENCH_SOURCE_FILES EXCLUDE REGEX "${MLAS_BENCH_DIR}/riscv64/.*")
14031404
onnxruntime_add_executable(onnxruntime_mlas_benchmark ${MLAS_BENCH_SOURCE_FILES} ${ONNXRUNTIME_ROOT}/core/framework/error_code.cc)
14041405
target_include_directories(onnxruntime_mlas_benchmark PRIVATE ${ONNXRUNTIME_ROOT}/core/mlas/inc)
14051406
target_link_libraries(onnxruntime_mlas_benchmark PRIVATE benchmark::benchmark onnxruntime_util ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common ${CMAKE_DL_LIBS})
@@ -1418,6 +1419,33 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
14181419
target_link_libraries(onnxruntime_mlas_benchmark PRIVATE cpuinfo)
14191420
endif()
14201421
set_target_properties(onnxruntime_mlas_benchmark PROPERTIES FOLDER "ONNXRuntimeTest")
1422+
1423+
endif()
1424+
1425+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^riscv64.*")
1426+
set(MLAS_RISCV64_BENCH_DIR ${TEST_SRC_DIR}/mlas/bench/riscv64)
1427+
1428+
onnxruntime_add_executable(
1429+
onnxruntime_mlas_sgemm_riscv_bench
1430+
${MLAS_RISCV64_BENCH_DIR}/sgemm_riscv_bench.cpp)
1431+
target_include_directories(onnxruntime_mlas_sgemm_riscv_bench PRIVATE ${ONNXRUNTIME_ROOT}/core/mlas/inc)
1432+
target_link_libraries(
1433+
onnxruntime_mlas_sgemm_riscv_bench
1434+
PRIVATE ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common ${CMAKE_DL_LIBS})
1435+
target_compile_definitions(onnxruntime_mlas_sgemm_riscv_bench PRIVATE ${mlas_private_compile_definitions})
1436+
set_target_properties(onnxruntime_mlas_sgemm_riscv_bench PROPERTIES FOLDER "ONNXRuntimeTest")
1437+
1438+
onnxruntime_add_executable(
1439+
onnxruntime_mlas_softmax_riscv_compare
1440+
${MLAS_RISCV64_BENCH_DIR}/softmax_rvv_compare.cpp)
1441+
target_include_directories(
1442+
onnxruntime_mlas_softmax_riscv_compare
1443+
PRIVATE ${ONNXRUNTIME_ROOT} ${ONNXRUNTIME_ROOT}/core/mlas/inc)
1444+
target_link_libraries(
1445+
onnxruntime_mlas_softmax_riscv_compare
1446+
PRIVATE ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common ${CMAKE_DL_LIBS})
1447+
target_compile_definitions(onnxruntime_mlas_softmax_riscv_compare PRIVATE ${mlas_private_compile_definitions})
1448+
set_target_properties(onnxruntime_mlas_softmax_riscv_compare PROPERTIES FOLDER "ONNXRuntimeTest")
14211449
endif()
14221450

14231451
if(WIN32)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
diff --git a/src/linux/processors.c b/src/linux/processors.c
2+
index 47bee76..d0c5569 100644
3+
--- a/src/linux/processors.c
4+
+++ b/src/linux/processors.c
5+
@@ -2,0 +3 @@
6+
+#include <unistd.h>
7+
@@ -291,0 +293,22 @@
8+
+static uint32_t cpuinfo_linux_get_max_processor_from_sysconf(
9+
+ uint32_t max_processors_count,
10+
+ const char* processor_list_name) {
11+
+ const long nproc = sysconf(_SC_NPROCESSORS_ONLN);
12+
+ if (nproc <= 0) {
13+
+ cpuinfo_log_warning(
14+
+ "failed to query online processors from sysconf(_SC_NPROCESSORS_ONLN) for %s",
15+
+ processor_list_name);
16+
+ return UINT32_MAX;
17+
+ }
18+
+
19+
+ uint32_t max_processor = (uint32_t)(nproc - 1);
20+
+ if ((uint64_t)nproc > (uint64_t)max_processors_count) {
21+
+ cpuinfo_log_warning(
22+
+ "online processors count %ld exceeds system limit %" PRIu32 ": truncating to the latter",
23+
+ nproc,
24+
+ max_processors_count);
25+
+ max_processor = max_processors_count - 1;
26+
+ }
27+
+ return max_processor;
28+
+}
29+
+
30+
@@ -301 +324 @@
31+
- return UINT32_MAX;
32+
+ return cpuinfo_linux_get_max_processor_from_sysconf(max_processors_count, POSSIBLE_CPULIST_FILENAME);
33+
@@ -323 +346 @@
34+
- return UINT32_MAX;
35+
+ return cpuinfo_linux_get_max_processor_from_sysconf(max_processors_count, PRESENT_CPULIST_FILENAME);
36+
@@ -357,0 +381,31 @@
37+
+static bool cpuinfo_linux_detect_processors_from_sysconf(
38+
+ uint32_t max_processors_count,
39+
+ uint32_t* processor0_flags,
40+
+ uint32_t processor_struct_size,
41+
+ uint32_t detected_flag,
42+
+ const char* processor_list_name) {
43+
+ const long nproc = sysconf(_SC_NPROCESSORS_ONLN);
44+
+ if (nproc <= 0) {
45+
+ cpuinfo_log_warning(
46+
+ "failed to query online processors from sysconf(_SC_NPROCESSORS_ONLN) for %s",
47+
+ processor_list_name);
48+
+ return false;
49+
+ }
50+
+
51+
+ uint32_t processors_count = (uint32_t)nproc;
52+
+ if ((uint64_t)nproc > (uint64_t)max_processors_count) {
53+
+ cpuinfo_log_warning(
54+
+ "online processors count %ld exceeds system limit %" PRIu32 ": truncating to the latter",
55+
+ nproc,
56+
+ max_processors_count);
57+
+ processors_count = max_processors_count;
58+
+ }
59+
+
60+
+ for (uint32_t processor = 0; processor < processors_count; processor++) {
61+
+ *((uint32_t*)((uintptr_t)processor0_flags + processor_struct_size * processor)) |= detected_flag;
62+
+ }
63+
+ cpuinfo_log_warning(
64+
+ "falling back to sysconf(_SC_NPROCESSORS_ONLN) = %ld for %s", nproc, processor_list_name);
65+
+ return true;
66+
+}
67+
+
68+
@@ -373 +427,6 @@
69+
- return false;
70+
+ return cpuinfo_linux_detect_processors_from_sysconf(
71+
+ max_processors_count,
72+
+ processor0_flags,
73+
+ processor_struct_size,
74+
+ possible_flag,
75+
+ POSSIBLE_CPULIST_FILENAME);
76+
@@ -392 +451,6 @@
77+
- return false;
78+
+ return cpuinfo_linux_detect_processors_from_sysconf(
79+
+ max_processors_count,
80+
+ processor0_flags,
81+
+ processor_struct_size,
82+
+ present_flag,
83+
+ PRESENT_CPULIST_FILENAME);

0 commit comments

Comments
 (0)