name: 'Apply SUSFS Patches' description: 'Copy base SUSFS patches and apply version-specific fake patches' inputs: version: description: 'Kernel config version (e.g., android15-6.6)' required: true sublevel: description: 'Kernel sublevel' required: true os_patch_level: description: 'OS patch level (e.g., 2024-07)' required: true runs: using: "composite" steps: - name: Apply Kernel SUSFS Patches shell: bash working-directory: ${{ github.workspace }}/kernel/common run: | # Apply base SUSFS patches cp "${{ github.workspace }}/susfs4ksu/kernel_patches/fs/"* "${{ github.workspace }}/kernel/common/fs/" cp "${{ github.workspace }}/susfs4ksu/kernel_patches/include/linux/"* "${{ github.workspace }}/kernel/common/include/linux/" cp ${{ github.workspace }}/susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.version }}.patch ./ - name: Apply Android 12 5.10 Fake Patches shell: bash if: inputs.version == 'android12-5.10' working-directory: ${{ github.workspace }}/kernel/common run: | if [ "${{ inputs.sublevel }}" -le "43" ]; then echo "Applying base.c Android 12 5.10 Fake Patch" 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 fi if [ "${{ inputs.sublevel }}" -le "117" ]; then echo "Applying fdinfo.c Android 12 5.10 Fake Patch" 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 perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c echo "Adding inotify_mark_user_mask function definition" 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)' fi - name: Apply Android 13 5.10 Fake Patches shell: bash if: inputs.version == 'android13-5.10' working-directory: ${{ github.workspace }}/kernel/common run: | echo "Applying Android 13 5.10 SUSFS fixes" if [ "${{ inputs.sublevel }}" -le "107" ]; then echo "Applying fdinfo.c Android 13 5.10 Fake Patch" 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 perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c echo "Adding inotify_mark_user_mask function definition" 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)' fi - name: Apply Android 13 5.15 Fake Patches shell: bash if: inputs.version == 'android13-5.15' working-directory: ${{ github.workspace }}/kernel/common run: | echo "Applying Android 13 5.15 SUSFS fixes" if [ "${{ inputs.sublevel }}" -le "41" ]; then echo "Applying namespace.c Android 13 5.15 SUSFS fixes" sed -i '/^#include $/a #include ' fs/namespace.c echo "Applying open.c Android 13 5.15 Fake Patch" sed -i '/^#include $/a #include ' fs/open.c echo "Applying fdinfo.c Android 13 5.15 Fake Patch" 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 perl -i -pe 's/\bmask,\s*mark->ignored_mask/inotify_mark_user_mask(mark)/g' fs/notify/fdinfo.c perl -i -pe 's/ignored_mask:%x/ignored_mask:0/g' fs/notify/fdinfo.c echo "Adding inotify_mark_user_mask function definition" 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)' fi if [ "${{ inputs.sublevel }}" -ge "197" ]; then echo "Applying namespace.c Android 13 5.15 Fake Patch" sed -i '/^#include $/d' fs/namespace.c fi if [ "${{ inputs.sublevel }}" -ge "197" ]; then echo "Applying task_mmu.c Android 13 5.15 Fake Patch" sed -i '/^#include $/d' fs/proc/task_mmu.c fi - name: Apply Android 14 6.1 Fake Patches shell: bash if: inputs.version == 'android14-6.1' working-directory: ${{ github.workspace }}/kernel/common run: | if [ "${{ inputs.sublevel }}" -le "25" ]; then echo "Applying base.c Android 14 6.1 Fake Patch" sed -i '/^#include $/a #include ' fs/proc/base.c fi if [ "${{ inputs.sublevel }}" -le "141" ]; then echo "Applying base.c Android 14 6.1 Fake Patch" sed -i '/^#include $/a #include ' fs/proc/base.c fi if [ "${{ inputs.sublevel }}" -ge "157" ]; then echo "Applying namespace.c Android 14 6.1 Fake Patch" sed -i '/^#include $/d' fs/namespace.c fi - name: Apply Android 15 6.6 Fake Patches shell: bash if: inputs.version == 'android15-6.6' working-directory: ${{ github.workspace }}/kernel/common run: | echo "Applying 6.6 SUSFS fixes" if [ "${{ inputs.sublevel }}" -le "30" ]; then echo "Applying taskmmu.c Android 15 6.6 Fake Patch" 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)' fi if [ "${{ inputs.sublevel }}" -le "30" ] && [ "${{ inputs.os_patch_level }}" = "2024-07" ]; then echo "Adding __fold_filemap_fixup_entry stub for 2024-07 kernels" sed -i '/^#include $/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 fi if [ "${{ inputs.sublevel }}" -le "92" ]; then echo "Applying base.c Android 15 6.6 Fake Patch" sed -i '/^#include $/a #include ' fs/proc/base.c fi if [ "${{ inputs.sublevel }}" -le "57" ]; then echo "Applying base.c Android 15 6.6 Fake Patch" sed -i '/^#include $/a #include ' mm/memory.c fi - name: Apply Android 16 6.12 Fake Patches shell: bash if: inputs.version == 'android16-6.12' working-directory: ${{ github.workspace }}/kernel/common run: | echo "Applying 6.12 SUSFS fixes" if [ "${{ inputs.sublevel }}" -ge "58" ]; then echo "Applying exec.c Android 16 6.12 Fake Patch" sed -i '/^#include $/d' fs/exec.c fi if [ "${{ inputs.sublevel }}" -ge "69" ]; then echo "Applying task_mmu.c Android 16 6.12 Fake Patch" sed -i 's/vma_data_pages/vma_pages/g' fs/proc/task_mmu.c fi - name: Apply Kernel SUSFS Patches shell: bash working-directory: ${{ github.workspace }}/kernel/common run: | patch -p1 < 50_add_susfs_in_gki-${{ inputs.version }}.patch # SUSFS's OPEN_REDIRECT code unconditionally calls VMA_PAD_START(), which # only exists on GKI branches that carry Google's page-size-migration # feature (added to each android version's kernel/common branch at a # different, sometime later, os_patch_level). Older os_patch_levels in # our build matrix predate it, so fall back to a no-padding definition # when the real header/macro isn't present. This is version-agnostic and # a no-op wherever the real header already provides it. #if grep -q 'VMA_PAD_START(' fs/proc/task_mmu.c && ! grep -qE '#include |define VMA_PAD_START' fs/proc/task_mmu.c; then # sed -i '1a #ifndef VMA_PAD_START\n#define VMA_PAD_START(vma) ((vma)->vm_end)\n#endif' fs/proc/task_mmu.c # echo "Added VMA_PAD_START fallback definition to fs/proc/task_mmu.c" #fi # Same story for __fold_filemap_fixup_entry(), declared in page_size_compat.h. #if grep -q '__fold_filemap_fixup_entry' fs/proc/task_mmu.c && ! grep -q '#include ' fs/proc/task_mmu.c; then # sed -i '/#include /a #include ' fs/proc/task_mmu.c # echo "Added page_size_compat.h include to fs/proc/task_mmu.c" #fi # Fix set_nameidata() calls for 5.10 kernels. # The SUSFS patch adds set_nameidata(nd, old_dfd, fake_filename, NULL) with 4 args, # but 5.10 kernels only have 3-param set_nameidata(p, dfd, name) - no root param. #if [[ "${{ inputs.version }}" == "android12-5.10" || "${{ inputs.version }}" == "android13-5.10" ]]; then # if grep -q 'set_nameidata(nd, old_dfd, fake_filename, NULL)' fs/namei.c; then # echo "Fixing set_nameidata calls for 5.10 (4-arg -> 3-arg)" # sed -i 's/set_nameidata(nd, old_dfd, fake_filename, NULL)/set_nameidata(nd, old_dfd, fake_filename)/g' fs/namei.c # fi #fi # Fix getname_flags() arity for 6.12: SUSFS patch emits 3-arg # getname_flags(filename, lookup_flags, NULL) but 6.12 fs.h declares # only 2-arg getname_flags(const char *, int). Drop the trailing NULL. #if [[ "${{ inputs.version }}" == "android16-6.12" ]]; then # if grep -q 'getname_flags(filename, lookup_flags, NULL)' fs/open.c; then # echo "Fixing getname_flags 3-arg -> 2-arg for 6.12" # sed -i 's/getname_flags(filename, lookup_flags, NULL)/getname_flags(filename, lookup_flags)/g' fs/open.c # fi #fi