From: sashiko-bot@kernel.org
To: "Ye Weihua" <yeweihua4@huawei.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH -next 1/2] ASoC: SOF: ipc4-control: Fix out-of-bounds backup restore in bytes ext put
Date: Thu, 19 Nov 2026 13:04:02 +0000 [thread overview]
Message-ID: <sashiko-outbox-223133@kernel.org> (raw)
In-Reply-To: <20261119121446.124833-1-yeweihua4@huawei.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ASoC: SOF: restored scontrol->size overwritten in
sof_ipc4_bytes_ext_put()
- [Medium] ASoC: SOF: scontrol->size not restored on EFAULT in
sof_ipc4_bytes_ext_put()
- [Medium] ASoC: SOF: ipc4-control: incomplete backup restore when
priv_size is 0
- [Medium] ASoC: SOF: ipc4-control: incomplete msg restore in
sof_ipc4_set_get_kcontrol_data()
--
commit 3d54ef5fbf4ff729417838f0907d7062db9c4154
Author: Ye Weihua <yeweihua4@huawei.com>
ASoC: SOF: ipc4-control: Fix out-of-bounds backup restore in bytes ext put
This commit records the backup size in old_ipc_control_data_size to avoid an
out-of-bounds read when restoring bytes control data, restores msg->data_size
when replaying the backup, and moves the scontrol->size update in
sof_ipc4_bytes_ext_put() until after sof_ipc4_set_get_bytes_data() returns.
> diff --git a/sound/soc/sof/ipc4-control.c b/sound/soc/sof/ipc4-control.c
> index e29c8d89284af..f8b4842f39365 100644
> --- a/sound/soc/sof/ipc4-control.c
> +++ b/sound/soc/sof/ipc4-control.c
> @@ -58,6 +58,8 @@ static int sof_ipc4_set_get_kcontrol_data(struct snd_sof_control *scontrol,
>
> /* It is a set-data operation, and we have a valid backup that we can restore */
> if (ret < 0) {
> + struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
> +
> if (!scontrol->old_ipc_control_data)
> goto unlock;
> /*
> @@ -65,9 +67,18 @@ static int sof_ipc4_set_get_kcontrol_data(struct snd_sof_control *scontrol,
> * configuration
> */
> memcpy(scontrol->ipc_control_data, scontrol->old_ipc_control_data,
> - scontrol->size);
> + scontrol->old_ipc_control_data_size);
> + scontrol->size = scontrol->old_ipc_control_data_size;
> kfree(scontrol->old_ipc_control_data);
> scontrol->old_ipc_control_data = NULL;
> + scontrol->old_ipc_control_data_size = 0;
> + /*
> + * If the message payload points into the restored buffer, its size
> + * must be restored as well, otherwise the last known good
> + * configuration would be sent with the size of the rejected data.
> + */
> + if (msg->data_ptr == cdata->data->data)
> + msg->data_size = cdata->data->size;
> /* Send the last known good configuration to firmware */
> ret = iops->set_get_data(sdev, msg, msg->data_size, set);
> if (ret < 0)
[Severity: Medium]
Does checking msg->data_ptr == cdata->data->data miss generic bytes controls
(SOF_IPC4_BYTES_CONTROL_PARAM_ID) and leave msg->extension un-restored?
When data->type == SOF_IPC4_BYTES_CONTROL_PARAM_ID,
sof_ipc4_set_get_bytes_data() calls sof_ipc4_set_bytes_control_data(), which
copies the new payload into a separate msg_data buffer and sets
msg.data_ptr = msg_data:
sound/soc/sof/ipc4-control.c:sof_ipc4_set_bytes_control_data() {
...
msg_data->id = cdata->index;
msg_data->num_elems = data->size;
memcpy(msg_data->data, data->data, data->size);
memcpy(&msg, &cdata->msg, sizeof(msg));
msg.extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(data->type);
msg.data_ptr = msg_data;
msg.data_size = data_size;
ret = sof_ipc4_set_get_kcontrol_data(scontrol, &msg, true, lock);
...
}
Because msg->data_ptr points to msg_data rather than cdata->data->data, the
replay call re-sends the rejected msg_data buffer and size instead of the
restored backup. Even when msg->data_ptr == cdata->data->data,
sof_ipc4_bytes_ext_put() overwrites data->type from user space before
sof_ipc4_set_get_bytes_data() sets msg.extension, so msg->extension is not
restored from the backed-up cdata->data->type either.
> @@ -630,6 +641,7 @@ static int sof_ipc4_bytes_ext_put(struct snd_sof_control *scontrol,
> struct sof_abi_hdr *data = cdata->data;
> struct sof_abi_hdr abi_hdr;
> struct snd_ctl_tlv header;
> + int ret;
>
> /*
> * The beginning of bytes data contains a header from where
> @@ -686,21 +698,25 @@ static int sof_ipc4_bytes_ext_put(struct snd_sof_control *scontrol,
> scontrol->size, GFP_KERNEL);
> if (!scontrol->old_ipc_control_data)
> return -ENOMEM;
> + scontrol->old_ipc_control_data_size = scontrol->size;
> }
[Severity: Medium]
Can backing up and restoring scontrol->size bytes leave cdata->data
un-restored when a bytes control has no initial topology payload?
In sof_ipc4_control_load_bytes(), scontrol->size is initialized to
sizeof(*control_data) + scontrol->priv_size. When scontrol->priv_size is 0,
scontrol->size is only sizeof(*cdata), which stops before the flexible array
member cdata->data (struct sof_abi_hdr). kmemdup() then backs up 0 bytes of
cdata->data, and on failure of copy_from_user() or iops->set_get_data(),
memcpy(..., scontrol->old_ipc_control_data_size) restores only sizeof(*cdata)
bytes, leaving the rejected ABI header and payload in cdata->data and
replaying the rejected cdata->data->size and payload to the firmware.
> /* Copy the whole binary data which includes the ABI header and the payload */
> if (copy_from_user(data, tlvd->tlv, header.length)) {
> memcpy(scontrol->ipc_control_data, scontrol->old_ipc_control_data,
> - scontrol->size);
> + scontrol->old_ipc_control_data_size);
> kfree(scontrol->old_ipc_control_data);
> scontrol->old_ipc_control_data = NULL;
> + scontrol->old_ipc_control_data_size = 0;
> return -EFAULT;
> }
[Severity: Medium]
Should this error path also restore
scontrol->size = scontrol->old_ipc_control_data_size, like
sof_ipc4_set_get_kcontrol_data() does?
Because scontrol->old_ipc_control_data is kept across successful updates
while later updates change scontrol->size, a copy_from_user() failure on a
subsequent call restores the older backup into scontrol->ipc_control_data
without resetting scontrol->size, causing the next sof_ipc4_bytes_ext_put()
to kmemdup() the wrong size.
> - /* Update the cdata size */
> - scontrol->size = sizeof(*cdata) + header.length;
> + ret = sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true);
> + if (!ret)
> + /* Update the cdata size */
> + scontrol->size = sizeof(*cdata) + header.length;
>
> - return sof_ipc4_set_get_bytes_data(sdev, scontrol, true, true);
> + return ret;
> }
[Severity: Medium]
Does this overwrite the restored scontrol->size with the rejected payload
size whenever the backup replay succeeds?
When the firmware rejects the new payload in
sof_ipc4_set_get_kcontrol_data(), the recovery path restores
scontrol->size = scontrol->old_ipc_control_data_size, frees
scontrol->old_ipc_control_data, and calls:
ret = iops->set_get_data(sdev, msg, msg->data_size, set);
When replaying the backup configuration succeeds, ret becomes 0 and
sof_ipc4_set_get_bytes_data() returns 0. Then if (!ret) here overwrites the
restored scontrol->size with sizeof(*cdata) + header.length from the rejected
request, so the next sof_ipc4_bytes_ext_put() backs up the wrong size.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119121446.124833-1-yeweihua4@huawei.com?part=1
prev parent reply other threads:[~2026-11-19 13:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 12:14 [PATCH -next 1/2] ASoC: SOF: ipc4-control: Fix out-of-bounds backup restore in bytes ext put Ye Weihua
2026-11-19 12:14 ` [PATCH -next 2/2] ASoC: SOF: topology: Free bytes control backup on unload Ye Weihua
2026-11-19 13:04 ` sashiko-bot [this message]
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=sashiko-outbox-223133@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yeweihua4@huawei.com \
/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