cloudlinux / libcare

libcare -- Patch Userspace Code in Live Processes
GNU General Public License v2.0
145 stars 57 forks source link

Read error when apply QEMU patch #51

Open yaozhenguo opened 4 years ago

yaozhenguo commented 4 years ago

I made QEMU patch by libcare-patch-make successfully. But After apply patch for QEMU, following error logs are reported

Copying 0x5 bytes from 0x4ceda0 to 0x555555db2240 in target... FAIL kpatch_patch.c(495): Patching qemu-system-x86_64 failed, unapplying partially applied patch Verifying safety for pid 32695...

I have checked kpatch_process_mem_read return is 5(I/O error) and patch info->daddr is 0x4ceda0. But qemu-system-x86_64 text section is as below

Object 'qemu-system-x86_64' (806:643262840), patch: yes VM areas: inmem: 555555554000-555555d5461c r-e, ondisk: 00000000-0080061c r-e inmem: 555555f54d80-55555610c000 r--, ondisk: 00800d80-009b8000 r-- inmem: 55555610c000-5555565b4300 rw-, ondisk: 009b8000-00a16b28 rw-

0x4ceda0 (info->daddr) is invalid in qemu‘s process,Does it need add some offset to info->daddr when reading it? Or, is there something wrong when making patch but logs are not reported?

yaozhenguo commented 4 years ago

I notice that qemu-system-x86_64 is built with PIE enabled. I disabled PIE, patch is successful.

yaozhenguo commented 4 years ago

It works when PIE enabled. when c++ is installed. qemu uses c++ as linker. this lead to libcare-cc wrapper can't add -Wl,-q flags to linker. Relocations of the patch is dropped after linking. Removing c++ and then it works.

coryee commented 4 years ago

Hi @yaozhenguo, Can you please tell me how to make QEMU patch? I've tried it in the same way as sample SERVER does, but there is no kpatch info found in the patched qemu-system-xxx using "eu-readelf -S" which cause no patch file generated.

Are there any modifications should be made to qemu makefile?

loyfan commented 3 years ago

@coryee check if #52 solves your problem.

coryee commented 3 years ago

@loyfan Thanks a lot

I found that the commit 9edc19c(make: switch from -I to -iquote) of the qemu changed the compile options