From 3041dfa8d20d783da9ac3a1623629e376735a1c3 Mon Sep 17 00:00:00 2001 From: handyohos Date: Fri, 15 May 2026 10:22:25 +0800 Subject: [PATCH] #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)/* ./