-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
net: buf: Pre-initialize user_data
on net_buf_alloc()
#77088
Comments
proposed by @sjanc here: https://discord.com/channels/720317445772017664/733036837576376341/1273296703868633241 Due to me breaking |
Disclaimer: Not claiming that we need to do a major refactor or significantly modify our API My thoughts about In that train of thought it should perhaps have been I'm not opposed to applying a patch to prevent issue and keep on with the current API, as I believe is suggested here |
note: this is affecting multiple bluetooth qualification tests (I'd consider reverting check for time being) |
Ah okay. Then you see, the stack's way of thinking is the opposite (for which I made the check). It used In the previous meeting, @jhedberg showed us the linux kernel's skbuff, which was the inspiration for net_buf in Zephyr. It specifically says the user_data is the allocator's and definitely not intended for passing data between layers. We mostly use user_data for passing data between layers for in the Bluetooth stack. So maybe we need to change that and not use user_data at all. |
When user_data is not zeroed-out, the API returns an error. Downgrade the API error to a warning log instead. Introducing this check (zephyrproject-rtos#76489) broke a few PTS tests, as user_data is not initialized by `net_buf_alloc()`. Doing so is in discussion: zephyrproject-rtos#77088 Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Made a PR to downgrade to a warning: #77113 |
Bluetooth WG:
|
When user_data is not zeroed-out, the API returns an error. Downgrade the API error to a warning log instead. Introducing this check (#76489) broke a few PTS tests, as user_data is not initialized by `net_buf_alloc()`. Doing so is in discussion: #77088 Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
When user_data is not zeroed-out, the API returns an error. Downgrade the API error to a warning log instead. Introducing this check (#76489) broke a few PTS tests, as user_data is not initialized by `net_buf_alloc()`. Doing so is in discussion: #77088 Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no> (cherry picked from commit 6fa6c4c)
When user_data is not zeroed-out, the API returns an error. Downgrade the API error to a warning log instead. Introducing this check (#76489) broke a few PTS tests, as user_data is not initialized by `net_buf_alloc()`. Doing so is in discussion: zephyrproject-rtos/zephyr#77088 (cherry picked from commit 6fa6c4c) Original-Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no> GitOrigin-RevId: 6fa6c4c Cr-Build-Id: 8739091610579900001 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8739091610579900001 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: Ic115fe0bdfe6595a874c7782cd8385c49f99405c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5799351 Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com> Reviewed-by: Eric Yilun Lin <yllin@google.com> Commit-Queue: Eric Yilun Lin <yllin@google.com>
When user_data is not zeroed-out, the API returns an error. Downgrade the API error to a warning log instead. Introducing this check (zephyrproject-rtos#76489) broke a few PTS tests, as user_data is not initialized by `net_buf_alloc()`. Doing so is in discussion: zephyrproject-rtos#77088 Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Introduction
We can initialize a net_buf's
user_data
member with a known pattern.Just like the
CONFIG_INIT_STACKS
option.Problem description
It is not clear who owns
user_data
.Is it the module that allocates it, the API that consumes it, something else?
With a known (non-null) initialized value, it will be possible to perform some checks and avoid head-scratching debug sessions. We've had some of those sessions in Bluetooth/L2CAP.
Proposed change
Call
memset(buf->user_data, 0xAA, buf->user_data_size)
innet_buf_alloc()
right before returningbuf
.Can be locked behind a kconfig, just like the stacks option.
Concerns and Unresolved Questions
Other users (maybe out of tree too) could break due to
NULL
checks on user_data not working anymore.E.g. the pattern of casting
cb
fromuser_data
and having a block like this one:Alternatives
net_buf
s enforce clearing by the applicationThe text was updated successfully, but these errors were encountered: