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

Bluetooth: services: Adds additonal len checks for ots_dir_list #33872

Merged
merged 2 commits into from
Apr 22, 2021

Conversation

Thalley
Copy link
Collaborator

@Thalley Thalley commented Mar 30, 2021

Adds additional length checks for the OTS directory listing
implementation. This will check the object name length and
the total length of the object when encoding,
as well as the length of the objects when removing objects
from the directory listing.

Signed-off-by: Emil Gydesen emil.gydesen@nordicsemi.no

fixes #33830

Comment on lines +138 to +140
__ASSERT((len + offset) <= dir_list->net_buf.len,
"Invalid dir_list buf length %u, expected at least %u",
dir_list->net_buf.len, len + offset);
Copy link
Member

Choose a reason for hiding this comment

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

Does dir_list.net_buf originate from some remote peer device? If so, then assert is the wrong choice here. That should only be used to catch local programming bugs, whereas invalid data from a peer should be handled gracefully.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The dir_list.net_buf (in fact everything related to the dir_list) is created by the OTS service locally. It is an internal read-only object.

The dir_list object is, however, created based on metadata from other, potentially remotely created objects, but my opinion is that it is the responsibility of the OTS implementation (and not the OTS dir list implementation) to validate remotely created objects. That being said, the current version of our OTS implementation does not allow a client to create objects, but only the local application.

@Thalley Thalley requested a review from jhedberg March 31, 2021 09:16
@carlescufi
Copy link
Member

@kapi-no can you please review?

net_buf_simple_add_u8(net_buf, strlen(obj->metadata.name));
obj_name_len = strlen(obj->metadata.name);
__ASSERT(obj_name_len >= 0 && obj_name_len <= 120,
"Dir list object len is too small %u", len);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"Dir list object len is too small %u", len);
"Dir list object len is incorrect %u", len);

It can be too large.

The first condition seems always true:

obj_name_len >= 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The first condition should have been obj_name_len > 0 as empty strings are not allowed for the names.

Thalley added 2 commits April 16, 2021 12:39
Adds additional length checks for the OTS directory listing
implementation. This will check the object name length and
the total length of the object when encoding,
as well as the length of the objects when removing objects
from the directory listing.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Adds name length checks. The OTS spec does not
explicitely specifiy a maximum name length, but the
maximum name length in the directory listing object
shall be less or equal to 120 octets.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
@Thalley Thalley force-pushed the ots_length_checks branch from af9ac0f to 72e5fc6 Compare April 16, 2021 10:40
@github-actions github-actions bot added the area: API Changes to public APIs label Apr 16, 2021
@Thalley Thalley requested review from kapi-no and jhedberg April 16, 2021 10:41
@Thalley
Copy link
Collaborator Author

Thalley commented Apr 16, 2021

@jhedberg Added another commit w.r.t. name length checks. Will you please re-review?

@carlescufi carlescufi merged commit cfe0849 into zephyrproject-rtos:master Apr 22, 2021
@Thalley Thalley deleted the ots_length_checks branch April 22, 2021 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Coverity CID: 220314] Untrusted value as argument in subsys/bluetooth/services/ots/ots_dir_list.c
5 participants