action.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. perl -0777 -i -pe 's{(if \(inode\) \{\n)\t\t/\*\n(\t\t \*[^\n]*\n)+\t\t \*/\n}{$1}g; s{^[[:space:]]*u32 mask = mark->mask & IN_ALL_EVENTS;\n}{}m' 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. echo "Adding inotify_mark_user_mask function definition"
  39. python3 -c 'import re;c=open("fs/notify/fdinfo.c").read();c=re.sub(r"^static void inotify_fdinfo\(struct seq_file \*m, struct fsnotify_mark \*mark\)$",lambda m:"static inline u32 inotify_mark_user_mask(struct fsnotify_mark *mark)\n{\n\treturn mark->mask & IN_ALL_EVENTS;\n}\n\n"+m.group(0),c,count=1,flags=re.MULTILINE);open("fs/notify/fdinfo.c","w").write(c)'
  40. fi
  41. - name: Apply Android 13 5.10 Fake Patches
  42. shell: bash
  43. if: inputs.version == 'android13-5.10'
  44. working-directory: ${{ github.workspace }}/kernel/common
  45. run: |
  46. echo "Applying Android 13 5.10 SUSFS fixes"
  47. if [ "${{ inputs.sublevel }}" -le "107" ]; then
  48. echo "Applying fdinfo.c Android 13 5.10 Fake Patch"
  49. perl -0777 -i -pe 's{(if \(inode\) \{\n)\t\t/\*\n(\t\t \*[^\n]*\n)+\t\t \*/\n}{$1}g; s{^[[:space:]]*u32 mask = mark->mask & IN_ALL_EVENTS;\n}{}m' fs/notify/fdinfo.c
  50. perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c
  51. perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c
  52. echo "Adding inotify_mark_user_mask function definition"
  53. python3 -c 'import re;c=open("fs/notify/fdinfo.c").read();c=re.sub(r"^static void inotify_fdinfo\(struct seq_file \*m, struct fsnotify_mark \*mark\)$",lambda m:"static inline u32 inotify_mark_user_mask(struct fsnotify_mark *mark)\n{\n\treturn mark->mask & IN_ALL_EVENTS;\n}\n\n"+m.group(0),c,count=1,flags=re.MULTILINE);open("fs/notify/fdinfo.c","w").write(c)'
  54. fi
  55. - name: Apply Android 13 5.15 Fake Patches
  56. shell: bash
  57. if: inputs.version == 'android13-5.15'
  58. working-directory: ${{ github.workspace }}/kernel/common
  59. run: |
  60. echo "Applying Android 13 5.15 SUSFS fixes"
  61. if [ "${{ inputs.sublevel }}" -le "41" ]; then
  62. echo "Applying namespace.c Android 13 5.15 SUSFS fixes"
  63. sed -i '/^#include <linux\/shmem_fs.h>$/a #include <linux/mnt_idmapping.h>' fs/namespace.c
  64. echo "Applying open.c Android 13 5.15 Fake Patch"
  65. sed -i '/^#include <linux\/compat.h>$/a #include <linux/mnt_idmapping.h>' fs/open.c
  66. echo "Applying fdinfo.c Android 13 5.15 Fake Patch"
  67. perl -0777 -i -pe 's{(if \(inode\) \{\n)\t\t/\*\n(\t\t \*[^\n]*\n)+\t\t \*/\n}{$1}g; s{^[[:space:]]*u32 mask = mark->mask & IN_ALL_EVENTS;\n}{}m' fs/notify/fdinfo.c
  68. perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c
  69. perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c
  70. echo "Adding inotify_mark_user_mask function definition"
  71. python3 -c 'import re;c=open("fs/notify/fdinfo.c").read();c=re.sub(r"^static void inotify_fdinfo\(struct seq_file \*m, struct fsnotify_mark \*mark\)$",lambda m:"static inline u32 inotify_mark_user_mask(struct fsnotify_mark *mark)\n{\n\treturn mark->mask & IN_ALL_EVENTS;\n}\n\n"+m.group(0),c,count=1,flags=re.MULTILINE);open("fs/notify/fdinfo.c","w").write(c)'
  72. fi
  73. if [ "${{ inputs.sublevel }}" -ge "197" ]; then
  74. echo "Applying namespace.c Android 13 5.15 Fake Patch"
  75. sed -i '/^#include <trace\/hooks\/blk.h>$/d' fs/namespace.c
  76. fi
  77. if [ "${{ inputs.sublevel }}" -ge "197" ]; then
  78. echo "Applying task_mmu.c Android 13 5.15 Fake Patch"
  79. sed -i '/^#include <trace\/hooks\/mm.h>$/d' fs/proc/task_mmu.c
  80. fi
  81. - name: Apply Android 14 6.1 Fake Patches
  82. shell: bash
  83. if: inputs.version == 'android14-6.1'
  84. working-directory: ${{ github.workspace }}/kernel/common
  85. run: |
  86. if [ "${{ inputs.sublevel }}" -le "25" ]; then
  87. echo "Applying base.c Android 14 6.1 Fake Patch"
  88. sed -i '/^#include <trace\/events\/oom.h>$/a #include <trace/hooks/sched.h>' fs/proc/base.c
  89. fi
  90. if [ "${{ inputs.sublevel }}" -le "141" ]; then
  91. echo "Applying base.c Android 14 6.1 Fake Patch"
  92. sed -i '/^#include <linux\/cpufreq_times.h>$/a #include <linux/dma-buf.h>' fs/proc/base.c
  93. fi
  94. if [ "${{ inputs.sublevel }}" -ge "157" ]; then
  95. echo "Applying namespace.c Android 14 6.1 Fake Patch"
  96. sed -i '/^#include <trace\/hooks\/blk.h>$/d' fs/namespace.c
  97. fi
  98. - name: Apply Android 15 6.6 Fake Patches
  99. shell: bash
  100. if: inputs.version == 'android15-6.6'
  101. working-directory: ${{ github.workspace }}/kernel/common
  102. run: |
  103. echo "Applying 6.6 SUSFS fixes"
  104. if [ "${{ inputs.sublevel }}" -le "30" ]; then
  105. echo "Applying taskmmu.c Android 15 6.6 Fake Patch"
  106. 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)'
  107. fi
  108. if [ "${{ inputs.sublevel }}" -le "30" ] && [ "${{ inputs.os_patch_level }}" = "2024-07" ]; then
  109. echo "Adding __fold_filemap_fixup_entry stub for 2024-07 kernels"
  110. 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
  111. fi
  112. if [ "${{ inputs.sublevel }}" -le "92" ]; then
  113. echo "Applying base.c Android 15 6.6 Fake Patch"
  114. sed -i '/^#include <linux\/cpufreq_times.h>$/a #include <linux/dma-buf.h>' fs/proc/base.c
  115. fi
  116. if [ "${{ inputs.sublevel }}" -le "57" ]; then
  117. echo "Applying base.c Android 15 6.6 Fake Patch"
  118. sed -i '/^#include <linux\/sched\/sysctl.h>$/a #include <linux/zswap.h>' mm/memory.c
  119. fi
  120. - name: Apply Android 16 6.12 Fake Patches
  121. shell: bash
  122. if: inputs.version == 'android16-6.12'
  123. working-directory: ${{ github.workspace }}/kernel/common
  124. run: |
  125. echo "Applying 6.12 SUSFS fixes"
  126. if [ "${{ inputs.sublevel }}" -ge "58" ]; then
  127. echo "Applying exec.c Android 16 6.12 Fake Patch"
  128. sed -i '/^#include <linux\/dma-buf.h>$/d' fs/exec.c
  129. fi
  130. if [ "${{ inputs.sublevel }}" -ge "69" ]; then
  131. echo "Applying task_mmu.c Android 16 6.12 Fake Patch"
  132. sed -i 's/vma_data_pages/vma_pages/g' fs/proc/task_mmu.c
  133. fi
  134. - name: Apply Kernel SUSFS Patches
  135. shell: bash
  136. working-directory: ${{ github.workspace }}/kernel/common
  137. run: |
  138. patch -p1 < 50_add_susfs_in_gki-${{ inputs.version }}.patch
  139. # SUSFS's OPEN_REDIRECT code unconditionally calls VMA_PAD_START(), which
  140. # only exists on GKI branches that carry Google's page-size-migration
  141. # feature (added to each android version's kernel/common branch at a
  142. # different, sometime later, os_patch_level). Older os_patch_levels in
  143. # our build matrix predate it, so fall back to a no-padding definition
  144. # when the real header/macro isn't present. This is version-agnostic and
  145. # a no-op wherever the real header already provides it.
  146. 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
  147. sed -i '1a #ifndef VMA_PAD_START\n#define VMA_PAD_START(vma) ((vma)->vm_end)\n#endif' fs/proc/task_mmu.c
  148. echo "Added VMA_PAD_START fallback definition to fs/proc/task_mmu.c"
  149. fi
  150. # Same story for __fold_filemap_fixup_entry(), declared in page_size_compat.h.
  151. 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
  152. sed -i '/#include <linux\/pkeys.h>/a #include <linux/page_size_compat.h>' fs/proc/task_mmu.c
  153. echo "Added page_size_compat.h include to fs/proc/task_mmu.c"
  154. fi
  155. # Fix set_nameidata() calls for 5.10 kernels.
  156. # The SUSFS patch adds set_nameidata(nd, old_dfd, fake_filename, NULL) with 4 args,
  157. # but 5.10 kernels only have 3-param set_nameidata(p, dfd, name) — no root param.
  158. if [[ "${{ inputs.version }}" == "android12-5.10" || "${{ inputs.version }}" == "android13-5.10" ]]; then
  159. if grep -q 'set_nameidata(nd, old_dfd, fake_filename, NULL)' fs/namei.c; then
  160. echo "Fixing set_nameidata calls for 5.10 (4-arg -> 3-arg)"
  161. sed -i 's/set_nameidata(nd, old_dfd, fake_filename, NULL)/set_nameidata(nd, old_dfd, fake_filename)/g' fs/namei.c
  162. fi
  163. fi