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

logging: rpc: fix overwriting of buffer's header #20032

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kderda
Copy link
Contributor

@kderda kderda commented Jan 22, 2025

This commit fixes an issue where a header of a MPSC buffer was overwritten by log's header causing a log be falsely claimed.

@kderda kderda requested a review from a team as a code owner January 22, 2025 13:03
@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Jan 22, 2025
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Jan 22, 2025

CI Information

To view the history of this post, clich the 'edited' button above
Build number: 2

Inputs:

Sources:

sdk-nrf: PR head: b571a6ea9ecf4d0c0ca54dacadb51c657c4e3825

more details

sdk-nrf:

PR head: b571a6ea9ecf4d0c0ca54dacadb51c657c4e3825
merge base: 1c36f9c6163f8b4f2b8d94693243b78da5465fdd
target head (main): 47c18832e293d6f3e11b91c753ce436e62a46265
Diff

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (1)
subsys
│  ├── logging
│  │  │ log_backend_rpc_history_ram.c

Outputs:

Toolchain

Version: 342151af73
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:342151af73_912848a074

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ✅ Build twister
    • sdk-nrf test count: 38
  • ✅ Integration tests
Disabled integration tests
    • desktop52_verification
    • doc-internal
    • test_ble_nrf_config
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_mesh
    • test-fw-nrfconnect-ble_samples
    • test-fw-nrfconnect-boot
    • test-fw-nrfconnect-chip
    • test-fw-nrfconnect-fem
    • test-fw-nrfconnect-nfc
    • test-fw-nrfconnect-nrf-iot_libmodem-nrf
    • test-fw-nrfconnect-nrf-iot_lwm2m
    • test-fw-nrfconnect-nrf-iot_mosh
    • test-fw-nrfconnect-nrf-iot_positioning
    • test-fw-nrfconnect-nrf-iot_samples
    • test-fw-nrfconnect-nrf-iot_serial_lte_modem
    • test-fw-nrfconnect-nrf-iot_thingy91
    • test-fw-nrfconnect-nrf-iot_zephyr_lwm2m
    • test-fw-nrfconnect-nrf_crypto
    • test-fw-nrfconnect-ps
    • test-fw-nrfconnect-rpc
    • test-fw-nrfconnect-rs
    • test-fw-nrfconnect-tfm
    • test-fw-nrfconnect-thread
    • test-fw-nrfconnect-zigbee
    • test-low-level
    • test-sdk-audio
    • test-sdk-dfu
    • test-sdk-find-my
    • test-sdk-mcuboot
    • test-sdk-pmic-samples
    • test-sdk-sidewalk
    • test-sdk-wifi
    • test-secdom-samples-public

Note: This message is automatically posted and updated by the CI

This commit fixes an issue where a header of a MPSC buffer was
overwritten by log's header causing a log be falsely claimed.

Signed-off-by: Konrad Derda <[email protected]>
@kderda kderda force-pushed the fix_rpc_log_history branch from 7686057 to b571a6e Compare January 22, 2025 13:59
Copy link
Contributor

@Damian-Nordic Damian-Nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, a few readability/maintainability suggestions but LGTM otherwise

@@ -14,6 +14,40 @@
static uint32_t __aligned(Z_LOG_MSG_ALIGNMENT) log_history_raw[HISTORY_WLEN];
static struct mpsc_pbuf_buffer log_history_pbuf;

static bool copy_to_pbuffer(const union log_msg_generic *msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to extract this to a separate function if it's used in only one function that does only this? This way it's harder to figure out that the actual change is copying everything without the first two bits :)

uint8_t *src_data;
size_t hdr_wlen;

wlen = log_msg_generic_get_wlen((union mpsc_pbuf_generic *)msg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wlen = log_msg_generic_get_wlen((union mpsc_pbuf_generic *)msg);
wlen = log_msg_generic_get_wlen(&msg->buf);

To avoid unsafe casts if not needed.

Comment on lines +37 to +44
hdr_wlen = DIV_ROUND_UP(sizeof(struct mpsc_pbuf_hdr), sizeof(uint32_t));

if (wlen <= hdr_wlen) {
return false;
}

dst->hdr.data = msg->buf.hdr.data;
memcpy(dst_data, src_data, (wlen - hdr_wlen) * sizeof(uint32_t));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the rounding up was actually needed, this code would be incorrect as it would copy too few bytes. Suggest a bit more assumption-less code:

Suggested change
hdr_wlen = DIV_ROUND_UP(sizeof(struct mpsc_pbuf_hdr), sizeof(uint32_t));
if (wlen <= hdr_wlen) {
return false;
}
dst->hdr.data = msg->buf.hdr.data;
memcpy(dst_data, src_data, (wlen - hdr_wlen) * sizeof(uint32_t));
if (wlen * sizeof(uint32_t) <= sizeof(struct mpsc_pbuf_hdr)) {
return false;
}
dst->hdr.data = msg->buf.hdr.data;
memcpy(dst_data, src_data, wlen * sizeof(uint32_t) - sizeof(struct mpsc_pbuf_hdr));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants