action.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. name: Setup SUSFS
  2. description: Clone and apply SUSFS patches with version-specific fixes
  3. inputs:
  4. android_version:
  5. description: 'Android version (e.g., android15)'
  6. required: true
  7. kernel_version:
  8. description: 'Kernel version (e.g., 6.6)'
  9. required: true
  10. os_patch_level:
  11. description: 'OS patch level (e.g., 2024-07)'
  12. required: true
  13. sublevel:
  14. description: 'Kernel sublevel'
  15. required: true
  16. susfs_commit:
  17. description: 'Commit map (branch:commit,branch:commit...)'
  18. required: false
  19. runs:
  20. using: composite
  21. steps:
  22. - name: Setup SUSFS Branch
  23. shell: bash
  24. run: |
  25. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  26. SUSFS_REPO="https://gitlab.com/simonpunk/susfs4ksu.git"
  27. echo "Preparing SUSFS for branch: $SUSFS_BRANCH"
  28. # Parse commit map to find the commit for this branch
  29. COMMIT_MAP="${{ inputs.susfs_commit }}"
  30. TARGET_COMMIT=""
  31. if [ -n "$COMMIT_MAP" ]; then
  32. # Split by comma
  33. IFS=',' read -ra ENTRIES <<< "$COMMIT_MAP"
  34. for entry in "${ENTRIES[@]}"; do
  35. # Split by colon
  36. IFS=':' read -r branch commit <<< "$entry"
  37. if [ "$branch" == "$SUSFS_BRANCH" ]; then
  38. TARGET_COMMIT="$commit"
  39. break
  40. fi
  41. done
  42. fi
  43. if [ -n "$TARGET_COMMIT" ]; then
  44. echo "Found specific commit for $SUSFS_BRANCH: $TARGET_COMMIT"
  45. git clone "$SUSFS_REPO" -b "$SUSFS_BRANCH" susfs4ksu
  46. cd susfs4ksu
  47. git checkout "$TARGET_COMMIT"
  48. cd ..
  49. else
  50. echo "No specific commit found for $SUSFS_BRANCH, cloning latest..."
  51. git clone "$SUSFS_REPO" -b "$SUSFS_BRANCH" --depth=1 susfs4ksu
  52. fi
  53. SUSFS_VERSION="v2.1.0"
  54. echo "SUSFS_VERSION=$SUSFS_VERSION" >> $GITHUB_ENV
  55. echo "SUSFS_BRANCH=$SUSFS_BRANCH" >> $GITHUB_ENV
  56. echo "SUSFS_COMMIT=$TARGET_COMMIT" >> $GITHUB_ENV
  57. - name: Enable KernelSU SUSFS Config
  58. shell: bash
  59. working-directory: ${{ github.workspace }}/kernel
  60. run: |
  61. cat >> "${{ github.workspace }}/wild_gki.fragment" << 'EOF'
  62. # KernelSU SUSFS Configuration
  63. CONFIG_KSU_SUSFS=y
  64. CONFIG_KSU_SUSFS_SUS_PATH=y
  65. CONFIG_KSU_SUSFS_SUS_MOUNT=y
  66. CONFIG_KSU_SUSFS_SUS_KSTAT=y
  67. CONFIG_KSU_SUSFS_SPOOF_UNAME=y
  68. CONFIG_KSU_SUSFS_ENABLE_LOG=y
  69. CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y
  70. CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y
  71. CONFIG_KSU_SUSFS_OPEN_REDIRECT=y
  72. CONFIG_KSU_SUSFS_SUS_MAP=y
  73. EOF
  74. - name: Apply KSU SUSFS Patches
  75. shell: bash
  76. working-directory: ${{ github.workspace }}/kernel/KernelSU-Next
  77. run: |
  78. cp ${{ github.workspace }}/kernel_patches/wild/ksun-e6ba52b-susfs-v2.1.0-a14-6.1-e1c57040.patch ./
  79. patch -p1 < ksun-e6ba52b-susfs-v2.1.0-a14-6.1-e1c57040.patch
  80. - name: Apply Kernel SUSFS Patches
  81. shell: bash
  82. working-directory: ${{ github.workspace }}/kernel/common
  83. run: |
  84. # Apply base SUSFS patches
  85. cp "${{ github.workspace }}/susfs4ksu/kernel_patches/fs/"* "${{ github.workspace }}/kernel/common/fs/"
  86. cp "${{ github.workspace }}/susfs4ksu/kernel_patches/include/linux/"* "${{ github.workspace }}/kernel/common/include/linux/"
  87. cp ${{ github.workspace }}/susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./
  88. FIX_REJ=0
  89. if [ "${{ inputs.kernel_version }}" = "5.10" ] && [ "${{ inputs.android_version }}" = "android12" ]; then
  90. echo "Applying Android 12 5.10 SUSFS fixes"
  91. if [ "${{ inputs.sublevel }}" -le "43" ]; then
  92. 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
  93. fi
  94. if [ "${{ inputs.sublevel }}" -le "117" ]; then
  95. perl -i -0pe 's/^\s*\/\*[\s\S]*?IN_ALL_EVENTS.*?u32 mask = mark->mask & IN_ALL_EVENTS;\s*?\n//m' fs/notify/fdinfo.c
  96. fi
  97. fi
  98. if [ "${{ inputs.kernel_version }}" = "5.15" ] && [ "${{ inputs.android_version }}" = "android13" ]; then
  99. echo "Applying Android 13 5.15 SUSFS fixes"
  100. if grep -q '^size_t this_len = min_t(size_t, count, PAGE_SIZE);$' fs/proc/base.c; then
  101. 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
  102. FIX_REJ=1
  103. fi
  104. if ! grep -q '^#include <linux/mnt_idmapping.h>$' fs/namespace.c; then
  105. sed -i '/^#include <linux\/shmem_fs.h>$/a #include <linux/mnt_idmapping.h>' fs/namespace.c
  106. FIX_REJ=1
  107. fi
  108. if ! grep -q '^#include <linux/mnt_idmapping.h>$' fs/open.c; then
  109. sed -i '/^#include <linux\/compat.h>$/a #include <linux/mnt_idmapping.h>' fs/open.c
  110. FIX_REJ=1
  111. fi
  112. fi
  113. if [ "${{ inputs.kernel_version }}" = "6.1" ]; then
  114. if grep -q '^#include <trace/hooks/blk.h>$' fs/namespace.c; then
  115. sed -i '/^#include <trace\/hooks\/blk.h>$/d' fs/namespace.c
  116. FIX_REJ=1
  117. fi
  118. fi
  119. if [ "${{ inputs.kernel_version }}" = "6.6" ]; then
  120. echo "Applying 6.6 SUSFS fixes"
  121. if ! grep -q '^#include <trace/hooks/fs.h>$' fs/namespace.c; then
  122. sed -i '/^#include <trace\/hooks\/blk.h>$/a #include <trace/hooks/fs.h>' fs/namespace.c
  123. FIX_REJ=1
  124. fi
  125. if ! grep -q '^#include <linux/dma-buf.h>$' fs/proc/base.c; then
  126. sed -i '/^#include <linux\/cpufreq_times.h>$/a #include <linux/dma-buf.h>' fs/proc/base.c
  127. FIX_REJ=1
  128. fi
  129. if ! grep -q '^\s*pagemap_entry_t \*res = NULL;$' fs/proc/task_mmu.c; then
  130. sed -i '/int ret.*= 0, copied.*= 0;/{
  131. /int ret.*= 0, copied.*= 0;/!d
  132. a\
  133. unsigned int nr_subpages = __PAGE_SIZE / PAGE_SIZE;\
  134. pagemap_entry_t *res = NULL;
  135. }' fs/proc/task_mmu.c
  136. FIX_REJ=1
  137. fi
  138. fi
  139. if [ "${{ inputs.kernel_version }}" = "6.12" ]; then
  140. echo "Applying 6.12 SUSFS fixes"
  141. if grep -q '^#include <linux/dma-buf.h>$' fs/exec.c; then
  142. sed -i '/^#include <linux\/dma-buf.h>$/d' fs/exec.c
  143. FIX_REJ=1
  144. fi
  145. fi
  146. patch -p1 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true
  147. if [ "${{ inputs.kernel_version }}" = "5.10" ] && [ "${{ inputs.android_version }}" = "android12" ]; then
  148. if [ "${{ inputs.sublevel }}" -le "43" ]; then
  149. 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
  150. fi
  151. if [ "${{ inputs.sublevel }}" -le "117" ]; then
  152. perl -i -pe 's/^(\s*if \(inode\) \{)/$1\n \/\*\n * IN_ALL_EVENTS represents all of the mask bits\n * that we expose to userspace. There is at\n * least one bit (FS_EVENT_ON_CHILD) which is\n * used only internally to the kernel.\n *\/\n u32 mask = mark->mask & IN_ALL_EVENTS;/m' fs/notify/fdinfo.c
  153. fi
  154. fi
  155. if [ "${{ inputs.kernel_version }}" = "5.15" ] && [ "${{ inputs.android_version }}" = "android13" ]; then
  156. sed -i '/#include <linux\/mnt_idmapping.h>$/d' fs/namespace.c
  157. sed -i '/#include <linux\/mnt_idmapping.h>$/d' fs/open.c
  158. 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
  159. fi
  160. if [ "${{ inputs.kernel_version }}" = "6.1" ]; then
  161. sed -i '/^#include "internal.h"$/a #include <trace/hooks/blk.h>' fs/namespace.c
  162. fi
  163. if [ "${{ inputs.kernel_version }}" = "6.6" ]; then
  164. sed -i '/^#include <trace\/hooks\/fs.h>$/d' fs/namespace.c
  165. sed -i '/^#include <linux\/dma-buf.h>$/d' fs/proc/base.c
  166. sed -i '/unsigned int nr_subpages.*__PAGE_SIZE.*PAGE_SIZE/d' fs/proc/task_mmu.c
  167. sed -i '/pagemap_entry_t.*res.*NULL/d' fs/proc/task_mmu.c
  168. fi
  169. if [ "${{ inputs.kernel_version }}" = "6.12" ]; then
  170. sed -i '/^#include <linux\/ksh.h>$/a #include <linux/dma-buf.h>' fs/exec.c
  171. FIX_REJ=1
  172. fi
  173. SHOW_PAD_FIX=0
  174. if [[ "${{ inputs.android_version }}" = "android12" && "${{ inputs.kernel_version }}" = "5.10" && "${{ inputs.sublevel }}" -le 209 ]]; then
  175. SHOW_PAD_FIX=1
  176. elif [[ "${{ inputs.android_version }}" = "android13" && "${{ inputs.kernel_version }}" = "5.10" && "${{ inputs.sublevel }}" -le 209 && "${{ inputs.os_patch_level }}" != "2024-05" ]]; then
  177. SHOW_PAD_FIX=1
  178. elif [[ "${{ inputs.android_version }}" = "android13" && "${{ inputs.kernel_version }}" = "5.15" && "${{ inputs.sublevel }}" -le 148 && "${{ inputs.os_patch_level }}" != "2024-05" ]]; then
  179. SHOW_PAD_FIX=1
  180. elif [[ "${{ inputs.android_version }}" = "android14" && "${{ inputs.kernel_version }}" = "5.15" && "${{ inputs.sublevel }}" -le 148 && "${{ inputs.os_patch_level }}" != "2024-05" ]]; then
  181. SHOW_PAD_FIX=1
  182. elif [[ "${{ inputs.android_version }}" = "android14" && "${{ inputs.kernel_version }}" = "6.1" && "${{ inputs.sublevel }}" -le 75 && "${{ inputs.os_patch_level }}" != "2024-05" ]]; then
  183. SHOW_PAD_FIX=1
  184. fi
  185. if [[ "$SHOW_PAD_FIX" = "1" ]]; then
  186. sed -i -e 's/goto show_pad;/return 0;/' ./fs/proc/task_mmu.c
  187. fi
  188. - name: Apply Android 13 5.10 Fixes
  189. if: inputs.android_version == 'android13' && inputs.kernel_version == '5.10'
  190. shell: bash
  191. working-directory: ${{ github.workspace }}/kernel/common
  192. run: |
  193. if [ "${{ inputs.sublevel }}" -le "107" ]; then
  194. sed -i '/u32 mask = mark->mask & IN_ALL_EVENTS;/r'<(cat <<'EOF'
  195. #ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
  196. mnt = real_mount(file->f_path.mnt);
  197. if (mnt->mnt_id >= DEFAULT_KSU_MNT_ID &&
  198. likely(susfs_is_current_proc_umounted()))
  199. {
  200. struct path path;
  201. char *pathname = kmalloc(PAGE_SIZE, GFP_KERNEL);
  202. char *dpath;
  203. if (!pathname) {
  204. goto orig_flow;
  205. }
  206. dpath = d_path(&file->f_path, pathname, PAGE_SIZE);
  207. if (!dpath) {
  208. goto out_kfree;
  209. }
  210. if (kern_path(dpath, 0, &path)) {
  211. goto out_kfree;
  212. }
  213. if (!path.dentry->d_inode) {
  214. goto out_path_put;
  215. }
  216. seq_printf(m, "inotify wd:%x ino:%lx sdev:%x mask:%x ignored_mask:0 ",
  217. inode_mark->wd, path.dentry->d_inode->i_ino, path.dentry->d_inode->i_sb->s_dev,
  218. (mark->mask & IN_ALL_EVENTS));
  219. show_mark_fhandle(m, path.dentry->d_inode);
  220. seq_putc(m, '\n');
  221. path_put(&path);
  222. kfree(pathname);
  223. iput(inode);
  224. return;
  225. out_path_put:
  226. path_put(&path);
  227. out_kfree:
  228. kfree(pathname);
  229. }
  230. orig_flow:
  231. #endif // #ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
  232. EOF
  233. ) fs/notify/fdinfo.c
  234. fi
  235. - name: Apply Android 13 5.15 Fixes
  236. if: inputs.android_version == 'android13' && inputs.kernel_version == '5.15'
  237. shell: bash
  238. working-directory: ${{ github.workspace }}/kernel/common
  239. run: |
  240. if [ "${{ inputs.sublevel }}" -le "117" ]; then
  241. sed -i '/u32 mask = mark->mask & IN_ALL_EVENTS;/r'<(cat <<'EOF'
  242. #ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
  243. mnt = real_mount(file->f_path.mnt);
  244. if (mnt->mnt_id >= DEFAULT_KSU_MNT_ID &&
  245. likely(susfs_is_current_proc_umounted()))
  246. {
  247. struct path path;
  248. char *pathname = kmalloc(PAGE_SIZE, GFP_KERNEL);
  249. char *dpath;
  250. if (!pathname) {
  251. goto orig_flow;
  252. }
  253. dpath = d_path(&file->f_path, pathname, PAGE_SIZE);
  254. if (!dpath) {
  255. goto out_kfree;
  256. }
  257. if (kern_path(dpath, 0, &path)) {
  258. goto out_kfree;
  259. }
  260. if (!path.dentry->d_inode) {
  261. goto out_path_put;
  262. }
  263. seq_printf(m, "inotify wd:%x ino:%lx sdev:%x mask:%x ignored_mask:0 ",
  264. inode_mark->wd, path.dentry->d_inode->i_ino, path.dentry->d_inode->i_sb->s_dev,
  265. (mark->mask & IN_ALL_EVENTS));
  266. show_mark_fhandle(m, path.dentry->d_inode);
  267. seq_putc(m, '\n');
  268. path_put(&path);
  269. kfree(pathname);
  270. iput(inode);
  271. return;
  272. out_path_put:
  273. path_put(&path);
  274. out_kfree:
  275. kfree(pathname);
  276. }
  277. orig_flow:
  278. #endif // #ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
  279. EOF
  280. ) fs/notify/fdinfo.c
  281. fi
  282. - name: Apply Android 14 6.1 Fixes
  283. if: inputs.android_version == 'android14' && inputs.kernel_version == '6.1'
  284. shell: bash
  285. working-directory: ${{ github.workspace }}/kernel/common
  286. run: |
  287. if [ "${{ inputs.sublevel }}" -le "141" ]; then
  288. sed -i '/#include "fd.h"/r'<(cat <<'EOF'
  289. #ifdef CONFIG_KSU_SUSFS_SUS_MAP
  290. #include <linux/susfs_def.h>
  291. #endif
  292. EOF
  293. ) fs/proc/base.c
  294. fi