media: venus: hfi_cmds: Replace one-element array with flex-array member and use...
authorGustavo A. R. Silva <gustavoars@kernel.org>
Mon, 9 Oct 2023 18:42:05 +0000 (12:42 -0600)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 23 Oct 2023 10:24:52 +0000 (12:24 +0200)
commit4c99885d592ea53f9d4872595858e3f14eaf0823
tree785d1366a92aad9cdd69c89beaa638960a6b72ca
parent0768a9dd809ef52440b5df7dce5a1c1c7e97abbd
media: venus: hfi_cmds: Replace one-element array with flex-array member and use __counted_by

Array `data` in `struct hfi_sfr` is being used as a fake flexible array
at run-time:

drivers/media/platform/qcom/venus/hfi_venus.c:
1033         p = memchr(sfr->data, '\0', sfr->buf_size);
1034         /*
1035          * SFR isn't guaranteed to be NULL terminated since SYS_ERROR indicates
1036          * that Venus is in the process of crashing.
1037          */
1038         if (!p)
1039                 sfr->data[sfr->buf_size - 1] = '\0';
1040
1041         dev_err_ratelimited(dev, "SFR message from FW: %s\n", sfr->data);

Fake flexible arrays are deprecated, and should be replaced by
flexible-array members. So, replace one-element array with a
flexible-array member in `struct hfi_sfr`.

While there, also annotate array `data` with __counted_by() to prepare
for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

This results in no differences in binary output.

This issue was found with the help of Coccinelle, and audited and fixed
manually.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Stanimir Varbanov <stanimir.k.varbanov@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/platform/qcom/venus/hfi_cmds.h