Commit 7ba59ac7 authored by Kees Cook's avatar Kees Cook Committed by Greg Kroah-Hartman

greybus: Avoid fake flexible array for response data

FORTIFY_SOURCE has been ignoring 0-sized destinations while the kernel
code base has been converted to flexible arrays. In order to enforce
the 0-sized destinations (e.g. with __counted_by), the remaining 0-sized
destinations need to be handled. Instead of converting an empty struct
into using a flexible array, just directly use a pointer without any
additional indirection. Remove struct gb_bootrom_get_firmware_response
and struct gb_fw_download_fetch_firmware_response.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
Link: https://lore.kernel.org/r/20240304211940.it.083-kees@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 34164202
...@@ -243,10 +243,10 @@ static int gb_bootrom_get_firmware(struct gb_operation *op) ...@@ -243,10 +243,10 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
struct gb_bootrom *bootrom = gb_connection_get_data(op->connection); struct gb_bootrom *bootrom = gb_connection_get_data(op->connection);
const struct firmware *fw; const struct firmware *fw;
struct gb_bootrom_get_firmware_request *firmware_request; struct gb_bootrom_get_firmware_request *firmware_request;
struct gb_bootrom_get_firmware_response *firmware_response;
struct device *dev = &op->connection->bundle->dev; struct device *dev = &op->connection->bundle->dev;
unsigned int offset, size; unsigned int offset, size;
enum next_request_type next_request; enum next_request_type next_request;
u8 *firmware_response;
int ret = 0; int ret = 0;
/* Disable timeouts */ /* Disable timeouts */
...@@ -280,15 +280,15 @@ static int gb_bootrom_get_firmware(struct gb_operation *op) ...@@ -280,15 +280,15 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
goto unlock; goto unlock;
} }
if (!gb_operation_response_alloc(op, sizeof(*firmware_response) + size, /* gb_bootrom_get_firmware_response contains only a byte array */
GFP_KERNEL)) { if (!gb_operation_response_alloc(op, size, GFP_KERNEL)) {
dev_err(dev, "%s: error allocating response\n", __func__); dev_err(dev, "%s: error allocating response\n", __func__);
ret = -ENOMEM; ret = -ENOMEM;
goto unlock; goto unlock;
} }
firmware_response = op->response->payload; firmware_response = op->response->payload;
memcpy(firmware_response->data, fw->data + offset, size); memcpy(firmware_response, fw->data + offset, size);
dev_dbg(dev, "responding with firmware (offs = %u, size = %u)\n", dev_dbg(dev, "responding with firmware (offs = %u, size = %u)\n",
offset, size); offset, size);
......
...@@ -270,11 +270,11 @@ static int fw_download_fetch_firmware(struct gb_operation *op) ...@@ -270,11 +270,11 @@ static int fw_download_fetch_firmware(struct gb_operation *op)
struct gb_connection *connection = op->connection; struct gb_connection *connection = op->connection;
struct fw_download *fw_download = gb_connection_get_data(connection); struct fw_download *fw_download = gb_connection_get_data(connection);
struct gb_fw_download_fetch_firmware_request *request; struct gb_fw_download_fetch_firmware_request *request;
struct gb_fw_download_fetch_firmware_response *response;
struct fw_request *fw_req; struct fw_request *fw_req;
const struct firmware *fw; const struct firmware *fw;
unsigned int offset, size; unsigned int offset, size;
u8 firmware_id; u8 firmware_id;
u8 *response;
int ret = 0; int ret = 0;
if (op->request->payload_size != sizeof(*request)) { if (op->request->payload_size != sizeof(*request)) {
...@@ -324,8 +324,8 @@ static int fw_download_fetch_firmware(struct gb_operation *op) ...@@ -324,8 +324,8 @@ static int fw_download_fetch_firmware(struct gb_operation *op)
goto put_fw; goto put_fw;
} }
if (!gb_operation_response_alloc(op, sizeof(*response) + size, /* gb_fw_download_fetch_firmware_response contains only a byte array */
GFP_KERNEL)) { if (!gb_operation_response_alloc(op, size, GFP_KERNEL)) {
dev_err(fw_download->parent, dev_err(fw_download->parent,
"error allocating fetch firmware response\n"); "error allocating fetch firmware response\n");
ret = -ENOMEM; ret = -ENOMEM;
...@@ -333,7 +333,7 @@ static int fw_download_fetch_firmware(struct gb_operation *op) ...@@ -333,7 +333,7 @@ static int fw_download_fetch_firmware(struct gb_operation *op)
} }
response = op->response->payload; response = op->response->payload;
memcpy(response->data, fw->data + offset, size); memcpy(response, fw->data + offset, size);
dev_dbg(fw_download->parent, dev_dbg(fw_download->parent,
"responding with firmware (offs = %u, size = %u)\n", offset, "responding with firmware (offs = %u, size = %u)\n", offset,
......
...@@ -232,9 +232,7 @@ struct gb_fw_download_fetch_firmware_request { ...@@ -232,9 +232,7 @@ struct gb_fw_download_fetch_firmware_request {
__le32 size; __le32 size;
} __packed; } __packed;
struct gb_fw_download_fetch_firmware_response { /* gb_fw_download_fetch_firmware_response contains no other data */
__u8 data[0];
} __packed;
/* firmware download release firmware request */ /* firmware download release firmware request */
struct gb_fw_download_release_firmware_request { struct gb_fw_download_release_firmware_request {
...@@ -414,9 +412,7 @@ struct gb_bootrom_get_firmware_request { ...@@ -414,9 +412,7 @@ struct gb_bootrom_get_firmware_request {
__le32 size; __le32 size;
} __packed; } __packed;
struct gb_bootrom_get_firmware_response { /* gb_bootrom_get_firmware_response contains no other data */
__u8 data[0];
} __packed;
/* Bootrom protocol Ready to boot request */ /* Bootrom protocol Ready to boot request */
struct gb_bootrom_ready_to_boot_request { struct gb_bootrom_ready_to_boot_request {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment