kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] remoteproc: harden rproc_handle_vdev() against integer overflow
@ 2022-09-15 14:11 Dan Carpenter
  2022-09-15 14:17 ` Gustavo A. R. Silva
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dan Carpenter @ 2022-09-15 14:11 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Mathieu Poirier, Gustavo A. R. Silva, linux-remoteproc,
	kernel-janitors

The struct_size() macro protects against integer overflows but adding
"+ rsc->config_len" introduces the risk of integer overflows again.
Use size_add() to be safe.

Fixes: c87846571587 ("remoteproc: use struct_size() helper")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/remoteproc/remoteproc_core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index e5279ed9a8d7..4fc5ce2187ac 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -520,12 +520,13 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
 	struct fw_rsc_vdev *rsc = ptr;
 	struct device *dev = &rproc->dev;
 	struct rproc_vdev *rvdev;
+	size_t rsc_size;
 	int i, ret;
 	char name[16];
 
 	/* make sure resource isn't truncated */
-	if (struct_size(rsc, vring, rsc->num_of_vrings) + rsc->config_len >
-			avail) {
+	rsc_size = struct_size(rsc, vring, rsc->num_of_vrings);
+	if (size_add(rsc_size, rsc->config_len) > avail) {
 		dev_err(dev, "vdev rsc is truncated\n");
 		return -EINVAL;
 	}
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] remoteproc: harden rproc_handle_vdev() against integer overflow
  2022-09-15 14:11 [PATCH] remoteproc: harden rproc_handle_vdev() against integer overflow Dan Carpenter
@ 2022-09-15 14:17 ` Gustavo A. R. Silva
  2022-09-15 14:24 ` Mukesh Ojha
  2022-09-19 20:34 ` Mathieu Poirier
  2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2022-09-15 14:17 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Bjorn Andersson, Mathieu Poirier, Gustavo A. R. Silva,
	linux-remoteproc, kernel-janitors

On Thu, Sep 15, 2022 at 05:11:44PM +0300, Dan Carpenter wrote:
> The struct_size() macro protects against integer overflows but adding
> "+ rsc->config_len" introduces the risk of integer overflows again.
> Use size_add() to be safe.
> 
> Fixes: c87846571587 ("remoteproc: use struct_size() helper")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks!
--
Gustavo

> ---
>  drivers/remoteproc/remoteproc_core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index e5279ed9a8d7..4fc5ce2187ac 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -520,12 +520,13 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
>  	struct fw_rsc_vdev *rsc = ptr;
>  	struct device *dev = &rproc->dev;
>  	struct rproc_vdev *rvdev;
> +	size_t rsc_size;
>  	int i, ret;
>  	char name[16];
>  
>  	/* make sure resource isn't truncated */
> -	if (struct_size(rsc, vring, rsc->num_of_vrings) + rsc->config_len >
> -			avail) {
> +	rsc_size = struct_size(rsc, vring, rsc->num_of_vrings);
> +	if (size_add(rsc_size, rsc->config_len) > avail) {
>  		dev_err(dev, "vdev rsc is truncated\n");
>  		return -EINVAL;
>  	}
> -- 
> 2.35.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] remoteproc: harden rproc_handle_vdev() against integer overflow
  2022-09-15 14:11 [PATCH] remoteproc: harden rproc_handle_vdev() against integer overflow Dan Carpenter
  2022-09-15 14:17 ` Gustavo A. R. Silva
@ 2022-09-15 14:24 ` Mukesh Ojha
  2022-09-19 20:34 ` Mathieu Poirier
  2 siblings, 0 replies; 4+ messages in thread
From: Mukesh Ojha @ 2022-09-15 14:24 UTC (permalink / raw)
  To: Dan Carpenter, Bjorn Andersson
  Cc: Mathieu Poirier, Gustavo A. R. Silva, linux-remoteproc,
	kernel-janitors

Hi,

On 9/15/2022 7:41 PM, Dan Carpenter wrote:
> The struct_size() macro protects against integer overflows but adding
> "+ rsc->config_len" introduces the risk of integer overflows again.
> Use size_add() to be safe.
> 
> Fixes: c87846571587 ("remoteproc: use struct_size() helper")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>   drivers/remoteproc/remoteproc_core.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index e5279ed9a8d7..4fc5ce2187ac 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -520,12 +520,13 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
>   	struct fw_rsc_vdev *rsc = ptr;
>   	struct device *dev = &rproc->dev;
>   	struct rproc_vdev *rvdev;
> +	size_t rsc_size;
>   	int i, ret;
>   	char name[16];
>   
>   	/* make sure resource isn't truncated */
> -	if (struct_size(rsc, vring, rsc->num_of_vrings) + rsc->config_len >
> -			avail) {
> +	rsc_size = struct_size(rsc, vring, rsc->num_of_vrings);
> +	if (size_add(rsc_size, rsc->config_len) > avail) {
>   		dev_err(dev, "vdev rsc is truncated\n");
>   		return -EINVAL;

Looks Good.

Reviewed-by: Mukesh Ojha <quic_mojha@quicinc.com>

-Mukesh

>   	}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] remoteproc: harden rproc_handle_vdev() against integer overflow
  2022-09-15 14:11 [PATCH] remoteproc: harden rproc_handle_vdev() against integer overflow Dan Carpenter
  2022-09-15 14:17 ` Gustavo A. R. Silva
  2022-09-15 14:24 ` Mukesh Ojha
@ 2022-09-19 20:34 ` Mathieu Poirier
  2 siblings, 0 replies; 4+ messages in thread
From: Mathieu Poirier @ 2022-09-19 20:34 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Bjorn Andersson, Gustavo A. R. Silva, linux-remoteproc,
	kernel-janitors

On Thu, Sep 15, 2022 at 05:11:44PM +0300, Dan Carpenter wrote:
> The struct_size() macro protects against integer overflows but adding
> "+ rsc->config_len" introduces the risk of integer overflows again.
> Use size_add() to be safe.
> 
> Fixes: c87846571587 ("remoteproc: use struct_size() helper")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/remoteproc/remoteproc_core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Applied.

Thanks,
Mathieu

> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index e5279ed9a8d7..4fc5ce2187ac 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -520,12 +520,13 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
>  	struct fw_rsc_vdev *rsc = ptr;
>  	struct device *dev = &rproc->dev;
>  	struct rproc_vdev *rvdev;
> +	size_t rsc_size;
>  	int i, ret;
>  	char name[16];
>  
>  	/* make sure resource isn't truncated */
> -	if (struct_size(rsc, vring, rsc->num_of_vrings) + rsc->config_len >
> -			avail) {
> +	rsc_size = struct_size(rsc, vring, rsc->num_of_vrings);
> +	if (size_add(rsc_size, rsc->config_len) > avail) {
>  		dev_err(dev, "vdev rsc is truncated\n");
>  		return -EINVAL;
>  	}
> -- 
> 2.35.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-19 20:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-15 14:11 [PATCH] remoteproc: harden rproc_handle_vdev() against integer overflow Dan Carpenter
2022-09-15 14:17 ` Gustavo A. R. Silva
2022-09-15 14:24 ` Mukesh Ojha
2022-09-19 20:34 ` Mathieu Poirier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).