Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propose new KVM driver based on KVMi subsystem #844

Merged
merged 252 commits into from
Jul 30, 2020
Merged

Conversation

mtarral
Copy link
Contributor

@mtarral mtarral commented Dec 5, 2019

This PR proposes a brand new KVM driver, based on the experimental KVMi subsystem currently being developed by BitDefender.

The driver's code has been splitted:

  • kvm_legacy.c: legacy kvm driver (GDB and qemu memaccess patch)
  • kvm.c the new driver based in KVMi
  • kvm_common.c: common functions share by both drivers.

This PR also changes some of the examples to include a new kvmi_socket optional parameter.

cc @tklengyel , @adlazar, @mdontu

Fixes #827 , #778

adlazar and others added 30 commits August 24, 2019 21:04
Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
This will enable querying all the registers in one step.
Implement a new KVM driver specific MSR translation.

This reverts commit f75a73c.
This is still quite experimental. To be more specific, I think kvm_set_vcpureg
is likely to be broken. The reason for this is that the kernel only supports
setting all the registers at once and for us to be able to set only a single
register we need to retrieve the old values first. Of course, both of these
operations need to be done without the vcpu continuing execution while the
operations are happening. Maybe we should explicitly pause the vcpu before the
operations.
Apparently I had broken the kvm.h header when picking chunks for the previous
commit. Sorry for that.
kvmi_uninit was called twice leading to a double free bug if unix socket
connection errored. This fixes the problem by manually setting the kvmi pointer
to NULL as kvmi_uninit checks for that.
This replaces the hard coded /var/run/testing.sock path with a configurable option.
This commit removes all the other access methods from the kvm driver and only
leaves the new kvmi based one. Now `--enable-kvm` implies kvmi.
Kernel API
----------
Noteworthy changes
  - different values for KVMI_EVENT_* (we have KVMI_EVENT_X and KVMI_EVENT_X_FLAG)
  - kvmi_event_page_fault renamed to kvmi_event_pf + a new member (shadow_gs)
  - KVMI_PAUSE_ALL_VCPUS command replaced KVMI_PAUSE_VCPU
  - kvmi_event_reply has a new member (the event id)
  - kvmi_get_guest_info_reply extended the vcpu_count member to u32

New
  - two new VM events: KVMI_EVENT_CREATE_VCPU and KVMI_EVENT_UNHOOK

Library API
-----------
Noteworthy changes
  - the structures exchanged during handshake changed
  - kvmi_domain_close() has a second parameter (to shutdown the socket)
  - the events received while waiting a command' reply are saved for later processing (kvmi_pop_event)
  - the event callback has been removed; the events should be accesed with kvmi_wait_event()+kvmi_pop_event()

New
  - a handshake callback can be supplied to kvmi_init_* functions
  - a logging callback can be set (kvmi_set_log_cb) to receive debug/info/warning/error messages from libkvmi
  - reads and writes have a 15 seconds timeout
  - all commands (send+recv) and event replies (send) are synchronized with a mutex

Signed-off-by: Mihai Donțu <mdontu@bitdefender.com>
Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
Signed-off-by: Nicușor Cîțu <ncitu@bitdefender.com>
Signed-off-by: Mircea Cîrjaliu <mcirjaliu@bitdefender.com>
The libkvmi API (RFC v5) changed two functions used by this driver:
  - kvmi_init_unix_socket()
  - kvmi_domain_close()

Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
In order to silence:

    warning: implicit declaration of function ‘vasprintf’ [-Wimplicit-function-declaration]

Signed-off-by: Adalbert Lazăr <alazar@bitdefender.com>
@Wenzel
Copy link
Member

Wenzel commented Jul 28, 2020

@tklengyel can you trigger the jenkins also ?
thanks

@tklengyel
Copy link
Contributor

@drakvuf-jenkins retest this please

.travis.yml Outdated Show resolved Hide resolved
@tklengyel
Copy link
Contributor

tklengyel commented Jul 28, 2020

This is looking good to me, I only spotted some minor things that really aren't blockers. Lots of kudos @mtarral for getting this done! 🥇 🥳

@Wenzel
Copy link
Member

Wenzel commented Jul 29, 2020

@tklengyel thanks for you review, I've just fixed the minor issues you have found.
Are we waiting for @smaresca's approval also ?

I'm excited to bring this new driver to the LibVMI community !

@smaresca
Copy link
Member

smaresca commented Jul 29, 2020

@tklengyel thanks for you review, I've just fixed the minor issues you have found.
Are we waiting for @smaresca's approval also ?

@Wenzel Thank you for addressing my license and header-related concerns. There are a few remaining Sandia references in libvmi/driver/kvm files though that need attention.

@Wenzel
Copy link
Member

Wenzel commented Jul 29, 2020

According to @tklengyel's comment: #844 (comment)
I thought I needed to remove the Sandia license only in new code/new files.
(therefore I should also remove the license in kvm_common.c and kvm_legacy.c)
is that what you meant @smaresca ?

or did you mean that since the files have changed so much, the Sandia license wasn't applying anymore ?

@smaresca
Copy link
Member

smaresca commented Jul 29, 2020

According to @tklengyel's comment: #844 (comment)
I thought I needed to remove the Sandia license only in new code/new files.
(therefore I should also remove the license in kvm_common.c and kvm_legacy.c)
is that what you meant @smaresca ?

@Wenzel Ah, disregard my comment about the other Sandia lines. The notices I cited do indeed need to stay in place.

README.rst Show resolved Hide resolved
@smaresca
Copy link
Member

Echoing Tamas: I'm very happy to see this come to fruition. Thanks to all Mathieu especially but also to the substantial set of reviewers/contributors we've had on this one.

@Wenzel
Copy link
Member

Wenzel commented Jul 30, 2020

Thanks @smaresca :) 👌
Shall we merge then ? no more blockers ?

@tklengyel tklengyel merged commit aeb8d1d into libvmi:master Jul 30, 2020
@Wenzel Wenzel deleted the kvmi branch August 1, 2020 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration of the new KVM driver based on KVMi APIs