action.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. name: 'Kernel Fixes'
  2. description: 'Applies compatibility fixes based on android/kernel/sublevel'
  3. inputs:
  4. version:
  5. required: true
  6. type: string
  7. android_version:
  8. required: true
  9. type: string
  10. kernel_version:
  11. required: true
  12. type: string
  13. sublevel:
  14. required: true
  15. type: string
  16. os_patch_level:
  17. required: true
  18. type: string
  19. runs:
  20. using: composite
  21. steps:
  22. - name: 'Apply Makefile and parse-options.c fixes for GLIBC >= 2.38'
  23. working-directory: ${{ github.workspace }}/kernel/common
  24. shell: bash
  25. run: |
  26. set -euo pipefail
  27. GLIBC_VERSION="$(ldd --version 2>/dev/null | head -n 1 | awk '{print $NF}')"
  28. echo "[*] Detected GLIBC version: $GLIBC_VERSION"
  29. if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n 1)" = "2.38" ]; then
  30. echo "[*] GLIBC >= 2.38, attempting Makefile fix."
  31. # Check if the pattern that needs fixing actually exists
  32. if grep -q '\$(Q)\$(MAKE) -C \$(SUBCMD_SRC) OUTPUT=\$(abspath \$(dir \$@))\/ \$(abspath \$@)' tools/bpf/resolve_btfids/Makefile; then
  33. echo "[*] Found pattern to fix, applying sed."
  34. sed -i '/\$(Q)\$(MAKE) -C \$(SUBCMD_SRC) OUTPUT=\$(abspath \$(dir \$@))\/ \$(abspath \$@)/s//$(Q)$(MAKE) -C $(SUBCMD_SRC) EXTRA_CFLAGS="$(CFLAGS)" OUTPUT=$(abspath $(dir $@))\/ $(abspath $@)/' tools/bpf/resolve_btfids/Makefile
  35. MAKEFILE_FIXED="true"
  36. elif grep -q 'EXTRA_CFLAGS' tools/bpf/resolve_btfids/Makefile; then
  37. echo "[*] EXTRA_CFLAGS already present, no fix needed."
  38. MAKEFILE_FIXED="already_fixed"
  39. else
  40. echo "[!] Neither pattern found in Makefile."
  41. MAKEFILE_FIXED="false"
  42. fi
  43. echo "MAKEFILE_FIXED=$MAKEFILE_FIXED" >> $GITHUB_ENV
  44. if [[ "${{ inputs.version }}" == "android13-5.10" && "${{ inputs.sublevel }}" -le 186 ]] || \
  45. [[ "${{ inputs.version }}" == "android13-5.15" && "${{ inputs.sublevel }}" -le 119 ]] || \
  46. [[ "${{ inputs.version }}" == "android14-5.15" && "${{ inputs.sublevel }}" -le 110 ]]; then
  47. echo "[*] Applying parse-options.c fixes."
  48. sed -i '/char \*buf = NULL;/a int i;' tools/lib/subcmd/parse-options.c 2>/dev/null || true
  49. sed -i 's/for (int i = 0; subcommands\[i\]; i++) {/for (i = 0; subcommands[i]; i++) {/' tools/lib/subcmd/parse-options.c 2>/dev/null || true
  50. sed -i '/if (subcommands) {/a int i;' tools/lib/subcmd/parse-options.c 2>/dev/null || true
  51. sed -i 's/for (int i = 0; subcommands\[i\]; i++)/for (i = 0; subcommands[i]; i++)/' tools/lib/subcmd/parse-options.c 2>/dev/null || true
  52. echo "PARSE_OPTIONS_FIXED=true" >> $GITHUB_ENV
  53. else
  54. echo "PARSE_OPTIONS_FIXED=false" >> $GITHUB_ENV
  55. fi
  56. else
  57. echo "[-] GLIBC version < 2.38, skipping Makefile fix."
  58. fi
  59. - name: 'Apply mmap.c fix for specific versions'
  60. shell: bash
  61. if: inputs.version == 'android15-6.6' && inputs.sublevel <= '58'
  62. working-directory: ${{ github.workspace }}/kernel/common
  63. run: |
  64. echo "[*] Checking for android15 + kernel 6.6 include fix..."
  65. if [[ "${{ inputs.android_version }}" == "android15" && "${{ inputs.kernel_version }}" == "6.6" ]]; then
  66. echo "[+] android15 + 6.6, checking for fs.h include."
  67. cd "${{ github.workspace }}/kernel/common"
  68. if ! grep -qxF '#include <trace/hooks/fs.h>' ./fs/namespace.c; then
  69. echo "[*] Adding missing #include <trace/hooks/fs.h> to fs/namespace.c."
  70. sed -i '/#include <trace\/hooks\/blk.h>/a #include <trace\/hooks\/fs.h>' ./fs/namespace.c
  71. echo "MMAP_NAMESPACE_FIX=true" >> "$GITHUB_ENV"
  72. else
  73. echo "[*] #include <trace/hooks/fs.h> already present."
  74. echo "MMAP_NAMESPACE_FIX=already_present" >> "$GITHUB_ENV"
  75. fi
  76. fi
  77. - name: 'Apply mmap.c fix for specific versions'
  78. shell: bash
  79. if: (inputs.version == 'android12-5.10' && inputs.sublevel == 226) || (inputs.version == 'android13-5.10' && inputs.sublevel == 223) || (inputs.version == 'android13-5.15' && inputs.sublevel == 167) || (inputs.version == 'android14-5.15' && inputs.sublevel == 167)
  80. working-directory: ${{ github.workspace }}/kernel/common
  81. run: |
  82. echo "[*] Applying mmap.c fix for specific version combo."
  83. sed -i 's/\s*vm_flags_clear(new_vma, VM_PAD_MASK);/ new_vma->vm_flags \&= ~VM_PAD_MASK;/' mm/mmap.c
  84. echo "MMAP_VM_FLAGS_FIX=true" >> "$GITHUB_ENV"
  85. - name: 'Final Kernel Fixes Summary'
  86. shell: bash
  87. run: |
  88. SUMMARY_FILE="/tmp/kernel-fixes-summary.md"
  89. echo "## Final Kernel Fixes Summary" >> "$SUMMARY_FILE"
  90. echo "" >> "$SUMMARY_FILE"
  91. echo "**Kernel Version:** ${{ inputs.android_version }} + ${{ inputs.kernel_version }} (sublevel ${{ inputs.sublevel }})" >> "$SUMMARY_FILE"
  92. echo "" >> "$SUMMARY_FILE"
  93. echo "### Fix Status" >> "$SUMMARY_FILE"
  94. GLIBC_VERSION="$(ldd --version 2>/dev/null | head -n 1 | awk '{print $NF}')"
  95. if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n 1)" = "2.38" ]; then
  96. if [ "${MAKEFILE_FIXED:-false}" = "true" ]; then
  97. echo "- Makefile EXTRA_CFLAGS fix: applied" >> "$SUMMARY_FILE"
  98. elif [ "${MAKEFILE_FIXED:-false}" = "already_fixed" ]; then
  99. echo "- Makefile EXTRA_CFLAGS fix: already present" >> "$SUMMARY_FILE"
  100. else
  101. echo "- Makefile EXTRA_CFLAGS fix: pattern not found" >> "$SUMMARY_FILE"
  102. fi
  103. if [ "${PARSE_OPTIONS_FIXED:-false}" = "true" ]; then
  104. echo "- parse-options.c fix: applied" >> "$SUMMARY_FILE"
  105. else
  106. echo "- parse-options.c fix: not applicable" >> "$SUMMARY_FILE"
  107. fi
  108. else
  109. echo "- Makefile EXTRA_CFLAGS fix: skipped because GLIBC < 2.38" >> "$SUMMARY_FILE"
  110. echo "- parse-options.c fix: skipped because GLIBC < 2.38" >> "$SUMMARY_FILE"
  111. fi
  112. if [ "${MMAP_NAMESPACE_FIX:-not_applicable}" = "true" ]; then
  113. echo "- fs/namespace.c include fix: applied" >> "$SUMMARY_FILE"
  114. elif [ "${MMAP_NAMESPACE_FIX:-not_applicable}" = "already_present" ]; then
  115. echo "- fs/namespace.c include fix: already present" >> "$SUMMARY_FILE"
  116. else
  117. echo "- fs/namespace.c include fix: not applicable" >> "$SUMMARY_FILE"
  118. fi
  119. if [ "${MMAP_VM_FLAGS_FIX:-not_applicable}" = "true" ]; then
  120. echo "- mm/mmap.c VM_PAD_MASK fix: applied" >> "$SUMMARY_FILE"
  121. else
  122. echo "- mm/mmap.c VM_PAD_MASK fix: not applicable" >> "$SUMMARY_FILE"
  123. fi
  124. if [[ "${SELINUX_HIDE_FIX:-not_applicable}" == patched:* ]]; then
  125. echo "- selinux_hide.c 6.6+ pointer-bool fix: ${SELINUX_HIDE_FIX#patched:}" >> "$SUMMARY_FILE"
  126. elif [ "${SELINUX_HIDE_FIX:-not_applicable}" = "not_needed" ]; then
  127. echo "- selinux_hide.c 6.6+ pointer-bool fix: already patched / not needed" >> "$SUMMARY_FILE"
  128. elif [ "${SELINUX_HIDE_FIX:-not_applicable}" = "skipped" ]; then
  129. echo "- selinux_hide.c 6.6+ pointer-bool fix: skipped (<6.6)" >> "$SUMMARY_FILE"
  130. else
  131. echo "- selinux_hide.c 6.6+ pointer-bool fix: not applicable" >> "$SUMMARY_FILE"
  132. fi