action.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 "[INFO] Detected GLIBC version: $GLIBC_VERSION"
  29. if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n 1)" = "2.38" ]; then
  30. echo "[INFO] 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 "[INFO] 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 "[INFO] EXTRA_CFLAGS already present, no fix needed."
  38. MAKEFILE_FIXED="already_fixed"
  39. else
  40. echo "[WARN] 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 "[INFO] 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 "[SKIP] 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 "[INFO] Checking for android15 + kernel 6.6 include fix..."
  65. if [[ "${{ inputs.android_version }}" == "android15" && "${{ inputs.kernel_version }}" == "6.6" ]]; then
  66. echo "[MATCH] 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 "[INFO] 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 "[INFO] #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 "[INFO] 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: 'Fix selinux_hide pointer-bool-conversion on 6.6+'
  86. shell: bash
  87. run: |
  88. set -euo pipefail
  89. KVER="${{ inputs.kernel_version }}"
  90. # version >= 6.6 ? apply to ALL flavors/branches (kernelsu/next/resukisu, any GKI)
  91. if [ "$(printf '%s\n' "6.6" "$KVER" | sort -V | head -n1)" = "6.6" ]; then
  92. echo "[INFO] KVER $KVER >= 6.6, checking selinux_hide.c (all branches)"
  93. # Search workspace-wide so we catch kernel/common/drivers/kernelsu, common/drivers/kernelsu, kernel/KernelSU, etc.
  94. for f in $(find "${{ github.workspace }}" -name selinux_hide.c 2>/dev/null); do
  95. if grep -q "security_dump_masked_av_fn" "$f" && grep -q "if (security_dump_masked_av_fn)" "$f"; then
  96. echo "[INFO] Patching $f (security_dump_masked_av_fn)"
  97. sed -i 's/if (security_dump_masked_av_fn)/if (security_dump_masked_av_fn != NULL)/g' "$f"
  98. sed -i 's/if (context_struct_compute_av_fn)/if (context_struct_compute_av_fn != NULL)/g' "$f"
  99. echo "SELINUX_HIDE_FIX=patched:$f" >> "$GITHUB_ENV"
  100. else
  101. echo "[INFO] $f already patched or no pattern"
  102. fi
  103. done
  104. if [ -z "${SELINUX_HIDE_FIX:-}" ]; then
  105. echo "[INFO] No selinux_hide.c needing patch found"
  106. echo "SELINUX_HIDE_FIX=not_needed" >> "$GITHUB_ENV"
  107. fi
  108. else
  109. echo "[SKIP] KVER $KVER < 6.6, no selinux_hide fix (covers all branches)"
  110. echo "SELINUX_HIDE_FIX=skipped" >> "$GITHUB_ENV"
  111. fi
  112. - name: 'Final Kernel Fixes Summary'
  113. shell: bash
  114. run: |
  115. SUMMARY_FILE="/tmp/kernel-fixes-summary.md"
  116. echo "## Final Kernel Fixes Summary" >> "$SUMMARY_FILE"
  117. echo "" >> "$SUMMARY_FILE"
  118. echo "**Kernel Version:** ${{ inputs.android_version }} + ${{ inputs.kernel_version }} (sublevel ${{ inputs.sublevel }})" >> "$SUMMARY_FILE"
  119. echo "" >> "$SUMMARY_FILE"
  120. echo "### Fix Status" >> "$SUMMARY_FILE"
  121. GLIBC_VERSION="$(ldd --version 2>/dev/null | head -n 1 | awk '{print $NF}')"
  122. if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n 1)" = "2.38" ]; then
  123. if [ "${MAKEFILE_FIXED:-false}" = "true" ]; then
  124. echo "- Makefile EXTRA_CFLAGS fix: applied" >> "$SUMMARY_FILE"
  125. elif [ "${MAKEFILE_FIXED:-false}" = "already_fixed" ]; then
  126. echo "- Makefile EXTRA_CFLAGS fix: already present" >> "$SUMMARY_FILE"
  127. else
  128. echo "- Makefile EXTRA_CFLAGS fix: pattern not found" >> "$SUMMARY_FILE"
  129. fi
  130. if [ "${PARSE_OPTIONS_FIXED:-false}" = "true" ]; then
  131. echo "- parse-options.c fix: applied" >> "$SUMMARY_FILE"
  132. else
  133. echo "- parse-options.c fix: not applicable" >> "$SUMMARY_FILE"
  134. fi
  135. else
  136. echo "- Makefile EXTRA_CFLAGS fix: skipped because GLIBC < 2.38" >> "$SUMMARY_FILE"
  137. echo "- parse-options.c fix: skipped because GLIBC < 2.38" >> "$SUMMARY_FILE"
  138. fi
  139. if [ "${MMAP_NAMESPACE_FIX:-not_applicable}" = "true" ]; then
  140. echo "- fs/namespace.c include fix: applied" >> "$SUMMARY_FILE"
  141. elif [ "${MMAP_NAMESPACE_FIX:-not_applicable}" = "already_present" ]; then
  142. echo "- fs/namespace.c include fix: already present" >> "$SUMMARY_FILE"
  143. else
  144. echo "- fs/namespace.c include fix: not applicable" >> "$SUMMARY_FILE"
  145. fi
  146. if [ "${MMAP_VM_FLAGS_FIX:-not_applicable}" = "true" ]; then
  147. echo "- mm/mmap.c VM_PAD_MASK fix: applied" >> "$SUMMARY_FILE"
  148. else
  149. echo "- mm/mmap.c VM_PAD_MASK fix: not applicable" >> "$SUMMARY_FILE"
  150. fi
  151. if [[ "${SELINUX_HIDE_FIX:-not_applicable}" == patched:* ]]; then
  152. echo "- selinux_hide.c 6.6+ pointer-bool fix: ${SELINUX_HIDE_FIX#patched:}" >> "$SUMMARY_FILE"
  153. elif [ "${SELINUX_HIDE_FIX:-not_applicable}" = "not_needed" ]; then
  154. echo "- selinux_hide.c 6.6+ pointer-bool fix: already patched / not needed" >> "$SUMMARY_FILE"
  155. elif [ "${SELINUX_HIDE_FIX:-not_applicable}" = "skipped" ]; then
  156. echo "- selinux_hide.c 6.6+ pointer-bool fix: skipped (<6.6)" >> "$SUMMARY_FILE"
  157. else
  158. echo "- selinux_hide.c 6.6+ pointer-bool fix: not applicable" >> "$SUMMARY_FILE"
  159. fi