]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Fix the issue that VTOY_LINUX_REMOUNT=1 does not work on some distros (e.g. Pop OS...
authorlongpanda <admin@ventoy.net>
Fri, 6 Oct 2023 13:12:34 +0000 (21:12 +0800)
committerlongpanda <admin@ventoy.net>
Fri, 6 Oct 2023 13:12:34 +0000 (21:12 +0800)
12 files changed:
DMPATCH/dmpatch.c
DMPATCH/readme.txt
DMPATCH/ubuntu_build.sh
IMG/cpio/ventoy/hook/suse/udev_disk_hook.sh
IMG/cpio/ventoy/hook/ventoy-hook-lib.sh
IMG/cpio_x86/ventoy/tool/dm_patch_64.ko
IMG/cpio_x86/ventoy/tool/dm_patch_ibt_64.ko
VtoyTool/vtoykmod.c
VtoyTool/vtoytool/00/vtoytool_32
VtoyTool/vtoytool/00/vtoytool_64
VtoyTool/vtoytool/00/vtoytool_aa64
VtoyTool/vtoytool/00/vtoytool_m64e

index e508a0624e976f9814054875c9489ced6db717fd..2e5d1a981b950687ab30feb6951bf4d470ccf04b 100644 (file)
@@ -78,15 +78,25 @@ static volatile ko_param g_ko_param =
 #define PATCH_OP_POS2    1
 #define CODE_MATCH2(code, i) \
     (code[i] == 0x0C && code[i + 1] == 0x80 && code[i + 2] == 0x89 && code[i + 3] == 0xC6)
+    
+#define PATCH_OP_POS3    4
+#define CODE_MATCH3(code, i) \
+    (code[i] == 0x44 && code[i + 1] == 0x89 && code[i + 2] == 0xe8 && code[i + 3] == 0x0c && code[i + 4] == 0x80)
+
+
+
+
 
 #elif defined(CONFIG_X86_32)
 #define PATCH_OP_POS1    2
 #define CODE_MATCH1(code, i) \
     (code[i] == 0x80 && code[i + 1] == 0xca && code[i + 2] == 0x80 && code[i + 3] == 0xe8)
 
-#define PATCH_OP_POS2    2
-#define CODE_MATCH2(code, i) \
-    (code[i] == 0x80 && code[i + 1] == 0xca && code[i + 2] == 0x80 && code[i + 3] == 0xe8)
+#define PATCH_OP_POS2    PATCH_OP_POS1
+#define CODE_MATCH2      CODE_MATCH1
+#define PATCH_OP_POS3    PATCH_OP_POS1
+#define CODE_MATCH3      CODE_MATCH1
+
 
 #else
 #error "unsupported arch"
@@ -173,7 +183,7 @@ static int notrace dmpatch_replace_code
 
     vdebug("patch for %s style[%d] 0x%lx %d\n", desc, style, addr, (int)size);
 
-    for (i = 0; i < (int)size - 4; i++)
+    for (i = 0; i < (int)size - 8; i++)
     {
         if (style == 1)
         {
@@ -183,7 +193,7 @@ static int notrace dmpatch_replace_code
                 cnt++;
             }
         }
-        else
+        else if (style == 2)
         {
             if (CODE_MATCH2(opCode, i) && cnt < MAX_PATCH)
             {
@@ -191,8 +201,20 @@ static int notrace dmpatch_replace_code
                 cnt++;
             }
         }
+        else if (style == 3)
+        {
+            if (CODE_MATCH3(opCode, i) && cnt < MAX_PATCH)
+            {
+                patch[cnt] = opCode + i + PATCH_OP_POS3;
+                cnt++;
+            }
+        }
     }
 
+
+
+
+
     if (cnt != expect || cnt >= MAX_PATCH)
     {
         vdebug("patch error: cnt=%d expect=%d\n", cnt, expect);
@@ -297,9 +319,16 @@ static int notrace dmpatch_init(void)
     r = dmpatch_replace_code(1, g_ko_param.sym_get_addr, g_ko_param.sym_get_size, 2, "dm_get_table_device", g_get_patch);
     if (r && g_ko_param.kv_major >= 5)
     {
-        vdebug("new patch dm_get_table_device...\n");
+        vdebug("new2 patch dm_get_table_device...\n");
         r = dmpatch_replace_code(2, g_ko_param.sym_get_addr, g_ko_param.sym_get_size, 1, "dm_get_table_device", g_get_patch);
     }
+
+    if (r && g_ko_param.kv_major >= 5)
+    {
+        vdebug("new3 patch dm_get_table_device...\n");
+        r = dmpatch_replace_code(3, g_ko_param.sym_get_addr, g_ko_param.sym_get_size, 1, "dm_get_table_device", g_get_patch);
+    }
+    
     
     if (r)
     {
index c71e06995512dfbf36b6529d2dee4c2d5abb89a0..c427d3a8f952b5332125a91204d0b1f5d3cf97ff 100644 (file)
@@ -1,10 +1,12 @@
-1. install ubuntu 21.10\r
-2. apt-get install build-essential flex libncurses-dev linux-headers-generic linux-source libssl-dev ...... and so on\r
-3. cp /lib/modules/5.13.0-23-generic/build/Module.symvers ./\r
-4. /boot/config-5.13.0-23-generic as .config   make oldconfig\r
+1. install ubuntu 22.04  5.15.0-25\r
+2. apt-get install build-essential flex libncurses-dev linux-headers-generic linux-source libssl-dev bison yacc vim libelf-dev  ...... and so on\r
+3. cp /lib/modules/5.15.0-25-generic/build/Module.symvers ./\r
+4. /boot/config-5.15.0-25-generic as .config   make oldconfig\r
 5. make menuconfig \r
     1. close CONFIG_STACKPROTECTOR\r
     2. close CONFIG_RETPOLINE\r
+    3. close CONFIG_UBSAN_BOUNDS\r
+    4. close CONFIG_UBSAN_ENUM\r
 \r
 6. modify ./scripts/mod/modpost.c\r
     1. skip add_srcversion (just return)\r
index 995603bc8de39e55cff7568c18f0faff9bd15b72..521b82a1f6680fbbcc5122529f776e0d99c36e12 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-FTPIP=168.0.0.209
+FTPIP=192.168.44.1
 FTPUSR='a:a'
 
 rm -f dmpatch.c Makefile Makefile_IBT
@@ -27,7 +27,7 @@ mkdir ./aa
 cp -a *.c aa/
 cp -a Makefile aa/
 
-cd /home/panda/linux-source-5.13.0
+cd /home/panda/linux-source-5.15.0
 make modules M=/home/panda/build/aa/
 strip --strip-debug /home/panda/build/aa/dm_patch.ko
 cd -
@@ -43,7 +43,7 @@ mkdir ./aa
 cp -a *.c aa/
 cp -a Makefile_IBT aa/Makefile
 
-cd /home/panda/linux-source-5.13.0
+cd /home/panda/linux-source-5.15.0
 make modules M=/home/panda/build/aa/
 strip --strip-debug /home/panda/build/aa/dm_patch_ibt.ko
 cd -
index 67f36922c35d5933984446132e0267a38d8eb554..d5e8170df8523eb496f2dfad03f0f1b759d5702e 100644 (file)
@@ -54,6 +54,21 @@ if [ -z "$dmsetup_path" ]; then
     ventoy_os_install_dmsetup "/dev/${1:0:-1}"
 fi
 
+if [ -f /proc/devices ]; then
+    vtlog "/proc/devices exist OK"
+else
+    for i in 1 2 3 4 5 6 7 8 9; do
+        if [ -f /proc/devices ]; then
+            vtlog "/proc/devices exist OK now"
+            break
+        else
+            vtlog "/proc/devices NOT exist, wait $i"
+            $BUSYBOX_PATH/sleep 1
+        fi
+    done
+fi
+
+
 ventoy_udev_disk_common_hook $*
 
 # OK finish
index e8567929b835cdfc26d0b28a73c2e2e9fe7fbf15..62c29967d3a49ad1e54feba7b810a310aa6fbe40 100644 (file)
@@ -209,11 +209,20 @@ ventoy_check_dm_module() {
         vtlog "modprobe failed, now try to insmod ko..."
     
         $FIND /lib/modules/ -name "dm-mod.ko*" | while read vtline; do
-            vtlog "insmode $vtline "
+            vtlog "insmod $vtline "
             $BUSYBOX_PATH/insmod $vtline >>$VTLOG 2>&1
+            if [ $? -eq 0 ]; then
+                vtlog "insmod success"
+            else
+                vtlog "insmod failed, try decompress"
+                if echo $vtline | $GREP -q "\.zst"; then
+                    $VTOY_PATH/tool/zstdcat $vtline > $VTOY_PATH/extract_dm_mod.ko
+                    $BUSYBOX_PATH/insmod $VTOY_PATH/extract_dm_mod.ko >>$VTLOG 2>&1
+                fi
+            fi
         done
     fi
-    
+
     if $GREP -q 'device-mapper' /proc/devices; then
         vtlog "device-mapper found in /proc/devices after retry"
         $BUSYBOX_PATH/true; return
@@ -292,6 +301,7 @@ ventoy_need_dm_patch() {
 }
 
 ventoy_dm_patch() {
+    vtDmPatchDebug=0
     vtMType=$($BUSYBOX_PATH/uname -m)
 
     vtlog "######### ventoy_dm_patch ############"
@@ -350,6 +360,15 @@ ventoy_dm_patch() {
     kprobe_unreg_addr=$($GREP ' unregister_kprobe$' /proc/kallsyms | $AWK '{print $1}')
     
     if [ "$VTOY_DEBUG_LEVEL" = "01" ]; then
+        vtDmPatchDebug=1
+    fi
+    
+    if $GREP -q 'dmpatch_debug' /proc/cmdline; then
+        vtDmPatchDebug=1
+    fi
+    
+    
+    if [ $vtDmPatchDebug -eq 1 ]; then
         printk_addr=$($GREP ' printk$' /proc/kallsyms | $AWK '{print $1}')
         if [ -z "$printk_addr" ]; then
             printk_addr=$($GREP ' _printk$' /proc/kallsyms | $AWK '{print $1}')
@@ -384,14 +403,17 @@ ventoy_dm_patch() {
         return
     elif [ -d /lib/modules/$vtKv/kernel/fs ]; then
         vtModPath=$($FIND /lib/modules/$vtKv/kernel/fs/ -name "*.ko*" | $HEAD -n1)
-    else
+    elif [ -d /lib/modules/$vtKv/kernel ]; then
         vtModPath=$($FIND /lib/modules/$vtKv/kernel/ -name "xfs.ko*" | $HEAD -n1)
+    elif [ -d /lib/modules/$vtKv/initrd ]; then
+        vtModPath=$($FIND /lib/modules/$vtKv/initrd/ -name "xfs.ko*" | $HEAD -n1)
     fi
-    
+
+
     if [ -z "$vtModPath" ]; then
-        vtModPath=$($FIND /lib/modules/$vtKv/kernel/ -name "*.ko*" | $HEAD -n1)
+        vtModPath=$($FIND /lib/modules/$vtKv/ -name "*.ko*" | $HEAD -n1)
     fi
-    
+
     vtModName=$($BUSYBOX_PATH/basename $vtModPath)
     
     vtlog "template module is $vtModPath $vtModName"
@@ -405,6 +427,8 @@ ventoy_dm_patch() {
         $BUSYBOX_PATH/xzcat $vtModPath > $VTOY_PATH/$vtModName
     elif echo $vtModPath | $GREP -q "[.]ko[.]gz$"; then
         $BUSYBOX_PATH/zcat $vtModPath > $VTOY_PATH/$vtModName
+    elif echo $vtModPath | $GREP -q "[.]ko[.]zst$"; then
+        $VTOY_PATH/tool/zstdcat $vtModPath > $VTOY_PATH/$vtModName
     else
         vtlog "unsupport module type"
         return
@@ -414,17 +438,21 @@ ventoy_dm_patch() {
     
     #step1: modify vermagic/mod crc/relocation
     vtlog "$VTOY_PATH/tool/vtoykmod -u $VTOY_PATH/tool/$vtKoName $VTOY_PATH/$vtModName $vtDebug"
-    $VTOY_PATH/tool/vtoykmod -u $VTOY_PATH/tool/$vtKoName $VTOY_PATH/$vtModName $vtDebug
+    $VTOY_PATH/tool/vtoykmod -u $VTOY_PATH/tool/$vtKoName $VTOY_PATH/$vtModName $vtDebug >>$VTLOG 2>&1
     
     #step2: fill parameters
     vtPgsize=$($VTOY_PATH/tool/vtoyksym -p)
     vtlog "$VTOY_PATH/tool/vtoykmod -f $VTOY_PATH/tool/$vtKoName $vtPgsize 0x$printk_addr 0x$ro_addr 0x$rw_addr $get_addr $get_size $put_addr $put_size 0x$kprobe_reg_addr 0x$kprobe_unreg_addr $vtKv $vtIBT $vtDebug"
-    $VTOY_PATH/tool/vtoykmod -f $VTOY_PATH/tool/$vtKoName $vtPgsize 0x$printk_addr 0x$ro_addr 0x$rw_addr $get_addr $get_size $put_addr $put_size 0x$kprobe_reg_addr 0x$kprobe_unreg_addr $vtKv $vtIBT $vtDebug
+    $VTOY_PATH/tool/vtoykmod -f $VTOY_PATH/tool/$vtKoName $vtPgsize 0x$printk_addr 0x$ro_addr 0x$rw_addr $get_addr $get_size $put_addr $put_size 0x$kprobe_reg_addr 0x$kprobe_unreg_addr $vtKv $vtIBT $vtDebug >>$VTLOG 2>&1
 
-    $BUSYBOX_PATH/insmod $VTOY_PATH/tool/$vtKoName
+    vtlog "insmod $VTOY_PATH/tool/$vtKoName"
+    $BUSYBOX_PATH/insmod $VTOY_PATH/tool/$vtKoName  >>$VTLOG 2>&1
     
     if $GREP -q 'dm_patch' /proc/modules; then
+        vtlog "dm_patch module OK"
         echo "done" > $VTOY_PATH/dm_patch_done
+    else
+        vtlog "dm_patch module FAILED"
     fi
     
 }
index 48050f6d96da936af2e7460172282ee424947e9f..dc26bf9d5c789395ed8563c9284d42a979b72407 100644 (file)
Binary files a/IMG/cpio_x86/ventoy/tool/dm_patch_64.ko and b/IMG/cpio_x86/ventoy/tool/dm_patch_64.ko differ
index 47fb9b2958cca6f8f02aa3bbd89065d94782aada..a73119ba8f84e8c7dcd5328e05dbaf5ed241453c 100644 (file)
Binary files a/IMG/cpio_x86/ventoy/tool/dm_patch_ibt_64.ko and b/IMG/cpio_x86/ventoy/tool/dm_patch_ibt_64.ko differ
index a1e2ea8d70e81e6cee56c6d1fda435797e04f11a..5cc42a5281d534ca8fc7c23eae624ab6a2846507 100644 (file)
@@ -164,6 +164,13 @@ struct modversion_info {
        char name[64 - sizeof(unsigned long)];
 };
 
+struct modversion_info2 {
+       /* Offset of the next modversion entry in relation to this one. */
+       uint32_t next;
+       uint32_t crc;
+       char name[0];
+};
+
 
 typedef struct ko_param
 {
@@ -294,14 +301,15 @@ static int vtoykmod_find_section32(char *buf, char *section, int *offset, int *l
     return 1;
 }
 
-static int vtoykmod_update_modcrc(char *oldmodver, int oldcnt, char *newmodver, int newcnt)
+static int vtoykmod_update_modcrc1(char *oldmodver, int oldcnt, char *newmodver, int newcnt)
 {
     int i, j;
     struct modversion_info *pold, *pnew;
-    
+
     pold = (struct modversion_info *)oldmodver;
     pnew = (struct modversion_info *)newmodver;
 
+    debug("module update modver format 1\n");
     for (i = 0; i < oldcnt; i++)
     {
         for (j = 0; j < newcnt; j++)
@@ -318,6 +326,51 @@ static int vtoykmod_update_modcrc(char *oldmodver, int oldcnt, char *newmodver,
     return 0;
 }
 
+
+static int vtoykmod_update_modcrc2(char *oldmodver, int oldlen, char *newmodver, int newlen)
+{
+    struct modversion_info2 *pold, *pnew, *pnewend;
+
+    pold = (struct modversion_info2 *)oldmodver;
+    pnew = (struct modversion_info2 *)newmodver;
+    pnewend = (struct modversion_info2 *)(newmodver + newlen);
+
+    debug("module update modver format 2\n");
+    /* here we think that there is only module_layout in oldmodver */
+
+    for (; pnew < pnewend && pnew->next; pnew = (struct modversion_info2 *)((char *)pnew + pnew->next))
+    {
+           if (strcmp(pnew->name, "module_layout") == 0)
+        {
+            debug("CRC  0x%08x --> 0x%08x  %s\n", pold->crc, pnew->crc, pnew->name);
+            memset(pold, 0, oldlen);
+            pold->next = 0x18;  /* 8 + module_layout align 8 */
+            pold->crc = pnew->crc;
+            strcpy(pold->name, pnew->name);
+            break;
+        }
+    }
+
+    return 0;
+}
+
+
+static int vtoykmod_update_modcrc(char *oldmodver, int oldlen, char *newmodver, int newlen)
+{
+    uint32_t uiCrc = 0;
+
+    memcpy(&uiCrc, newmodver + 4, 4);
+
+    if (uiCrc > 0)
+    {
+        return vtoykmod_update_modcrc2(oldmodver, oldlen, newmodver, newlen);
+    }
+    else
+    {
+        return vtoykmod_update_modcrc1(oldmodver, oldlen / 64, newmodver, newlen / 64);
+    }
+}
+
 static int vtoykmod_update_vermagic(char *oldbuf, int oldsize, char *newbuf, int newsize, int *modver)
 {
     int i = 0;
@@ -393,7 +446,7 @@ int vtoykmod_update(char *oldko, char *newko)
 
         if (rc == 0)
         {
-            vtoykmod_update_modcrc(oldbuf + oldoff, oldlen / 64, newbuf + newoff, newlen / 64);
+            vtoykmod_update_modcrc(oldbuf + oldoff, oldlen, newbuf + newoff, newlen);
         }
     }
     else
index 556f11bd494e3c20fe99430b6cded53a9e8b967a..cca95539aceca355b1670e02ff809aa15574014b 100644 (file)
Binary files a/VtoyTool/vtoytool/00/vtoytool_32 and b/VtoyTool/vtoytool/00/vtoytool_32 differ
index 45edfacd02d89b0443c90a4ea3343d41674d3b3e..950f532250067696b60bcdb55c3c5634e0a10a9b 100644 (file)
Binary files a/VtoyTool/vtoytool/00/vtoytool_64 and b/VtoyTool/vtoytool/00/vtoytool_64 differ
index 2546cb936de4faceaf0c7eef5ba5faea8c93a7ac..5bc9fad31e97a34f3987ee91f244b5809b964c54 100644 (file)
Binary files a/VtoyTool/vtoytool/00/vtoytool_aa64 and b/VtoyTool/vtoytool/00/vtoytool_aa64 differ
index 6a1283eeff3e5ae2a379a70960ae790a7effa98d..bac502a1961468a58660b77111d8b53ce215c93b 100644 (file)
Binary files a/VtoyTool/vtoytool/00/vtoytool_m64e and b/VtoyTool/vtoytool/00/vtoytool_m64e differ