]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
remoteproc: Harden rproc_handle_vdev() against integer overflow
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 15 Sep 2022 14:11:44 +0000 (17:11 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Oct 2022 07:57:53 +0000 (09:57 +0200)
[ Upstream commit 7d7f8fe4e399519cc9ac68a475fec6d3a996341b ]

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>
Reviewed-by: Mukesh Ojha <quic_mojha@quicinc.com>
Link: https://lore.kernel.org/r/YyMyoPoGOJUcEpZT@kili
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/remoteproc/remoteproc_core.c

index 02a04ab34a23086260ffb406a7923718d35ace9a..9d86470df79bbeed465304930a29052e3b910f0f 100644 (file)
@@ -518,12 +518,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;
        }