Commit Graph

403 Commits

Author SHA1 Message Date
Yonghua Huang
3348723805 dm: fix fault Injection into VirtIO console backend
CVE# CVE-2021-23905
 Add Null pointer check in init vq ring and add vq ring descriptor
 check in case cause Nullpointer exception.

Tracked-On: #5355
Signed-off-by: Liu Long <long.liu@intel.com>
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Wang, Yu1 <yu1.wang@intel.com>
2021-07-02 14:39:04 +08:00
Yonghua Huang
e09ecb13eb virtio: add virtio callbacks check
CVE# CVE-2021-23904
We can only call these callbacks when they are not NULL.

Tracked-On: #5342

Signed-off-by: Jie Deng <jie.deng@intel.com>
Signed-off-by: Yonghua Huang<yonghua.huang@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2021-07-02 14:39:04 +08:00
Jie Deng
d74f25fde4 dm: virtio_console: read only when the virtqueue is ready.
CVE# CVE-2021-23902
The read should not continue if the virtqueue is not ready.

Tracked-On: #5544
Signed-off-by: Jie Deng <jie.deng@intel.com>
2021-07-02 14:39:04 +08:00
Yonghua Huang
9d29f5ff69 dm: validate inputs in vq_endchains
inputs shall be validated to avoid NULL pointer access.

Tracked-On: #6129
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2021-07-02 10:33:37 +08:00
Yonghua Huang
ea76e59d77 DM: xHCI: Check trb pointer before use it
The trb pointer may be NULL when get the address from user space, add
the pointer check before use the trb.

Tracked-On: #6172
Signed-off-by: Liu Long <long.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2021-07-02 10:33:37 +08:00
Yonghua Huang
2b91780b4e dm: Reset virtio device before release
With virtio polling mode enabled, a timer is running in the virtio
backend service. And the timer will also be triggered if its frondend
driver didn't do the device reset in shutdown. A freed virtio device
will be accessed in the polling timer handler.

Do the virtio reset() callback specifically to clear the polling timer
before the free.

Tracked-On: #6147
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2021-07-02 10:33:37 +08:00
Jie Deng
2e08f32e7a dm: NULL check of vq->used in virtio_net_ping_rxq
Add a check on this place to avoid NULL access issue.

Tracked-On: #6100
Signed-off-by: Jie Deng <jie.deng@intel.com>
2021-07-02 10:33:37 +08:00
Gao Junhao
87a8cd50d7 dm: refine the check of return value of snprintf
int snprintf(char *str, size_t size, const char *format, ...)
The functions snprintf() write at most size bytes (including the
terminating null byte('\0')) to str.
only when returned value of snprintf is non-negative and less than size,
the string has been completely written.

Tracked-On: #4109
Signed-off-by: Gao Junhao <junhao.gao@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-11-18 10:39:23 +08:00
Yonghua Huang
e6e9f4da68 dm: fix mutex lock issue in tpm_rbc.c
In function crb_reg_write() in tpm_rbc.c
 'tpm_vdev->request_mutex' will potentially kept
 in locked state after crb_reg_write() returns.

Tracked-On: #4108
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Yadong Qi <yadong.qi@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-11-18 10:39:23 +08:00
Gao Junhao
48bcd98ec6 dm: modify DIR handler reference postion
DIR handler is referenced after release, need to be adjusted before
released.

Tracked-On: #4106
Signed-off-by: Gao Junhao <junhao.gao@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-11-18 10:39:23 +08:00
Junhao Gao
cf31b41f8b dm: reduce potential crash caused by LIST_FOREACH
When removing node in list, list_foreach_safe will be safer than
LIST_FOREACH.

Tracked-On: #4104
Signed-off-by: Junhao Gao <junhao.gao@intel.com>
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-11-18 10:39:23 +08:00
Yonghua Huang
cf6ba23fd9 dm: validate the input in 'pci_emul_mem_handler()'
checking the inputs explicitly instead of using Assert.

Tracked-On: #3991
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Shuo Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-11-06 16:33:11 +08:00
Tianhua Sun
de125e6c6f dm: fix variable argument list read without ending with va_end
va_end() was not getting called under certain condition
after the va_start() function call taking the va_list.

Tracked-On: #3406
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
2019-07-18 15:18:29 +08:00
Tianhua Sun
21083ee09c dm: fix some possible memory leak
free memory allocated by strdup()

Tracked-On: #3405
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
2019-07-18 15:18:29 +08:00
Tianhua Sun
835605855e dm: fix some potential memory leaks
This patch is to fix some potential memory leak issues

1, free mrp if the mmio_rb_lookup() function return 0;
2, free memory allocated by strdup in some error case handling.

Tracked-On: #3333
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2019-07-05 15:15:35 +08:00
Tianhua Sun
e7cfd9c561 dm: fix strncpy null-terminated issues
Fix strncpy null-terminated issues.

Tracked-On: #3332
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2019-07-05 15:15:35 +08:00
Yin Fengwei
f2d654cc44 signal SIGINT: map SIGINT to watchdog reset
Map SIGINT(2) to watchdog reset.
NOTE:
We required guest to do a full reset after detect the recent last
reset type is watchdog. This is used to resume the passthru devices
in UOS.

Tracked-On: #3103
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
2019-05-15 16:20:24 +08:00
Yin Fengwei
634e310f9b build: fix build issue with latest gcc
Fix build issues with gcc 9.1 version

Tracked-On: #3121
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
2019-05-15 15:51:20 +08:00
Wei Liu
57ac00a61f acrn-dm: enable debug option for acrn-dm
enable acrn-dm debug option via RELEASE=0(by default)

Tracked-On: #2939
Reviewed-by: Minggui Cao <minggui.cao@intel.com>
Signed-off-by: Wei Liu <weix.w.liu@intel.com>
2019-04-19 11:14:33 +08:00
Xiaoguang Wu
8f32193d99 DM USB: xHCI: refine the failure process logic of control transfer
The old logic to process control transfer failure is not complete, this
patch is used to fix this issue.

Tracked-On: #2824
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-03-20 11:57:51 +08:00
Xiaoguang Wu
7c79f50752 DM USB: xHCI: workaround for libusb timing issue
On some platforms, the VBus will drop after suspending is done, hence
a disconnect and re-connect for device connected before suspending will
be triggered in DM. But during the stress test, when the free memory is
limited to very low level, and put huge workload to SOS, under certain
possibility, the DM will receive re-connect event first and disconnect
event later, this behavior will result of failing to emulate USB device
to UOS.

The reason is due to a timing issue from libusb. Before we could upstream
fixing patch to libusb or find some other better solution, this workaround
patch will be used to avoid errors happen.

Tracked-On: #2823
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-03-20 11:57:51 +08:00
Xiaoguang Wu
66dabd1260 DM USB: xHCI: fix an synchronization issue during resuming process
When disable slot cmd is received by device model, the operation
should be: release the pci_xhci_dev_emu variable first, and signal
xhci_vbdp_thread to wakeup later. Tho old implementation is not
right, this patch is used to fix it.

Tracked-On: #2823
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-03-20 11:57:51 +08:00
Xiaoguang Wu
3593135673 DM USB: xHCI: Fix CTS test failure
This patch fixes the failure of CTS 'USB Device Test' itme.

Tracked-On: #2800
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-03-18 13:30:36 +08:00
Xiaoguang Wu
c6efc67c20 DM USB: xHCI: fix issue of discarding zero sized BULK transfer
Should not disacard zero-size bulk transfer.

Tracked-On: #2800
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-03-18 13:30:36 +08:00
Conghui Chen
2171b6d2b9 dm: usb: fix possible memory leak
fix possible memory leak for usb.

Tracked-On: #2705
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
2019-03-13 10:17:20 +08:00
Jie Deng
d585389554 dm: virtio-net: fix memory leak
Dynamic memory stored in 'net' allocated through function 'calloc'
should be freed correspondingly when return fail.

Tracked-On: #2704
Signed-off-by: Jie Deng <jie.deng@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
2019-03-12 10:22:05 +08:00
Xiaoguang Wu
b8017080b3 DM USB: xHCI: fix an logic error during USB reset
Should not set hci_address to zero during USB reset.

Tracked-On: #2633
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-03-11 11:34:32 +08:00
Binbin Wu
8cd892a4f0 dm: passthru: fix potential memory leak
Fix potential memory leakage in some error case handling.

Tracked-On: #2705
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
2019-03-11 10:11:11 +08:00
Huang Yang
1a59fa26fe DM: Attestation Keybox support in SOS DM
Retrieve the encrypted attestation Keybox from CSE
and provision it to RPMB storage.

Tracked-On: #2625
Signed-off-by: Huang Yang <yang.huang@intel.com>
Signed-off-by: Wei Xinghai <xinghaix.wei@intel.com>
Signed-off-by: Chen Gang <gang.g.chen@intel.com>
Acked-by: Zhu Bing <bing.zhu@intel.com>
2019-02-27 10:00:12 +08:00
Conghui Chen
0066171468 dm: virtio: add memory barrier before notify FE
Without memory barrier, the change of used ring index could not
immediately detected by FE, this would bring some problems.

For virtio-blk FE driver, when it receives an interrupt, and confirms the
used ring index has changed, it will first set ring flags with
VRING_AVAIL_F_NO_INTERRUPT, then get buffer from virtqueue, after
process this request, it will mask VRING_AVAIL_F_NO_INTERRUPT, and get
used ring index again before return. If used ring changes, it will
process it. At the same time, BE will read this flags before each notify,
if VRING_AVAIL_F_NO_INTERRUPT was set, BE will not inject interrupt.

Without memory barrier, before FE mask VRING_AVAIL_F_NO_INTERRUPT, BE
has finished notify without interrupt, then FE mask
VRING_AVAIL_F_NO_INTERRUPT, and get used ring index but failed (index
has changed from BE side). FE will return from interrupt handler
function, and wait for next interrupt which was not injected by BE. Thus,
this will cause kernel hung.

Tracked-On: #2628
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
2019-02-27 09:54:57 +08:00
Xiaoguang Wu
ecedf31bd1 DM USB: xHCI: delay 2s for enumeration in resuming process
During UOS S3 resume, the UOS will handle USB disconnect flow then
re-enumeration flow due to vbus drop be emulted for UOS S3 case. The
re-enumeration flow will impact UOS S3 resume latency, this patch
delayed the re-enumeration 2s as the workaround for this issue. Need to
do performance optimization in future.

This 2s can be tune which is depend on how fast UOS S3 resume, it should
be as short as possible to make virtual USB device ready immediately
after UOS screen turn on.

Tracked-On: #2576
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-25 16:43:18 +08:00
Xiaoguang Wu
9844ff0266 DM USB: xHCI: re-design the S3 logic to speed up resuming process
This patch unbinds the kernel driver usbfs with device before suspending
is completed and binds them again during resuming process, this could
avoid a busy loop in SOS due to VBUS drop. This patch could save ~200ms
for resuming process.

Tracked-On: #2576
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-25 16:43:18 +08:00
Xiaoguang Wu
b77755cd58 DM USB: xHCI: refine the de-init logic of xHCI vdevice
Add 'full' and 'non-full' de-initialize support for xHCI virtual
device. The non-full de-initialization mainly release usb_dev
structure and unbind the usbfs with native device. And the full
de-initialize will release all the resources allocated for xHCI
virtual device including the unbinding operation mentioned above

Tracked-On: #2576
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-25 16:43:18 +08:00
Xiaoguang Wu
76a5131b37 DM USB: xHCI: fix PORTSC error in 'pci_xhci_cmd_disable_slot'
The disable slot command is used for forcing a device slot to enter into
disconnect state, a typical usage would be to free a Device Slot when an
USB device is disconnected. But it should not impact the portsc value.

Tracked-On: #2576
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-25 16:43:18 +08:00
Xiaoguang Wu
c9d85cfaea DM USB: xHCI: fix a logic error in 'pci_xhci_portregs_write'
The function 'pci_xhci_portregs_write' always set CCS bit in
Port Status and Control (PORTSC) register when there is
pci_xhci_dev_emu instance existed. This is not right and this
patch is used to fix it.

Tracked-On: #2576
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-25 16:43:18 +08:00
Xiaoguang Wu
5f36580190 DM USB: xHCI: introduce get/set function for PORTSC register
Port Status and Control (PORTSC) register is one of the most frequently
accessed regiseter according the xHCI spec. This patch implement a pair
of set/get function to access PORTS and it gives a clear code structure
and help a lot for debugging work.

Tracked-On: #2576
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-25 16:43:18 +08:00
Xiaoguang Wu
be7b034763 DM USB: xHCI: fix an issue during BULK transfer
When LINK type TRB are received among multiple BULK TRBs, the copying
logic in DM will miss one or more TRBs. This patch is used to fix it.

Tracked-On: #2581
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-22 13:48:21 +08:00
Xiaoguang Wu
7aabea6b06 DM USB: xHCI: fix an error logic in DRD logic
The patch (commit id: b39524e) didn't achieve its purpose completely.
This patch is used to fix it.

Tracked-On: #2557
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-22 13:48:10 +08:00
Minggui Cao
d251afa8f3 DM: modify acpi for IASL to support ACPI6.3
patch is from Alex Du for IASL tool updated to support
ACPI 6.3 version.

Tracked-On: #2565
Signed-off-by: Alek Du <alek.du@intel.com>
Signed-off-by: Minggui Cao <minggui.cao@intel.com>
2019-02-20 14:18:33 +08:00
Yu Wang
b39524e989 DM USB: xHCI: do not reset DRD role during S3 process
To reset USB DRD role is one workaround for adb lost issue with xDCI
passthrough which reproduced in S3 stress test.

This workaround will involve the system global reset if xDCI working in
SuperSpeed mode. This is maybe caused by PMC firmware can't graceful
power gate the xDCI during S3 suspend. The current USB DRD driver will
set STATIC switch bits which will cause ungraceful DRD switch, it may
make the xDCI enter a unknown state, then involved this global reset
issue.

BTW, base on latest code base, the adb lost issue can't reproduce even
remove this workaround. So remove the old workaround for above reasons.

Tracked-On: #2557
Signed-off-by: Yu Wang <yu1.wang@intel.com>
Reviewed-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
Signed-off-by: Yu Wang <yu1.wang@intel.com>
2019-02-19 13:53:11 +08:00
Conghui Chen
a82cafe92d dm: storage: change DISCARD to synchronous mode
For virtio-blk, when the backend is a regular file, the discard
and
is implemented by fallocate(), but this function will not wait for
the discard command handled by disk.
So, add fdatasync to make sure the DISCARD is executed
synchronously.

Tracked-On: #2547
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Wang Yu <yu1.wang@intel.com>
2019-02-18 18:28:55 +08:00
Conghui Chen
b595abcc23 dm: storage: support discard command
Support DISCARD command is meaningful when eMMC usage is high or
there are lots of remove operations. For example, when Guest
Android is running, there will be lots of files being created and
removed. However, virtio-blk BE does not support DISCARD command,
data remove operation in UOS will not trigger erase in eMMC. After
period of time, the eMMC will be consumed out, and erase must be
done by eMMC firmware before writing any new data. This causes the
eMMC performance decrease in the whole system (SOS and UOS).
To solve the problem, DISCARD should be supported in virtio-blk BE.

Tracked-On: #2547
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-18 18:28:55 +08:00
Conghui Chen
c96e33ca64 dm: storage: rename delete to discard
To keep consistent with kernal code, change delete to discard.

Tracked-On: #2547
Signed-off-by: Conghui Chen <conghui.chen@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-02-18 18:28:55 +08:00
Yin Fengwei
135ed80f51 watchdog: map the watchdog reset to warm reset
Per debugging requirement, map the watchdog reset to warm reset.
So the ramconsole could be used to capture the kernel log of UOS
before watchdog is hit.

Tracked-On: #2471
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
2019-02-01 11:41:51 +08:00
Yin Fengwei
928dfefc62 dm: add log for debuging pci while vm reset
Print some log to dmesg when init/deinit vdev.

Tracked-On: #2419
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
2019-01-25 13:56:46 +08:00
Binbin Wu
80c394a86a dm: passthru: increase the delay after wifi reset
Increase the delay to 200ms after wifi reset for link training done.

Tracked-On: #2328
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
2019-01-16 13:06:21 +08:00
Xiaoguang Wu
83279f8573 DM USB: xHCI: WA for an isochronous crash issue
The current xHCI mediator doesn't well support disable endpoint command.
This patch is one workaround for disable endpoint command to avoid
xHCI mediator to continue handle already dropped data.

Tracked-On: #2325
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-01-14 13:27:57 +08:00
Xiaoguang Wu
79b145f89f DM USB: xHCI: WA for the 'lost adb' issue.
This patch is one xDCI passthrough workaround. To support DRD in Guest,
the xDCI does VT-d pass through, and DRD be emulated in xHCI mediator.
With Guest S3 stress test, ramdonly the xDCI can't be emuerated by USB
host even the DRD is already switch to device mode. When this issue
reproduce, does DRD switch to host then switch back can resuce this
issue.

Besides, the virtual drd regiters need to be set to reset value during
Guest warm reset flow.

Tracked-On: #2326
Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>y
2019-01-14 13:27:37 +08:00
Binbin Wu
a4014db275 dm: passthru: reset wifi chip via gpio
During UOS reboot, sometime the wifi firmware status is wrong and can't
handled by UOS driver, this patch add gpio reset for the wifi chip to avoid
such error.

Tracked-On: #2328
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
2019-01-14 12:47:53 +08:00
Yuan Liu
8b9100b15d IOC mediator: fix the issue of abnormally missing tx package
The issue will result in the loss of wakeup reason and signal
data, because the CBC header was not added when generating the
tx package.

Tracked-On: #2282
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2019-01-11 13:06:30 +08:00