From 3041dfa8d20d783da9ac3a1623629e376735a1c3 Mon Sep 17 00:00:00 2001 From: handyohos Date: Fri, 15 May 2026 10:22:25 +0800 Subject: [PATCH 1/4] #150 Fix container_escape_detection and xpm apply scripts - Fix path quoting issue in container_escape_detection/apply_ced.sh - Add xpm header symlinks in xpm/apply_xpm.sh - Use mkdir -p for safer directory creation - Add ohoe_headers directory for OpenHarmony specific headers Co-Authored-By: Agent Signed-off-by: handyohos Change-Id: Ibb407412ab60cea209d0a3b40f17b1febf0ffedb --- container_escape_detection/apply_ced.sh | 4 +- ohoe_headers/apply_ohoe_headers.sh | 79 +++++++++++++++++++++++++ xpm/apply_xpm.sh | 9 ++- 3 files changed, 88 insertions(+), 4 deletions(-) create mode 100755 ohoe_headers/apply_ohoe_headers.sh diff --git a/container_escape_detection/apply_ced.sh b/container_escape_detection/apply_ced.sh index 2d34691..d2dda32 100755 --- a/container_escape_detection/apply_ced.sh +++ b/container_escape_detection/apply_ced.sh @@ -15,8 +15,8 @@ function main() { pushd . - if [ ! -d " $KERNEL_BUILD_ROOT/security/container_escape_detection" ]; then - mkdir $KERNEL_BUILD_ROOT/security/container_escape_detection + if [ ! -d "$KERNEL_BUILD_ROOT/security/container_escape_detection" ]; then + mkdir -p $KERNEL_BUILD_ROOT/security/container_escape_detection fi cd $KERNEL_BUILD_ROOT/security/container_escape_detection diff --git a/ohoe_headers/apply_ohoe_headers.sh b/ohoe_headers/apply_ohoe_headers.sh new file mode 100755 index 0000000..ace6971 --- /dev/null +++ b/ohoe_headers/apply_ohoe_headers.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# Copyright (c) 2025 Huawei Device Co., Ltd. +# OpenHarmony specific header files injection for Linux kernel +# +# This script injects OpenHarmony-specific header files that are not +# present in the upstream Linux kernel but are required by OpenHarmony +# kernel modifications. + +set -e + +OHOS_ROOT_PATH=$1 +KERNEL_SRC_TMP_PATH=$2 +DEVICE_NAME=$3 +KERNEL_VERSION=$4 + +if [ -z "${OHOS_ROOT_PATH}" ] || [ -z "${KERNEL_SRC_TMP_PATH}" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Define header files to inject (from linux-5.10) +HEADER_BASE="${OHOS_ROOT_PATH}/kernel/linux/linux-5.10/include/linux" + +# Headers that are referenced by OpenHarmony kernel code +# but not present in upstream Linux-6.6 +HEADERS=( + "memcg_policy.h" + "memcheck.h" + "hyperhold_inf.h" + "lowmem_dbg.h" + "xpm.h" + "xpm_types.h" + "zswapd.h" + "mm_purgeable.h" + "reclaim_acct.h" +) + +# Target directory in the kernel source tree +TARGET_DIR="${KERNEL_SRC_TMP_PATH}/include/linux" + +echo "Applying OpenHarmony specific header files..." + +# Create target directory if it doesn't exist +mkdir -p "${TARGET_DIR}" + +# Copy each header file +for header in "${HEADERS[@]}"; do + if [ -f "${HEADER_BASE}/${header}" ]; then + cp "${HEADER_BASE}/${header}" "${TARGET_DIR}/${header}" + echo " Injected: ${header}" + else + echo " Warning: ${header} not found in source, skipping" + fi +done + +# memory_group_manager.h comes from rk3568_patch (ARM Mali GPU memory management) +# This is only needed if GPU support is enabled +MGM_HEADER="${OHOS_ROOT_PATH}/kernel/linux/patches/linux-6.6/rk3568_patch/kernel.patch" + +if [ -f "${MGM_HEADER}" ]; then + # Extract memory_group_manager.h from the patch + echo " Extracting memory_group_manager.h from rk3568_patch..." + awk ' + /\+\+\+ b\/include\/linux\/memory_group_manager.h/ { + p = 1 + next + } + p && /^\+/ { + print substr($0, 2) + if (/^+ \*\/$/) exit + } + p && /^@/ { exit } + ' "${MGM_HEADER}" > "${TARGET_DIR}/memory_group_manager.h" + echo " Injected: memory_group_manager.h (extracted from rk3568_patch)" +else + echo " Warning: memory_group_manager.h source not found, skipping" +fi + +echo "OpenHarmony header files injection complete." diff --git a/xpm/apply_xpm.sh b/xpm/apply_xpm.sh index e8947a9..6a4f3a2 100755 --- a/xpm/apply_xpm.sh +++ b/xpm/apply_xpm.sh @@ -10,15 +10,20 @@ KERNEL_BUILD_ROOT=$2 PRODUCT_NAME=$3 KERNEL_VERSION=$4 XPM_SOURCE_ROOT=$OHOS_SOURCE_ROOT/kernel/linux/common_modules/xpm +XPM_HEADER_SOURCE_ROOT=$OHOS_SOURCE_ROOT/kernel/linux/linux-5.10/include/linux function main() { pushd . - if [ ! -d " $KERNEL_BUILD_ROOT/security/xpm" ]; then - mkdir $KERNEL_BUILD_ROOT/security/xpm + if [ ! -d "$KERNEL_BUILD_ROOT/security/xpm" ]; then + mkdir -p $KERNEL_BUILD_ROOT/security/xpm fi + cd $KERNEL_BUILD_ROOT/include/linux + ln -s -f $(realpath --relative-to=$KERNEL_BUILD_ROOT/include/linux $XPM_HEADER_SOURCE_ROOT)/xpm.h ./ + ln -s -f $(realpath --relative-to=$KERNEL_BUILD_ROOT/include/linux $XPM_HEADER_SOURCE_ROOT)/xpm_types.h ./ + cd $KERNEL_BUILD_ROOT/security/xpm ln -s -f $(realpath --relative-to=$KERNEL_BUILD_ROOT/security/xpm/ $XPM_SOURCE_ROOT)/* ./ From 6b6669ca45ff97657d4767318c8b97f1700c799b Mon Sep 17 00:00:00 2001 From: handyohos Date: Fri, 15 May 2026 18:23:01 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20xpm=20=E5=A4=B4?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BB=8E=20ohoe=5Fheaders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xpm 头文件将通过 xpm 模块单独处理。 Co-Authored-By: Agent Signed-off-by: handyohos Change-Id: I7fd3480421c7c846ebe19325a6cfc6343f5291ed --- ohoe_headers/apply_ohoe_headers.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ohoe_headers/apply_ohoe_headers.sh b/ohoe_headers/apply_ohoe_headers.sh index ace6971..a16e922 100755 --- a/ohoe_headers/apply_ohoe_headers.sh +++ b/ohoe_headers/apply_ohoe_headers.sh @@ -28,8 +28,6 @@ HEADERS=( "memcheck.h" "hyperhold_inf.h" "lowmem_dbg.h" - "xpm.h" - "xpm_types.h" "zswapd.h" "mm_purgeable.h" "reclaim_acct.h" From 2e433f4cc088eca6c2750a0b5bcb752e97554e51 Mon Sep 17 00:00:00 2001 From: handyohos Date: Mon, 18 May 2026 21:25:40 +0800 Subject: [PATCH 3/4] xpm: Remove header symlink creation for linux-6.6 For linux-6.6, OpenHarmony headers are directly injected into the kernel source tree, so we no longer need to create symlinks from linux-5.10. This change: - Removes XPM_HEADER_SOURCE_ROOT variable pointing to linux-5.10 headers - Removes symlink creation for xpm.h and xpm_types.h Related: #150 Co-Authored-By: Claude Opus 4.7 (1M context) Signed-off-by: handyohos Change-Id: If4c6fac20fd7aaaed0052c91e69f24a21747e62c --- xpm/apply_xpm.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/xpm/apply_xpm.sh b/xpm/apply_xpm.sh index 6a4f3a2..6ee454e 100755 --- a/xpm/apply_xpm.sh +++ b/xpm/apply_xpm.sh @@ -10,7 +10,6 @@ KERNEL_BUILD_ROOT=$2 PRODUCT_NAME=$3 KERNEL_VERSION=$4 XPM_SOURCE_ROOT=$OHOS_SOURCE_ROOT/kernel/linux/common_modules/xpm -XPM_HEADER_SOURCE_ROOT=$OHOS_SOURCE_ROOT/kernel/linux/linux-5.10/include/linux function main() { @@ -20,10 +19,6 @@ function main() mkdir -p $KERNEL_BUILD_ROOT/security/xpm fi - cd $KERNEL_BUILD_ROOT/include/linux - ln -s -f $(realpath --relative-to=$KERNEL_BUILD_ROOT/include/linux $XPM_HEADER_SOURCE_ROOT)/xpm.h ./ - ln -s -f $(realpath --relative-to=$KERNEL_BUILD_ROOT/include/linux $XPM_HEADER_SOURCE_ROOT)/xpm_types.h ./ - cd $KERNEL_BUILD_ROOT/security/xpm ln -s -f $(realpath --relative-to=$KERNEL_BUILD_ROOT/security/xpm/ $XPM_SOURCE_ROOT)/* ./ From be5d41ea4aca22a599db1308e2bbe3827c4e7dcd Mon Sep 17 00:00:00 2001 From: handyohos Date: Mon, 18 May 2026 21:53:43 +0800 Subject: [PATCH 4/4] ohoe_headers: Remove apply_ohoe_headers.sh For linux-6.6, OpenHarmony headers are now directly injected into the kernel source tree (include/linux/), so the separate header injection script is no longer needed. Related: #150 Co-Authored-By: Claude Opus 4.7 (1M context) Signed-off-by: handyohos Change-Id: I5fab59cba72bc6b7a555df8accc910a88c4ef03c --- ohoe_headers/apply_ohoe_headers.sh | 77 ------------------------------ 1 file changed, 77 deletions(-) delete mode 100755 ohoe_headers/apply_ohoe_headers.sh diff --git a/ohoe_headers/apply_ohoe_headers.sh b/ohoe_headers/apply_ohoe_headers.sh deleted file mode 100755 index a16e922..0000000 --- a/ohoe_headers/apply_ohoe_headers.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash -# Copyright (c) 2025 Huawei Device Co., Ltd. -# OpenHarmony specific header files injection for Linux kernel -# -# This script injects OpenHarmony-specific header files that are not -# present in the upstream Linux kernel but are required by OpenHarmony -# kernel modifications. - -set -e - -OHOS_ROOT_PATH=$1 -KERNEL_SRC_TMP_PATH=$2 -DEVICE_NAME=$3 -KERNEL_VERSION=$4 - -if [ -z "${OHOS_ROOT_PATH}" ] || [ -z "${KERNEL_SRC_TMP_PATH}" ]; then - echo "Usage: $0 " - exit 1 -fi - -# Define header files to inject (from linux-5.10) -HEADER_BASE="${OHOS_ROOT_PATH}/kernel/linux/linux-5.10/include/linux" - -# Headers that are referenced by OpenHarmony kernel code -# but not present in upstream Linux-6.6 -HEADERS=( - "memcg_policy.h" - "memcheck.h" - "hyperhold_inf.h" - "lowmem_dbg.h" - "zswapd.h" - "mm_purgeable.h" - "reclaim_acct.h" -) - -# Target directory in the kernel source tree -TARGET_DIR="${KERNEL_SRC_TMP_PATH}/include/linux" - -echo "Applying OpenHarmony specific header files..." - -# Create target directory if it doesn't exist -mkdir -p "${TARGET_DIR}" - -# Copy each header file -for header in "${HEADERS[@]}"; do - if [ -f "${HEADER_BASE}/${header}" ]; then - cp "${HEADER_BASE}/${header}" "${TARGET_DIR}/${header}" - echo " Injected: ${header}" - else - echo " Warning: ${header} not found in source, skipping" - fi -done - -# memory_group_manager.h comes from rk3568_patch (ARM Mali GPU memory management) -# This is only needed if GPU support is enabled -MGM_HEADER="${OHOS_ROOT_PATH}/kernel/linux/patches/linux-6.6/rk3568_patch/kernel.patch" - -if [ -f "${MGM_HEADER}" ]; then - # Extract memory_group_manager.h from the patch - echo " Extracting memory_group_manager.h from rk3568_patch..." - awk ' - /\+\+\+ b\/include\/linux\/memory_group_manager.h/ { - p = 1 - next - } - p && /^\+/ { - print substr($0, 2) - if (/^+ \*\/$/) exit - } - p && /^@/ { exit } - ' "${MGM_HEADER}" > "${TARGET_DIR}/memory_group_manager.h" - echo " Injected: memory_group_manager.h (extracted from rk3568_patch)" -else - echo " Warning: memory_group_manager.h source not found, skipping" -fi - -echo "OpenHarmony header files injection complete."