action.yml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. name: 'Apply SUSFS Patches'
  2. description: 'Copy base SUSFS patches and apply version-specific fake patches'
  3. inputs:
  4. version:
  5. description: 'Kernel config version (e.g., android15-6.6)'
  6. required: true
  7. sublevel:
  8. description: 'Kernel sublevel'
  9. required: true
  10. os_patch_level:
  11. description: 'OS patch level (e.g., 2024-07)'
  12. required: true
  13. runs:
  14. using: "composite"
  15. steps:
  16. - name: Apply Kernel SUSFS Patches
  17. shell: bash
  18. working-directory: ${{ github.workspace }}/kernel/common
  19. run: |
  20. # Apply base SUSFS patches
  21. cp "${{ github.workspace }}/susfs4ksu/kernel_patches/fs/"* "${{ github.workspace }}/kernel/common/fs/"
  22. cp "${{ github.workspace }}/susfs4ksu/kernel_patches/include/linux/"* "${{ github.workspace }}/kernel/common/include/linux/"
  23. cp ${{ github.workspace }}/susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.version }}.patch ./
  24. - name: Apply Android 12 5.10 Fake Patches
  25. shell: bash
  26. if: inputs.version == 'android12-5.10'
  27. working-directory: ${{ github.workspace }}/kernel/common
  28. run: |
  29. if [ "${{ inputs.sublevel }}" -le "43" ]; then
  30. echo "Applying base.c Android 12 5.10 Fake Patch"
  31. perl -i -pe 's/(int|size_t)\s+this_len\s*=\s*min_t\s*\(\s*\1\s*,/size_t this_len = min_t(size_t,/;' fs/proc/base.c
  32. fi
  33. if [ "${{ inputs.sublevel }}" -le "117" ]; then
  34. echo "Applying fdinfo.c Android 12 5.10 Fake Patch"
  35. sed -i '/^[[:space:]]*\/\*$\|^[[:space:]]*u32 mask = mark->mask & IN_ALL_EVENTS;$/d' fs/notify/fdinfo.c
  36. perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c
  37. perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c
  38. fi
  39. - name: Apply Android 13 5.10 Fake Patches
  40. shell: bash
  41. if: inputs.version == 'android13-5.10'
  42. working-directory: ${{ github.workspace }}/kernel/common
  43. run: |
  44. echo "Applying Android 13 5.10 SUSFS fixes"
  45. if [ "${{ inputs.sublevel }}" -le "107" ]; then
  46. echo "Applying fdinfo.c Android 13 5.10 Fake Patch"
  47. sed -i '/^[[:space:]]*\/\*$\|^[[:space:]]*u32 mask = mark->mask & IN_ALL_EVENTS;$/d' fs/notify/fdinfo.c
  48. perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c
  49. perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c
  50. fi
  51. - name: Apply Android 13 5.15 Fake Patches
  52. shell: bash
  53. if: inputs.version == 'android13-5.15'
  54. working-directory: ${{ github.workspace }}/kernel/common
  55. run: |
  56. echo "Applying Android 13 5.15 SUSFS fixes"
  57. if [ "${{ inputs.sublevel }}" -le "41" ]; then
  58. echo "Applying namespace.c Android 13 5.15 SUSFS fixes"
  59. sed -i '/^#include <linux\/shmem_fs.h>$/a #include <linux/mnt_idmapping.h>' fs/namespace.c
  60. echo "Applying open.c Android 13 5.15 Fake Patch"
  61. sed -i '/^#include <linux\/compat.h>$/a #include <linux/mnt_idmapping.h>' fs/open.c
  62. echo "Applying fdinfo.c Android 13 5.15 Fake Patch"
  63. sed -i '/^[[:space:]]*\/\*$\|^[[:space:]]*u32 mask = mark->mask & IN_ALL_EVENTS;$/d' fs/notify/fdinfo.c
  64. perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c
  65. perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c
  66. fi
  67. if [ "${{ inputs.sublevel }}" -ge "197" ]; then
  68. echo "Applying namespace.c Android 13 5.15 Fake Patch"
  69. sed -i '/^#include <trace\/hooks\/blk.h>$/d' fs/namespace.c
  70. fi
  71. if [ "${{ inputs.sublevel }}" -ge "197" ]; then
  72. echo "Applying task_mmu.c Android 13 5.15 Fake Patch"
  73. sed -i '/^#include <trace\/hooks\/mm.h>$/d' fs/proc/task_mmu.c
  74. fi
  75. - name: Apply Android 14 6.1 Fake Patches
  76. shell: bash
  77. if: inputs.version == 'android14-6.1'
  78. working-directory: ${{ github.workspace }}/kernel/common
  79. run: |
  80. if [ "${{ inputs.sublevel }}" -le "25" ]; then
  81. echo "Applying base.c Android 14 6.1 Fake Patch"
  82. sed -i '/^#include <trace\/events\/oom.h>$/a #include <trace/hooks/sched.h>' fs/proc/base.c
  83. fi
  84. if [ "${{ inputs.sublevel }}" -le "141" ]; then
  85. echo "Applying base.c Android 14 6.1 Fake Patch"
  86. sed -i '/^#include <linux\/cpufreq_times.h>$/a #include <linux/dma-buf.h>' fs/proc/base.c
  87. fi
  88. if [ "${{ inputs.sublevel }}" -ge "157" ]; then
  89. echo "Applying namespace.c Android 14 6.1 Fake Patch"
  90. sed -i '/^#include <trace\/hooks\/blk.h>$/d' fs/namespace.c
  91. fi
  92. - name: Apply Android 15 6.6 Fake Patches
  93. shell: bash
  94. if: inputs.version == 'android15-6.6'
  95. working-directory: ${{ github.workspace }}/kernel/common
  96. run: |
  97. echo "Applying 6.6 SUSFS fixes"
  98. if [ "${{ inputs.sublevel }}" -le "30" ]; then
  99. echo "Applying taskmmu.c Android 15 6.6 Fake Patch"
  100. python3 -c 'import re;c=open("fs/proc/task_mmu.c").read();c=re.sub(r"(\t+\t\tif\s*\(\s*vma->vm_end\s*>\s*last_vma_end\s*\))\n(\t+\t\t\tsmap_gather_stats\(vma,\s*&mss,\s*last_vma_end\);)\n(\t+)\}",lambda m:m.group(1)+" {\n"+m.group(2)+"\n"+m.group(3)+"\t\tlast_vma_end = vma->vm_end;\n"+m.group(3)+"\t}\n"+m.group(3)+"}",c,count=1);open("fs/proc/task_mmu.c","w").write(c)'
  101. fi
  102. if [ "${{ inputs.sublevel }}" -le "30" ] && [ "${{ inputs.os_patch_level }}" = "2024-07" ]; then
  103. echo "Adding __fold_filemap_fixup_entry stub for 2024-07 kernels"
  104. sed -i '/^#include <asm\/elf.h>$/i #ifndef __fold_filemap_fixup_entry\nstatic inline void __fold_filemap_fixup_entry(struct vma_iterator *iter, unsigned long *end) { }\n#endif /* __fold_filemap_fixup_entry */\n' fs/proc/task_mmu.c
  105. fi
  106. if [ "${{ inputs.sublevel }}" -le "92" ]; then
  107. echo "Applying base.c Android 15 6.6 Fake Patch"
  108. sed -i '/^#include <linux\/cpufreq_times.h>$/a #include <linux/dma-buf.h>' fs/proc/base.c
  109. fi
  110. if [ "${{ inputs.sublevel }}" -le "57" ]; then
  111. echo "Applying base.c Android 15 6.6 Fake Patch"
  112. sed -i '/^#include <linux\/sched\/sysctl.h>$/a #include <linux/zswap.h>' mm/memory.c
  113. fi
  114. - name: Apply Android 16 6.12 Fake Patches
  115. shell: bash
  116. if: inputs.version == 'android16-6.12'
  117. working-directory: ${{ github.workspace }}/kernel/common
  118. run: |
  119. echo "Applying 6.12 SUSFS fixes"
  120. if [ "${{ inputs.sublevel }}" -ge "58" ]; then
  121. echo "Applying exec.c Android 16 6.12 Fake Patch"
  122. sed -i '/^#include <linux\/dma-buf.h>$/d' fs/exec.c
  123. fi
  124. if [ "${{ inputs.sublevel }}" -ge "69" ]; then
  125. echo "Applying task_mmu.c Android 16 6.12 Fake Patch"
  126. sed -i 's/vma_data_pages/vma_pages/g' fs/proc/task_mmu.c
  127. fi
  128. - name: Apply Kernel SUSFS Patches
  129. shell: bash
  130. working-directory: ${{ github.workspace }}/kernel/common
  131. run: |
  132. patch -p1 < 50_add_susfs_in_gki-${{ inputs.version }}.patch
  133. # SUSFS's OPEN_REDIRECT code unconditionally calls VMA_PAD_START(), which
  134. # only exists on GKI branches that carry Google's page-size-migration
  135. # feature (added to each android version's kernel/common branch at a
  136. # different, sometime later, os_patch_level). Older os_patch_levels in
  137. # our build matrix predate it, so fall back to a no-padding definition
  138. # when the real header/macro isn't present. This is version-agnostic and
  139. # a no-op wherever the real header already provides it.
  140. if grep -q 'VMA_PAD_START(' fs/proc/task_mmu.c && ! grep -qE '#include <linux/pgsize_migration(_inline)?\.h>|define VMA_PAD_START' fs/proc/task_mmu.c; then
  141. sed -i '1a #ifndef VMA_PAD_START\n#define VMA_PAD_START(vma) ((vma)->vm_end)\n#endif' fs/proc/task_mmu.c
  142. echo "Added VMA_PAD_START fallback definition to fs/proc/task_mmu.c"
  143. fi
  144. # Same story for __fold_filemap_fixup_entry(), declared in page_size_compat.h.
  145. if grep -q '__fold_filemap_fixup_entry' fs/proc/task_mmu.c && ! grep -q '#include <linux/page_size_compat.h>' fs/proc/task_mmu.c; then
  146. sed -i '/#include <linux\/pkeys.h>/a #include <linux/page_size_compat.h>' fs/proc/task_mmu.c
  147. echo "Added page_size_compat.h include to fs/proc/task_mmu.c"
  148. fi