From: Jacek Anaszewski <jacek.anaszewski@gmail.com>
To: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cc: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>,
Hans Verkuil <hans.verkuil@cisco.com>,
Sylwester Nawrocki <s.nawrocki@samsung.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH 07/13] media: s5p-jpeg: prevent buffer overflows
Date: Thu, 17 Oct 2024 12:34:28 +0200 [thread overview]
Message-ID: <48d9f9b4-8b28-f24b-c0bd-d899c59bd247@gmail.com> (raw)
In-Reply-To: <16ccf3d588665a5a0dda91cbb04374d6aea99ca6.1729074076.git.mchehab+huawei@kernel.org>
Hi Mauro,
On 10/16/24 12:22, Mauro Carvalho Chehab wrote:
> The current logic allows word to be less than 2. If this happens,
> there will be buffer overflows. Add extra checks to prevent it.
>
> While here, remove an unused word = 0 assignment.
>
> Fixes: 6c96dbbc2aa9 ("[media] s5p-jpeg: add support for 5433")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
> .../media/platform/samsung/s5p-jpeg/jpeg-core.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c b/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c
> index d2c4a0178b3c..1db4609b3557 100644
> --- a/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c
> +++ b/drivers/media/platform/samsung/s5p-jpeg/jpeg-core.c
> @@ -775,11 +775,14 @@ static void exynos4_jpeg_parse_decode_h_tbl(struct s5p_jpeg_ctx *ctx)
> (unsigned long)vb2_plane_vaddr(&vb->vb2_buf, 0) + ctx->out_q.sos + 2;
> jpeg_buffer.curr = 0;
>
> - word = 0;
> -
> if (get_word_be(&jpeg_buffer, &word))
> return;
> - jpeg_buffer.size = (long)word - 2;
> +
> + if (word < 2)
> + jpeg_buffer.size = 0;
> + else
> + jpeg_buffer.size = (long)word - 2;
> +
> jpeg_buffer.data += 2;
> jpeg_buffer.curr = 0;
>
> @@ -1058,6 +1061,7 @@ static int get_word_be(struct s5p_jpeg_buffer *buf, unsigned int *word)
> if (byte == -1)
> return -1;
> *word = (unsigned int)byte | temp;
> +
> return 0;
> }
>
> @@ -1145,7 +1149,7 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data *result,
> if (get_word_be(&jpeg_buffer, &word))
> break;
> length = (long)word - 2;
> - if (!length)
> + if (length <= 0)
> return false;
> sof = jpeg_buffer.curr; /* after 0xffc0 */
> sof_len = length;
> @@ -1176,7 +1180,7 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data *result,
> if (get_word_be(&jpeg_buffer, &word))
> break;
> length = (long)word - 2;
> - if (!length)
> + if (length <= 0)
> return false;
> if (n_dqt >= S5P_JPEG_MAX_MARKER)
> return false;
> @@ -1189,7 +1193,7 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data *result,
> if (get_word_be(&jpeg_buffer, &word))
> break;
> length = (long)word - 2;
> - if (!length)
> + if (length <= 0)
> return false;
> if (n_dht >= S5P_JPEG_MAX_MARKER)
> return false;
> @@ -1214,6 +1218,7 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data *result,
> if (get_word_be(&jpeg_buffer, &word))
> break;
> length = (long)word - 2;
> + /* No need to check underflows as skip() does it */
> skip(&jpeg_buffer, length);
> break;
> }
Seems reasonable.
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
--
Best regards,
Jacek Anaszewski
next prev parent reply other threads:[~2024-10-17 10:34 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-16 10:22 [PATCH 00/13] Media: fix several issues on drivers Mauro Carvalho Chehab
2024-10-16 10:22 ` [PATCH 01/13] media: v4l2-ctrls-api: fix error handling for v4l2_g_ctrl() Mauro Carvalho Chehab
2024-10-16 10:56 ` Hans Verkuil
2024-10-16 10:22 ` [PATCH 02/13] media: v4l2-tpg: prevent the risk of a division by zero Mauro Carvalho Chehab
2024-10-16 10:49 ` Hans Verkuil
2024-10-16 10:22 ` [PATCH 03/13] media: dvbdev: prevent the risk of out of memory access Mauro Carvalho Chehab
2024-10-16 10:22 ` [PATCH 04/13] media: dvb_frontend: don't play tricks with underflow values Mauro Carvalho Chehab
2024-10-16 10:22 ` [PATCH 05/13] media: mgb4: protect driver against spectre Mauro Carvalho Chehab
2024-10-16 11:59 ` Martin Tůma
2024-10-18 4:32 ` Mauro Carvalho Chehab
2024-10-18 11:21 ` Martin Tůma
2024-10-16 10:22 ` [PATCH 06/13] media: av7110: fix a spectre vulnerability Mauro Carvalho Chehab
2024-10-16 10:22 ` [PATCH 07/13] media: s5p-jpeg: prevent buffer overflows Mauro Carvalho Chehab
2024-10-17 10:34 ` Jacek Anaszewski [this message]
2024-10-16 10:22 ` [PATCH 08/13] media: ar0521: don't overflow when checking PLL values Mauro Carvalho Chehab
2024-10-16 12:57 ` Sakari Ailus
2024-10-16 10:22 ` [PATCH 09/13] media: cx24116: prevent overflows on SNR calculus Mauro Carvalho Chehab
2024-10-16 10:22 ` [PATCH 10/13] media: adv7604 prevent underflow condition when reporting colorspace Mauro Carvalho Chehab
2024-10-16 10:57 ` Hans Verkuil
2024-10-16 11:24 ` Mauro Carvalho Chehab
2024-10-16 11:58 ` Hans Verkuil
2024-10-18 5:01 ` Mauro Carvalho Chehab
2024-10-16 10:22 ` [PATCH 11/13] media: stb0899_algo: initialize cfr before using it Mauro Carvalho Chehab
2024-10-16 10:22 ` [PATCH 12/13] media: cec: extron-da-hd-4k-plus: don't use -1 as an error code Mauro Carvalho Chehab
2024-10-16 10:36 ` Hans Verkuil
2024-10-16 10:22 ` [PATCH 13/13] media: pulse8-cec: fix data timestamp at pulse8_setup() Mauro Carvalho Chehab
2024-10-16 10:40 ` Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48d9f9b4-8b28-f24b-c0bd-d899c59bd247@gmail.com \
--to=jacek.anaszewski@gmail.com \
--cc=andrzejtp2010@gmail.com \
--cc=hans.verkuil@cisco.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab+huawei@kernel.org \
--cc=s.nawrocki@samsung.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®