mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-12-08 05:04:04 +00:00
hv: add max_len for sbuf_put param
sbuf_put copies sbuf->ele_size of data, and puts into ring. Currently this function assumes that data size from caller is no less than sbuf->ele_size. But as sbuf->ele_size is usually setup by some sources outside of the HV (e.g., the service VM), it is not meant to be trusted. So caller should provide the max length of the data for safety reason. sbuf_put() will return UINT32_MAX if max_len of data is less than element size. Additionally, a helper function sbuf_put_many() is added for putting multiple entries. Tracked-On: #8547 Signed-off-by: Wu Zhou <wu.zhou@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
@@ -91,18 +91,14 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
|
||||
|
||||
/* Check whether output to memory */
|
||||
if (do_mem_log) {
|
||||
uint32_t i, msg_len;
|
||||
uint32_t msg_len;
|
||||
struct shared_buf *sbuf = per_cpu(sbuf, pcpu_id)[ACRN_HVLOG];
|
||||
|
||||
/* If sbuf is not ready, we just drop the massage */
|
||||
if (sbuf != NULL) {
|
||||
msg_len = strnlen_s(buffer, LOG_MESSAGE_MAX_SIZE);
|
||||
|
||||
for (i = 0U; i < (((msg_len - 1U) / LOG_ENTRY_SIZE) + 1U);
|
||||
i++) {
|
||||
(void)sbuf_put(sbuf, (uint8_t *)buffer +
|
||||
(i * LOG_ENTRY_SIZE));
|
||||
}
|
||||
(void)sbuf_put_many(sbuf, LOG_ENTRY_SIZE, (uint8_t *)buffer,
|
||||
LOG_ENTRY_SIZE * (((msg_len - 1U) / LOG_ENTRY_SIZE) + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user