remoteproc: harden rproc_handle_vdev() against integer overflow
Subsystems (2)
PATCH 1/1 remoteproc: harden rproc_handle_vdev() against integer overflow
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.
--- drivers/remoteproc/remoteproc_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/remoteproc/remoteproc_core.c +3 -2
@@ -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 ; }
Signature · 1 line
2.35.1
Quoted 6 lines · Dan Carpenter
The
struct_size()macro protects against integer overflows but adding "+rsc->config_len" introduces the risk of integer overflows again. Usesize_add()to be safe.Fixes c87846571587 ("remoteproc: use struct_size() helper")Signed-off-by Dan Carpenter <[email protected]>
Thanks!
--
Gustavo
Quoted 27 lines
--- drivers/remoteproc/remoteproc_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/remoteproc/remoteproc_core.c +3
-2@@ -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 ; }Signature · 1 line
2.35.1
Hi,
Quoted 19 lines · Dan Carpenter
The
struct_size()macro protects against integer overflows but adding "+rsc->config_len" introduces the risk of integer overflows again. Usesize_add()to be safe.Fixes c87846571587 ("remoteproc: use struct_size() helper")Signed-off-by Dan Carpenter <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/remoteproc/remoteproc_core.c +1
-0@@ -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;
drivers/remoteproc/remoteproc_core.c static int rproc_handle_vdev(struct rproc *rproc, void *ptr, · line 531
Quoted 10 lines
drivers/remoteproc/remoteproc_core.c +2
-2int 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.
-Mukesh
Quoted 1 line
drivers/remoteproc/remoteproc_core.c +0
-0}
Quoted 9 lines · Dan Carpenter
The
struct_size()macro protects against integer overflows but adding "+rsc->config_len" introduces the risk of integer overflows again. Usesize_add()to be safe.Fixes c87846571587 ("remoteproc: use struct_size() helper")Signed-off-by Dan Carpenter <[email protected]>--- drivers/remoteproc/remoteproc_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Applied.
Thanks,
Mathieu
Quoted 24 lines
drivers/remoteproc/remoteproc_core.c +3
-2@@ -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 ; }Signature · 1 line
2.35.1