media: staging/intel-ipu3: Fix set_fmt error handling
authorRicardo Ribalda <ribalda@chromium.org>
Wed, 10 Mar 2021 00:16:46 +0000 (01:16 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 May 2021 12:47:38 +0000 (14:47 +0200)
commit ad91849996f9dd79741a961fd03585a683b08356 upstream.

If there in an error during a set_fmt, do not overwrite the previous
sizes with the invalid config.

Without this patch, v4l2-compliance ends up allocating 4GiB of RAM and
causing the following OOPs

[   38.662975] ipu3-imgu 0000:00:05.0: swiotlb buffer is full (sz: 4096 bytes)
[   38.662980] DMA: Out of SW-IOMMU space for 4096 bytes at device 0000:00:05.0
[   38.663010] general protection fault: 0000 [#1] PREEMPT SMP

Cc: stable@vger.kernel.org
Fixes: 6d5f26f2e045 ("media: staging/intel-ipu3-v4l: reduce kernel stack usage")
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/media/ipu3/ipu3-v4l2.c

index 6333952..be314c3 100644 (file)
@@ -669,6 +669,7 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node,
        struct imgu_css_pipe *css_pipe = &imgu->css.pipes[pipe];
        struct imgu_media_pipe *imgu_pipe = &imgu->imgu_pipe[pipe];
        struct imgu_v4l2_subdev *imgu_sd = &imgu_pipe->imgu_sd;
+       struct v4l2_pix_format_mplane fmt_backup;
 
        dev_dbg(dev, "set fmt node [%u][%u](try = %u)", pipe, node, try);
 
@@ -737,6 +738,7 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node,
                ret = -EINVAL;
                goto out;
        }
+       fmt_backup = *fmts[css_q];
        *fmts[css_q] = f->fmt.pix_mp;
 
        if (try)
@@ -744,6 +746,9 @@ static int imgu_fmt(struct imgu_device *imgu, unsigned int pipe, int node,
        else
                ret = imgu_css_fmt_set(&imgu->css, fmts, rects, pipe);
 
+       if (try || ret < 0)
+               *fmts[css_q] = fmt_backup;
+
        /* ret is the binary number in the firmware blob */
        if (ret < 0)
                goto out;