action.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. name: Setup SUSFS
  2. description: Clone and apply SUSFS patches with version-specific fixes
  3. inputs:
  4. use_latest_commits:
  5. description: 'Use the latest commit on the branch instead of the pinned commit'
  6. required: false
  7. default: true
  8. version:
  9. description: 'Kernel config version (e.g., android15-6.6)'
  10. required: true
  11. android_version:
  12. description: 'Android version (e.g., android15)'
  13. required: true
  14. kernel_version:
  15. description: 'Kernel version (e.g., 6.6)'
  16. required: true
  17. os_patch_level:
  18. description: 'OS patch level (e.g., 2024-07)'
  19. required: true
  20. sublevel:
  21. description: 'Kernel sublevel'
  22. required: true
  23. runs:
  24. using: composite
  25. steps:
  26. - name: Setup SUSFS Branch
  27. shell: bash
  28. run: |
  29. set -euo pipefail
  30. SUSFS_BRANCH="gki-${{ inputs.version }}"
  31. SUSFS_REPO="https://gitlab.com/simonpunk/susfs4ksu.git"
  32. echo "Preparing SUSFS for branch: $SUSFS_BRANCH"
  33. echo "Cloning latest from $SUSFS_BRANCH..."
  34. git clone "$SUSFS_REPO" -b "$SUSFS_BRANCH" susfs4ksu
  35. if [ "${{ inputs.use_latest_commits }}" != "true" ]; then
  36. COMMITS_JSON="${{ github.workspace }}/.github/config/commits.json"
  37. SUSFS_COMMIT=$(jq -er --arg key "$SUSFS_BRANCH" '.susfs[$key]' "$COMMITS_JSON")
  38. cd ${{ github.workspace }}/susfs4ksu
  39. git checkout "$SUSFS_COMMIT"
  40. fi
  41. - name: Enable KernelSU SUSFS Config
  42. uses: ./.github/actions/set-kernel-config
  43. with:
  44. defconfig: ${{ github.workspace }}/kernel/common/arch/arm64/configs/gki_defconfig
  45. fragment: ${{ github.workspace }}/wild_gki.fragment
  46. configs: |
  47. CONFIG_KSU_SUSFS
  48. CONFIG_KSU_SUSFS_SUS_PATH
  49. CONFIG_KSU_SUSFS_SUS_MOUNT
  50. CONFIG_KSU_SUSFS_SUS_KSTAT
  51. CONFIG_KSU_SUSFS_SPOOF_UNAME
  52. CONFIG_KSU_SUSFS_ENABLE_LOG
  53. CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS
  54. CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG
  55. CONFIG_KSU_SUSFS_OPEN_REDIRECT
  56. CONFIG_KSU_SUSFS_SUS_MAP
  57. - name: Apply KSU SUSFS Patches
  58. if: false
  59. shell: bash
  60. working-directory: ${{ github.workspace }}/kernel/KernelSU-Next
  61. run: |
  62. cp ${{ github.workspace }}/kernel_patches/wild/ksun-5a4a718-susfs-f7ae19ef-gki-android14-6.1.patch ./
  63. patch -p1 < ksun-5a4a718-susfs-f7ae19ef-gki-android14-6.1.patch
  64. - name: Apply Kernel SUSFS Patches
  65. shell: bash
  66. working-directory: ${{ github.workspace }}/kernel/common
  67. run: |
  68. # Apply base SUSFS patches
  69. cp "${{ github.workspace }}/susfs4ksu/kernel_patches/fs/"* "${{ github.workspace }}/kernel/common/fs/"
  70. cp "${{ github.workspace }}/susfs4ksu/kernel_patches/include/linux/"* "${{ github.workspace }}/kernel/common/include/linux/"
  71. cp ${{ github.workspace }}/susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.version }}.patch ./
  72. - name: Apply Android 12 5.10 Fake Patches
  73. shell: bash
  74. if: inputs.version == 'android12-5.10'
  75. working-directory: ${{ github.workspace }}/kernel/common
  76. run: |
  77. if [ "${{ inputs.sublevel }}" -le "43" ]; then
  78. echo "Applying base.c Android 12 5.10 Fake Patch"
  79. 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
  80. fi
  81. if [ "${{ inputs.sublevel }}" -le "117" ]; then
  82. echo "Applying fdinfo.c Android 12 5.10 Fake Patch"
  83. sed -i '/^[[:space:]]*\/\*$/,/^[[:space:]]*u32 mask = mark->mask & IN_ALL_EVENTS;$/d' fs/notify/fdinfo.c
  84. perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c
  85. perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c
  86. fi
  87. - name: Apply Android 13 5.10 Fake Patches
  88. shell: bash
  89. if: inputs.version == 'android13-5.10'
  90. working-directory: ${{ github.workspace }}/kernel/common
  91. run: |
  92. echo "Applying Android 13 5.10 SUSFS fixes"
  93. if [ "${{ inputs.sublevel }}" -le "107" ]; then
  94. echo "Applying fdinfo.c Android 13 5.10 Fake Patch"
  95. sed -i '/^[[:space:]]*\/\*$/,/^[[:space:]]*u32 mask = mark->mask & IN_ALL_EVENTS;$/d' fs/notify/fdinfo.c
  96. perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c
  97. perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c
  98. fi
  99. - name: Apply Android 13 5.15 Fake Patches
  100. shell: bash
  101. if: inputs.version == 'android13-5.15'
  102. working-directory: ${{ github.workspace }}/kernel/common
  103. run: |
  104. echo "Applying Android 13 5.15 SUSFS fixes"
  105. if [ "${{ inputs.sublevel }}" -le "41" ]; then
  106. #echo "Applying base.c Android 13 5.15 Fake Patch"
  107. #sed -i 's/^int this_len = min_t(int, count, PAGE_SIZE);$/size_t this_len = min_t(size_t, count, PAGE_SIZE);/' fs/proc/base.c
  108. echo "Applying namespace.c Android 13 5.15 SUSFS fixes"
  109. sed -i '/^#include <linux\/shmem_fs.h>$/a #include <linux/mnt_idmapping.h>' fs/namespace.c
  110. echo "Applying open.c Android 13 5.15 Fake Patch"
  111. sed -i '/^#include <linux\/compat.h>$/a #include <linux/mnt_idmapping.h>' fs/open.c
  112. echo "Applying fdinfo.c Android 13 5.15 Fake Patch"
  113. sed -i '/^[[:space:]]*\/\*$/,/^[[:space:]]*u32 mask = mark->mask & IN_ALL_EVENTS;$/d' fs/notify/fdinfo.c
  114. perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c
  115. perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c
  116. fi
  117. if [ "${{ inputs.sublevel }}" -ge "197" ]; then
  118. echo "Applying namespace.c Android 13 5.15 Fake Patch"
  119. sed -i '/^#include <trace\/hooks\/blk.h>$/d' fs/namespace.c
  120. fi
  121. if [ "${{ inputs.sublevel }}" -ge "207" ]; then
  122. echo "Applying task_mmu.c Android 13 5.15 Fake Patch"
  123. sed -i '/^#include <trace\/hooks\/mm.h>$/d' fs/proc/task_mmu.c
  124. fi
  125. - name: Apply Android 14 6.1 Fake Patches
  126. shell: bash
  127. if: inputs.version == 'android14-6.1'
  128. working-directory: ${{ github.workspace }}/kernel/common
  129. run: |
  130. if [ "${{ inputs.sublevel }}" -le "25" ]; then
  131. echo "Applying base.c Android 14 6.1 Fake Patch"
  132. sed -i '/^#include <trace\/events\/oom.h>$/a #include <trace/hooks/sched.h>' fs/proc/base.c
  133. fi
  134. if [ "${{ inputs.sublevel }}" -le "141" ]; then
  135. echo "Applying base.c Android 14 6.1 Fake Patch"
  136. sed -i '/^#include <linux\/cpufreq_times.h>$/a #include <linux/dma-buf.h>' fs/proc/base.c
  137. fi
  138. if [ "${{ inputs.sublevel }}" -ge "157" ]; then
  139. echo "Applying namespace.c Android 14 6.1 Fake Patch"
  140. sed -i '/^#include <trace\/hooks\/blk.h>$/d' fs/namespace.c
  141. fi
  142. - name: Apply Android 15 6.6 Fake Patches
  143. shell: bash
  144. if: inputs.version == 'android15-6.6'
  145. working-directory: ${{ github.workspace }}/kernel/common
  146. run: |
  147. echo "Applying 6.6 SUSFS fixes"
  148. if [ "${{ inputs.sublevel }}" -le "30" ]; then
  149. echo "Applying taskmmu.c Android 15 6.6 Fake Patch"
  150. sed -i '/smap_gather_stats(vma, &mss, last_vma_end);/a\last_vma_end = vma->vm_end;' fs/proc/task_mmu.c
  151. perl -0777 -i -pe '
  152. @l = split /\n/;
  153. for ($i = $#l; $i >= 0; $i--) {
  154. if ($l[$i] =~ /last_vma_end = vma->vm_end;/) {
  155. $l[$i] = "\t\t\t\t" . $l[$i];
  156. splice(@l, $i + 1, 0, "\t\t\t}");
  157. # add { to the if line above
  158. for ($j = $i; $j >= 0; $j--) {
  159. if ($l[$j] =~ /if\s*\(vma->vm_end > last_vma_end\)/) {
  160. $l[$j] =~ s/\)\s*$/) {/;
  161. last;
  162. }
  163. }
  164. last;
  165. }
  166. }
  167. $_ = join "\n", @l
  168. ' fs/proc/task_mmu.c
  169. fi
  170. if [ "${{ inputs.sublevel }}" -le "92" ]; then
  171. echo "Applying base.c Android 15 6.6 Fake Patch"
  172. sed -i '/^#include <linux\/cpufreq_times.h>$/a #include <linux/dma-buf.h>' fs/proc/base.c
  173. fi
  174. if [ "${{ inputs.sublevel }}" -le "57" ]; then
  175. echo "Applying base.c Android 15 6.6 Fake Patch"
  176. sed -i '/^#include <linux\/sched\/sysctl.h>$/a #include <linux/zswap.h>' mm/memory.c
  177. fi
  178. - name: Apply Android 16 6.12 Fake Patches
  179. shell: bash
  180. if: inputs.version == 'android16-6.12'
  181. working-directory: ${{ github.workspace }}/kernel/common
  182. run: |
  183. echo "Applying 6.12 SUSFS fixes"
  184. if [ "${{ inputs.sublevel }}" -ge "58" ]; then
  185. echo "Applying exec.c Android 16 6.12 Fake Patch"
  186. sed -i '/^#include <linux\/dma-buf.h>$/d' fs/exec.c
  187. fi
  188. if [ "${{ inputs.sublevel }}" -ge "69" ]; then
  189. echo "Applying task_mmu.c Android 16 6.12 Fake Patch"
  190. sed -i 's/vma_data_pages/vma_pages/g' fs/proc/task_mmu.c
  191. fi
  192. - name: Apply Kernel SUSFS Patches
  193. shell: bash
  194. working-directory: ${{ github.workspace }}/kernel/common
  195. run: |
  196. patch -p1 < 50_add_susfs_in_gki-${{ inputs.version }}.patch
  197. - name: Revert Android 12 5.10 Fake Patches
  198. shell: bash
  199. if: inputs.version == 'android12-5.10'
  200. working-directory: ${{ github.workspace }}/kernel/common
  201. run: |
  202. if [ "${{ inputs.sublevel }}" -le "43" ]; then
  203. echo "Reverting base.c Android 12 5.10 Fake Patch"
  204. sed -i 's/^size_t this_len = min_t(size_t, count, PAGE_SIZE);$/int this_len = min_t(int, count, PAGE_SIZE);/' fs/proc/base.c
  205. fi
  206. if [ "${{ inputs.sublevel }}" -le "117" ]; then
  207. echo "Reverting fdinfo.c Android 12 5.10 Fake Patch"
  208. perl -i -pe 's/^(\s+if \(inode\) \{)/$1\n\t\t\/\*\n\t\t * IN_ALL_EVENTS represents all of the mask bits\n\t\t * that we expose to userspace. There is at\n\t\t * least one bit (FS_EVENT_ON_CHILD) which is\n\t\t * used only internally to the kernel.\n\t\t *\/\n\t\tu32 mask = mark->mask & IN_ALL_EVENTS;/m' fs/notify/fdinfo.c
  209. perl -i -pe 's/\binotify_mark_user_mask\(mark\)/mask, mark->ignored_mask/g' fs/notify/fdinfo.c
  210. perl -i -pe 's/ignored_mask:0/ignored_mask:%x/g' fs/notify/fdinfo.c
  211. fi
  212. - name: Revert Android 13 5.10 Fake Patches
  213. shell: bash
  214. if: inputs.version == 'android13-5.10'
  215. working-directory: ${{ github.workspace }}/kernel/common
  216. run: |
  217. if [ "${{ inputs.sublevel }}" -le "107" ]; then
  218. echo "Reverting fdinfo.c Android 13 5.10 Fake Patch"
  219. perl -i -pe 's/^(\s+if \(inode\) \{)/$1\n\t\t\/\*\n\t\t * IN_ALL_EVENTS represents all of the mask bits\n\t\t * that we expose to userspace. There is at\n\t\t * least one bit (FS_EVENT_ON_CHILD) which is\n\t\t * used only internally to the kernel.\n\t\t *\/\n\t\tu32 mask = mark->mask & IN_ALL_EVENTS;/m' fs/notify/fdinfo.c
  220. perl -i -pe 's/\binotify_mark_user_mask\(mark\)/mask, mark->ignored_mask/g' fs/notify/fdinfo.c
  221. perl -i -pe 's/ignored_mask:0/ignored_mask:%x/g' fs/notify/fdinfo.c
  222. fi
  223. - name: Revert Android 13 5.15 Fake Patches
  224. shell: bash
  225. if: inputs.version == 'android13-5.15'
  226. working-directory: ${{ github.workspace }}/kernel/common
  227. run: |
  228. if [ "${{ inputs.sublevel }}" -le "41" ]; then
  229. #echo "Reverting base.c Android 13 5.15 Fake Patch"
  230. #sed -i 's/^size_t this_len = min_t(size_t, count, PAGE_SIZE);$/int this_len = min_t(int, count, PAGE_SIZE);/' fs/proc/base.c
  231. echo "Reverting namespace.c Android 13 5.15 Fake Patch"
  232. sed -i '/#include <linux\/mnt_idmapping.h>$/d' fs/namespace.c
  233. echo "Reverting open.c Android 13 5.15 Fake Patch"
  234. sed -i '/#include <linux\/mnt_idmapping.h>$/d' fs/open.c
  235. echo "Reverting fdinfo.c Android 13 5.15 Fake Patch"
  236. perl -i -pe 's/^(\s+if \(inode\) \{)/$1\n\t\t\/\*\n\t\t * IN_ALL_EVENTS represents all of the mask bits\n\t\t * that we expose to userspace. There is at\n\t\t * least one bit (FS_EVENT_ON_CHILD) which is\n\t\t * used only internally to the kernel.\n\t\t *\/\n\t\tu32 mask = mark->mask & IN_ALL_EVENTS;/m' fs/notify/fdinfo.c
  237. perl -i -pe 's/\binotify_mark_user_mask\(mark\)/mask, mark->ignored_mask/g' fs/notify/fdinfo.c
  238. perl -i -pe 's/ignored_mask:0/ignored_mask:%x/g' fs/notify/fdinfo.c
  239. sed -i 's|i_uid_into_mnt(i_user_ns(&fi->inode), &fi->inode).val|i_uid_into_mnt(\&init_user_ns, \&fi->inode).val|g' fs/susfs.c
  240. sed -i 's|i_uid_into_mnt(i_user_ns(inode), inode).val|i_uid_into_mnt(\&init_user_ns, inode).val|g' fs/susfs.c
  241. fi
  242. if [ "${{ inputs.sublevel }}" -ge "197" ]; then
  243. echo "Reverting namespace.c Android 13 5.15 Fake Patch"
  244. sed -i '/^#include "internal.h"$/a #include <trace/hooks/blk.h>' fs/namespace.c
  245. fi
  246. if [ "${{ inputs.sublevel }}" -ge "207" ]; then
  247. echo "Reverting task_mmu.c Android 13 5.15 Fake Patch"
  248. sed -i '/^#include <linux\/pkeys.h>$/a #include <trace/hooks/mm.h>' fs/proc/task_mmu.c
  249. fi
  250. - name: Revert Android 14 6.1 Fake Patches
  251. shell: bash
  252. if: inputs.version == 'android14-6.1'
  253. working-directory: ${{ github.workspace }}/kernel/common
  254. run: |
  255. if [ "${{ inputs.sublevel }}" -le "25" ]; then
  256. sed -i '/^#include <trace\/hooks\/sched.h>$/d' fs/proc/base.c
  257. fi
  258. if [ "${{ inputs.sublevel }}" -le "141" ]; then
  259. echo "Reverting base.c Android 14 6.1 Fake Patch"
  260. sed -i '/^#include <linux\/dma-buf.h>$/d' fs/proc/base.c
  261. fi
  262. if [ "${{ inputs.sublevel }}" -ge "157" ]; then
  263. echo "Reverting namespace.c Android 14 6.1 Fake Patch"
  264. sed -i '/^#include "internal.h"$/a #include <trace/hooks/blk.h>' fs/namespace.c
  265. fi
  266. - name: Revert Android 15 6.6 Fake Patches
  267. shell: bash
  268. if: inputs.version == 'android15-6.6'
  269. working-directory: ${{ github.workspace }}/kernel/common
  270. run: |
  271. echo "Reverting 6.6 Fake Patches"
  272. if [ "${{ inputs.sublevel }}" -le "92" ]; then
  273. echo "Reverting base.c Android 15 6.6 Fake Patch"
  274. sed -i '/^#include <linux\/dma-buf.h>$/d' fs/proc/base.c
  275. fi
  276. if [ "${{ inputs.sublevel }}" -le "57" ]; then
  277. echo "Reverting memory.c Android 15 6.6 Fake Patch"
  278. sed -i '/^#include <linux\/zswap.h>$/d' mm/memory.c
  279. fi
  280. - name: Revert Android 16 6.12 Fake Patches
  281. shell: bash
  282. if: inputs.version == 'android16-6.12'
  283. working-directory: ${{ github.workspace }}/kernel/common
  284. run: |
  285. echo "Reverting 6.12 Fake Patches"
  286. if [ "${{ inputs.sublevel }}" -ge "58" ]; then
  287. echo "Reverting exec.c Android 16 6.12 Fake Patch"
  288. sed -i '/^#include /a #include <linux/dma-buf.h>' fs/exec.c
  289. fi
  290. if [ "${{ inputs.sublevel }}" -ge "69" ]; then
  291. echo "Reverting task_mmu.c Android 16 6.12 Fake Patch"
  292. sed -i 's/vma_pages/vma_data_pages/g' fs/proc/task_mmu.c
  293. fi
  294. - name: Apply Kernel SUSFS Patches
  295. shell: bash
  296. if: true
  297. working-directory: ${{ github.workspace }}/kernel/common
  298. run: |
  299. SHOW_PAD_FIX=0
  300. if [[ "${{ inputs.version }}" = "android12-5.10" && "${{ inputs.sublevel }}" -le 209 ]]; then
  301. SHOW_PAD_FIX=1
  302. elif [[ "${{ inputs.version }}" = "android13-5.10" && "${{ inputs.sublevel }}" -le 209 && "${{ inputs.os_patch_level }}" != "2024-05" ]]; then
  303. SHOW_PAD_FIX=1
  304. elif [[ "${{ inputs.version }}" = "android13-5.15" && "${{ inputs.sublevel }}" -le 148 && "${{ inputs.os_patch_level }}" != "2024-05" ]]; then
  305. SHOW_PAD_FIX=1
  306. elif [[ "${{ inputs.version }}" = "android14-5.15" && "${{ inputs.sublevel }}" -le 148 && "${{ inputs.os_patch_level }}" != "2024-05" ]]; then
  307. SHOW_PAD_FIX=1
  308. elif [[ "${{ inputs.version }}" = "android14-6.1" && "${{ inputs.sublevel }}" -le 75 && "${{ inputs.os_patch_level }}" != "2024-05" ]]; then
  309. SHOW_PAD_FIX=1
  310. fi
  311. if [[ "$SHOW_PAD_FIX" = "1" ]]; then
  312. sed -i -e 's/goto show_pad;/return 0;/' ./fs/proc/task_mmu.c
  313. fi