[v1,2/9] media: vimc: Constify vimc_ent_type structures

Message ID 20240424235741.17093-3-laurent.pinchart@ideasonboard.com (mailing list archive)
State New
Headers
Series media: vimc improvements |

Commit Message

Laurent Pinchart April 24, 2024, 11:57 p.m. UTC
  The vimc_ent_type structure contains static pointers to functions, and
no other information that need to be modified after initialization. Make
them const to avoid the risk of arbitrary code execution following an
overflow that would overwrite the structure's contents.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/test-drivers/vimc/vimc-capture.c |  2 +-
 drivers/media/test-drivers/vimc/vimc-common.h  | 12 ++++++------
 drivers/media/test-drivers/vimc/vimc-debayer.c |  2 +-
 drivers/media/test-drivers/vimc/vimc-lens.c    |  2 +-
 drivers/media/test-drivers/vimc/vimc-scaler.c  |  2 +-
 drivers/media/test-drivers/vimc/vimc-sensor.c  |  2 +-
 6 files changed, 11 insertions(+), 11 deletions(-)
  

Comments

Shuah Khan May 30, 2024, 7:28 p.m. UTC | #1
On 4/24/24 17:57, Laurent Pinchart wrote:
> The vimc_ent_type structure contains static pointers to functions, and
> no other information that need to be modified after initialization. Make
> them const to avoid the risk of arbitrary code execution following an
> overflow that would overwrite the structure's contents.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>   drivers/media/test-drivers/vimc/vimc-capture.c |  2 +-
>   drivers/media/test-drivers/vimc/vimc-common.h  | 12 ++++++------
>   drivers/media/test-drivers/vimc/vimc-debayer.c |  2 +-
>   drivers/media/test-drivers/vimc/vimc-lens.c    |  2 +-
>   drivers/media/test-drivers/vimc/vimc-scaler.c  |  2 +-
>   drivers/media/test-drivers/vimc/vimc-sensor.c  |  2 +-
>   6 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c
> index ba7550b8ba7e..89506ae00901 100644
> --- a/drivers/media/test-drivers/vimc/vimc-capture.c
> +++ b/drivers/media/test-drivers/vimc/vimc-capture.c
> @@ -494,7 +494,7 @@ static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc,
>   	return ERR_PTR(ret);
>   }
>   
> -struct vimc_ent_type vimc_capture_type = {
> +const struct vimc_ent_type vimc_capture_type = {
>   	.add = vimc_capture_add,
>   	.unregister = vimc_capture_unregister,
>   	.release = vimc_capture_release
> diff --git a/drivers/media/test-drivers/vimc/vimc-common.h b/drivers/media/test-drivers/vimc/vimc-common.h
> index 7641a101a728..6a76717e0384 100644
> --- a/drivers/media/test-drivers/vimc/vimc-common.h
> +++ b/drivers/media/test-drivers/vimc/vimc-common.h
> @@ -156,7 +156,7 @@ struct vimc_ent_type {
>    */
>   struct vimc_ent_config {
>   	const char *name;
> -	struct vimc_ent_type *type;
> +	const struct vimc_ent_type *type;
>   };
>   
>   /**
> @@ -167,11 +167,11 @@ struct vimc_ent_config {
>    */
>   bool vimc_is_source(struct media_entity *ent);
>   
> -extern struct vimc_ent_type vimc_sensor_type;
> -extern struct vimc_ent_type vimc_debayer_type;
> -extern struct vimc_ent_type vimc_scaler_type;
> -extern struct vimc_ent_type vimc_capture_type;
> -extern struct vimc_ent_type vimc_lens_type;
> +extern const struct vimc_ent_type vimc_sensor_type;
> +extern const struct vimc_ent_type vimc_debayer_type;
> +extern const struct vimc_ent_type vimc_scaler_type;
> +extern const struct vimc_ent_type vimc_capture_type;
> +extern const struct vimc_ent_type vimc_lens_type;
>   
>   /**
>    * vimc_pix_map_by_index - get vimc_pix_map struct by its index
> diff --git a/drivers/media/test-drivers/vimc/vimc-debayer.c b/drivers/media/test-drivers/vimc/vimc-debayer.c
> index e1bf6db73050..e2f12a7fb58f 100644
> --- a/drivers/media/test-drivers/vimc/vimc-debayer.c
> +++ b/drivers/media/test-drivers/vimc/vimc-debayer.c
> @@ -622,7 +622,7 @@ static struct vimc_ent_device *vimc_debayer_add(struct vimc_device *vimc,
>   	return ERR_PTR(ret);
>   }
>   
> -struct vimc_ent_type vimc_debayer_type = {
> +const struct vimc_ent_type vimc_debayer_type = {
>   	.add = vimc_debayer_add,
>   	.release = vimc_debayer_release
>   };
> diff --git a/drivers/media/test-drivers/vimc/vimc-lens.c b/drivers/media/test-drivers/vimc/vimc-lens.c
> index 3ce7f4b4d2cc..e7d78fa8ccdb 100644
> --- a/drivers/media/test-drivers/vimc/vimc-lens.c
> +++ b/drivers/media/test-drivers/vimc/vimc-lens.c
> @@ -96,7 +96,7 @@ static void vimc_lens_release(struct vimc_ent_device *ved)
>   	kfree(vlens);
>   }
>   
> -struct vimc_ent_type vimc_lens_type = {
> +const struct vimc_ent_type vimc_lens_type = {
>   	.add = vimc_lens_add,
>   	.release = vimc_lens_release
>   };
> diff --git a/drivers/media/test-drivers/vimc/vimc-scaler.c b/drivers/media/test-drivers/vimc/vimc-scaler.c
> index afe13d6af321..3e32cfb79c64 100644
> --- a/drivers/media/test-drivers/vimc/vimc-scaler.c
> +++ b/drivers/media/test-drivers/vimc/vimc-scaler.c
> @@ -442,7 +442,7 @@ static struct vimc_ent_device *vimc_scaler_add(struct vimc_device *vimc,
>   	return &vscaler->ved;
>   }
>   
> -struct vimc_ent_type vimc_scaler_type = {
> +const struct vimc_ent_type vimc_scaler_type = {
>   	.add = vimc_scaler_add,
>   	.release = vimc_scaler_release
>   };
> diff --git a/drivers/media/test-drivers/vimc/vimc-sensor.c b/drivers/media/test-drivers/vimc/vimc-sensor.c
> index b535b3ffecff..11df18332865 100644
> --- a/drivers/media/test-drivers/vimc/vimc-sensor.c
> +++ b/drivers/media/test-drivers/vimc/vimc-sensor.c
> @@ -448,7 +448,7 @@ static struct vimc_ent_device *vimc_sensor_add(struct vimc_device *vimc,
>   	return ERR_PTR(ret);
>   }
>   
> -struct vimc_ent_type vimc_sensor_type = {
> +const struct vimc_ent_type vimc_sensor_type = {
>   	.add = vimc_sensor_add,
>   	.release = vimc_sensor_release
>   };

Looks good to me.

thanks,
-- Shuah
  

Patch

diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c
index ba7550b8ba7e..89506ae00901 100644
--- a/drivers/media/test-drivers/vimc/vimc-capture.c
+++ b/drivers/media/test-drivers/vimc/vimc-capture.c
@@ -494,7 +494,7 @@  static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc,
 	return ERR_PTR(ret);
 }
 
-struct vimc_ent_type vimc_capture_type = {
+const struct vimc_ent_type vimc_capture_type = {
 	.add = vimc_capture_add,
 	.unregister = vimc_capture_unregister,
 	.release = vimc_capture_release
diff --git a/drivers/media/test-drivers/vimc/vimc-common.h b/drivers/media/test-drivers/vimc/vimc-common.h
index 7641a101a728..6a76717e0384 100644
--- a/drivers/media/test-drivers/vimc/vimc-common.h
+++ b/drivers/media/test-drivers/vimc/vimc-common.h
@@ -156,7 +156,7 @@  struct vimc_ent_type {
  */
 struct vimc_ent_config {
 	const char *name;
-	struct vimc_ent_type *type;
+	const struct vimc_ent_type *type;
 };
 
 /**
@@ -167,11 +167,11 @@  struct vimc_ent_config {
  */
 bool vimc_is_source(struct media_entity *ent);
 
-extern struct vimc_ent_type vimc_sensor_type;
-extern struct vimc_ent_type vimc_debayer_type;
-extern struct vimc_ent_type vimc_scaler_type;
-extern struct vimc_ent_type vimc_capture_type;
-extern struct vimc_ent_type vimc_lens_type;
+extern const struct vimc_ent_type vimc_sensor_type;
+extern const struct vimc_ent_type vimc_debayer_type;
+extern const struct vimc_ent_type vimc_scaler_type;
+extern const struct vimc_ent_type vimc_capture_type;
+extern const struct vimc_ent_type vimc_lens_type;
 
 /**
  * vimc_pix_map_by_index - get vimc_pix_map struct by its index
diff --git a/drivers/media/test-drivers/vimc/vimc-debayer.c b/drivers/media/test-drivers/vimc/vimc-debayer.c
index e1bf6db73050..e2f12a7fb58f 100644
--- a/drivers/media/test-drivers/vimc/vimc-debayer.c
+++ b/drivers/media/test-drivers/vimc/vimc-debayer.c
@@ -622,7 +622,7 @@  static struct vimc_ent_device *vimc_debayer_add(struct vimc_device *vimc,
 	return ERR_PTR(ret);
 }
 
-struct vimc_ent_type vimc_debayer_type = {
+const struct vimc_ent_type vimc_debayer_type = {
 	.add = vimc_debayer_add,
 	.release = vimc_debayer_release
 };
diff --git a/drivers/media/test-drivers/vimc/vimc-lens.c b/drivers/media/test-drivers/vimc/vimc-lens.c
index 3ce7f4b4d2cc..e7d78fa8ccdb 100644
--- a/drivers/media/test-drivers/vimc/vimc-lens.c
+++ b/drivers/media/test-drivers/vimc/vimc-lens.c
@@ -96,7 +96,7 @@  static void vimc_lens_release(struct vimc_ent_device *ved)
 	kfree(vlens);
 }
 
-struct vimc_ent_type vimc_lens_type = {
+const struct vimc_ent_type vimc_lens_type = {
 	.add = vimc_lens_add,
 	.release = vimc_lens_release
 };
diff --git a/drivers/media/test-drivers/vimc/vimc-scaler.c b/drivers/media/test-drivers/vimc/vimc-scaler.c
index afe13d6af321..3e32cfb79c64 100644
--- a/drivers/media/test-drivers/vimc/vimc-scaler.c
+++ b/drivers/media/test-drivers/vimc/vimc-scaler.c
@@ -442,7 +442,7 @@  static struct vimc_ent_device *vimc_scaler_add(struct vimc_device *vimc,
 	return &vscaler->ved;
 }
 
-struct vimc_ent_type vimc_scaler_type = {
+const struct vimc_ent_type vimc_scaler_type = {
 	.add = vimc_scaler_add,
 	.release = vimc_scaler_release
 };
diff --git a/drivers/media/test-drivers/vimc/vimc-sensor.c b/drivers/media/test-drivers/vimc/vimc-sensor.c
index b535b3ffecff..11df18332865 100644
--- a/drivers/media/test-drivers/vimc/vimc-sensor.c
+++ b/drivers/media/test-drivers/vimc/vimc-sensor.c
@@ -448,7 +448,7 @@  static struct vimc_ent_device *vimc_sensor_add(struct vimc_device *vimc,
 	return ERR_PTR(ret);
 }
 
-struct vimc_ent_type vimc_sensor_type = {
+const struct vimc_ent_type vimc_sensor_type = {
 	.add = vimc_sensor_add,
 	.release = vimc_sensor_release
 };