From: sashiko-bot@kernel.org
To: "Jinseob Kim" <kimjinseob88@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH RFC v2 3/7] iio: osf: add protocol v0 decoding
Date: Sun, 24 May 2026 09:16:59 +0000 [thread overview]
Message-ID: <20260524091700.5D15B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260524085312.15369-4-kimjinseob88@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The function `osf_protocol_decode_sensor_sample` fails to validate the untrusted `sensor_type` field from the payload.
--
commit 771f82b33a67fcd96de20b3ff22ae83721808219
Author: Jinseob Kim <kimjinseob88@gmail.com>
iio: osf: add protocol v0 decoding
This commit introduces the OSF0 protocol frame and payload decoders for
device-to-host messages.
> diff --git a/drivers/iio/opensensorfusion/osf_protocol.c b/drivers/iio/opensensorfusion/osf_protocol.c
> new file mode 100644
> index 0000000000000..ac3c37ae28f32
> --- /dev/null
> +++ b/drivers/iio/opensensorfusion/osf_protocol.c
[ ... ]
> +int osf_protocol_decode_sensor_sample(const struct osf_frame *frame,
> + struct osf_sensor_sample *sample)
> +{
> + u16 channel_count;
> + u16 sample_format;
> + u32 expected_len;
> + const u8 *payload;
> +
> + if (!frame || !sample || !frame->payload)
> + return -EINVAL;
> +
> + if (frame->message_type != OSF_MSG_SENSOR_SAMPLE)
> + return -EPROTO;
> +
> + if (frame->payload_len < OSF_SENSOR_SAMPLE_BASE_LEN)
> + return -EMSGSIZE;
> +
> + payload = frame->payload;
> + channel_count = get_unaligned_le16(payload + 4);
> + sample_format = get_unaligned_le16(payload + 6);
> +
> + if (sample_format != OSF_SAMPLE_FORMAT_S32)
> + return -EPROTO;
> +
> + expected_len = OSF_SENSOR_SAMPLE_BASE_LEN + channel_count * sizeof(s32);
> + if (frame->payload_len != expected_len)
> + return -EMSGSIZE;
> +
> + sample->sensor_type = get_unaligned_le16(payload);
[Severity: Medium]
Should this code validate the untrusted sensor_type field?
The parser validates the sample format but assigns sample->sensor_type
directly from the untrusted device payload without calling the available
osf_sensor_type_valid() function.
If an invalid sensor type is accepted and passed to the core handler, it
could be stored in the latest_samples cache. Since the cache has a fixed
limit (OSF_MAX_CAPABILITIES), storing invalid sensor types from a malformed
payload could exhaust the available slots, causing legitimate future sensor
samples to be permanently dropped with -E2BIG.
> + sample->sensor_index = get_unaligned_le16(payload + 2);
> + sample->channel_count = channel_count;
> + sample->sample_format = sample_format;
> + sample->scale_nano = get_unaligned_le32(payload + 8);
> + sample->reserved = get_unaligned_le32(payload + 12);
> + sample->samples = payload + OSF_SENSOR_SAMPLE_BASE_LEN;
> +
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260524085312.15369-1-kimjinseob88@gmail.com?part=3
next prev parent reply other threads:[~2026-05-24 9:17 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-24 8:53 [PATCH RFC v2 0/7] iio: add Open Sensor Fusion UART driver Jinseob Kim
2026-05-24 8:53 ` [PATCH RFC v2 1/7] dt-bindings: iio: add Open Sensor Fusion UART device Jinseob Kim
2026-05-24 9:03 ` sashiko-bot
2026-05-24 18:59 ` Krzysztof Kozlowski
2026-05-24 19:34 ` Conor Dooley
2026-05-25 2:06 ` Kim Jinseob
2026-05-24 8:53 ` [PATCH RFC v2 2/7] Documentation: iio: add Open Sensor Fusion protocol v0 reference Jinseob Kim
2026-05-28 13:28 ` Jonathan Cameron
[not found] ` <CALMSew+3RVXxLJYtr3HkV7UeAf6Mqx6PpA2CehChoVaMFddpJw@mail.gmail.com>
2026-05-29 12:52 ` Kim Jinseob
2026-05-24 8:53 ` [PATCH RFC v2 3/7] iio: osf: add protocol v0 decoding Jinseob Kim
2026-05-24 9:16 ` sashiko-bot [this message]
2026-05-28 13:48 ` Jonathan Cameron
[not found] ` <CALMSew+wUH1H-2MTtexCFgyD4Y+upFuSfFzTWBn3VGN6CWYFNQ@mail.gmail.com>
2026-05-29 12:53 ` Kim Jinseob
2026-05-24 8:53 ` [PATCH RFC v2 4/7] iio: osf: add stream parser Jinseob Kim
2026-05-24 9:41 ` sashiko-bot
2026-05-28 13:58 ` Jonathan Cameron
2026-05-29 12:44 ` Kim Jinseob
2026-05-24 8:53 ` [PATCH RFC v2 5/7] iio: osf: add UART serdev transport Jinseob Kim
2026-05-28 14:06 ` Jonathan Cameron
2026-05-29 12:47 ` Kim Jinseob
2026-05-24 8:53 ` [PATCH RFC v2 6/7] iio: osf: register IIO devices from capabilities Jinseob Kim
2026-05-24 10:57 ` sashiko-bot
2026-05-28 14:30 ` Jonathan Cameron
2026-05-29 12:49 ` Kim Jinseob
2026-05-24 8:53 ` [PATCH RFC v2 7/7] MAINTAINERS: add Open Sensor Fusion IIO driver Jinseob Kim
2026-05-25 12:11 ` Krzysztof Kozlowski
2026-05-28 14:31 ` Jonathan Cameron
2026-05-29 12:51 ` Kim Jinseob
2026-05-29 13:07 ` Jonathan Cameron
2026-06-02 23:59 ` [PATCH RFC v2 0/7] iio: add Open Sensor Fusion UART driver Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260524091700.5D15B1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kimjinseob88@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox