#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"
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)
{
cnt++;
}
}
- else
+ else if (style == 2)
{
if (CODE_MATCH2(opCode, i) && cnt < MAX_PATCH)
{
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);
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)
{
-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
#!/bin/bash
-FTPIP=168.0.0.209
+FTPIP=192.168.44.1
FTPUSR='a:a'
rm -f dmpatch.c Makefile Makefile_IBT
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 -
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 -
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
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
}
ventoy_dm_patch() {
+ vtDmPatchDebug=0
vtMType=$($BUSYBOX_PATH/uname -m)
vtlog "######### 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}')
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"
$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
#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
}
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
{
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++)
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;
if (rc == 0)
{
- vtoykmod_update_modcrc(oldbuf + oldoff, oldlen / 64, newbuf + newoff, newlen / 64);
+ vtoykmod_update_modcrc(oldbuf + oldoff, oldlen, newbuf + newoff, newlen);
}
}
else