From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=79.135.106.26 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795220050; b=tKHXvBsaN2SX/w9AuCAhTGZDI0IoOVlbShekZDl/2SV2PT1WnuhsTVEbOBAZgMkpSaze pd8Ff4cJ59ZNg0Dk51lRFvhqZsQaCEEN4YBFZvSEvWvkjZ5RsrCjFoaFL8StxaQSNw206 vh2pCG+STMuY/CRDy47MHkpOyYBhzbo6KPUHEyYEYccQkc1OR1Bp+AjQKC9g0pjE9SAx8 cM6kAvWihXfyEz7NGVoQojppzu0M0w9jyugPQQpvLw5u2q1Df9Z9/7sL1foFdYy8IbQZB A+MkvStLHq4l8m8bBIYsq651y4k08rDrnex32+7ys8pMHv04ahtP2Gr0qEPxBODlKMw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795220050; h=DMARC-Filter:DKIM-Signature:Date:To:From:Subject:Message-ID: Feedback-ID:X-Pm-Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=K1CXcByfNOHhANa/Finumg+sufhb3wPGR1vQBaCQ6XY=; b=5GoHzoziErClm9esnXvD7+hRQmXUra3syVaox8n9ddha+7PmVNRSw0Rg2TKiCqKPwIw7 HuDp3jjTDG7bWO/UYaYA4U9eZ4PVlM8UFxvz4ktpda6jk/rXFfHXukravVKxHhVlvOVyS NX+i2z2mw5u6wzjZ1CfI117y/3VHCoZz4mxJL2kxctCARBgoSMTf5Ak57uJ5HhVPOX93N 5sE7pPPRq0kTBRgAKfr7q0Lb2cAmJvFh0gEu/Uul+sUjwpyYOy7bQzmahi19jaLb06FSx Z1hhCiv8+qhDB2G+/hvOVFNhmv7DFbkxV6sYZPKEmd3xDHd2uZ9iGZCgYWyll8w5W8g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=innora.ai; spf=pass smtp.mailfrom=innora.ai; dkim=pass header.d=innora.ai header.i=@innora.ai header.a=rsa-sha256 header.s=protonmail3 header.b=aC3HZKrs; arc=none smtp.remote-ip=79.135.106.26 Received: from mail-10626.protonmail.ch (mail-10626.protonmail.ch [79.135.106.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B34E6606A68C for ; Sat, 21 Nov 2026 00:14:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B34E6606A68C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=innora.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=innora.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=innora.ai header.i=@innora.ai header.a=rsa-sha256 header.s=protonmail3 header.b=aC3HZKrs DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=innora.ai; s=protonmail3; t=1795220044; x=1795479244; bh=K1CXcByfNOHhANa/Finumg+sufhb3wPGR1vQBaCQ6XY=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=aC3HZKrsMHa96/kXIu7A3U6mIMvrg5gsvlzoubuVuTYVw++llbaMAmlHI9aD6jJMX CDnpcHWUFhwbG+x6cNH0WM9f58x9C30Rb9CAFq6wLWUR8aniKs4+dI9INY3ju1lml2 6YZjRjAR7RaklmHkiOBBDjOASFZ9O5+hJFI4xrtzy0lc5Dz/FP0ydRyCqTPam+s2LZ KvnQ3wYHSKQv6J73G75wKm+Mxnja45Pa0TP41vVlMshlgAMdNgdqn6E+KzfDeAlOUg Dm+fzGGA6Lgr2cgn7kL0n2/xOxcuMKsbUOiAmb2mUYTxk/M0MXybjz/u0LLfP0xChm JQfgXCS/txPZQ== Date: Sat, 21 Nov 2026 00:14:01 +0000 To: stable@vger.kernel.org From: Feng Ning Subject: [PATCH 6.6.y] staging: media: atomisp: use array3_size() for overflow-safe allocation Message-ID: <0efc2ac848204586b6050047ce89a85f@innora.ai> Feedback-ID: 140578448:user:proton X-Pm-Message-ID: 94c569053de474a067fa1811892bdffa044fd3d8 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [ Upstream commit d178c7ca8fefc28115d35b94c3b1f4d653e34182 ] Replace open-coded width * height * sizeof() multiplications with array3_size() to prevent integer overflow in buffer allocations. The atomisp driver computes DVS, morphing table, shading table and statistics buffer sizes using unchecked arithmetic. When the table dimensions are large, the product can silently wrap, causing kvmalloc() to allocate an undersized buffer. array3_size() saturates to SIZE_MAX on overflow, so kvmalloc() returns NULL instead of succeeding with too few bytes. Backport note: these three files do not include in this tree yet, so the include is added here. No other changes were made. Signed-off-by: Feng Ning Signed-off-by: Sakari Ailus --- diff --git a/drivers/staging/media/atomisp/pci/sh_css_param_dvs.c b/drivers= /staging/media/atomisp/pci/sh_css_param_dvs.c index 5174bc210..87d35aede 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_param_dvs.c +++ b/drivers/staging/media/atomisp/pci/sh_css_param_dvs.c @@ -13,6 +13,8 @@ * more details. */ =20 +#include + #include "sh_css_param_dvs.h" #include #include @@ -58,7 +60,7 @@ alloc_dvs_6axis_table(const struct ia_css_resolution *fra= me_res, =09=09} =20 =09=09/* Generate Y buffers */ -=09=09dvs_config->xcoords_y =3D kvmalloc(width_y * height_y * sizeof(uint3= 2_t), +=09=09dvs_config->xcoords_y =3D kvmalloc(array3_size(width_y, height_y, si= zeof(uint32_t)), =09=09=09=09=09=09 GFP_KERNEL); =09=09if (!dvs_config->xcoords_y) { =09=09=09IA_CSS_ERROR("out of memory"); @@ -66,7 +68,7 @@ alloc_dvs_6axis_table(const struct ia_css_resolution *fra= me_res, =09=09=09goto exit; =09=09} =20 -=09=09dvs_config->ycoords_y =3D kvmalloc(width_y * height_y * sizeof(uint3= 2_t), +=09=09dvs_config->ycoords_y =3D kvmalloc(array3_size(width_y, height_y, si= zeof(uint32_t)), =09=09=09=09=09=09 GFP_KERNEL); =09=09if (!dvs_config->ycoords_y) { =09=09=09IA_CSS_ERROR("out of memory"); @@ -77,7 +79,8 @@ alloc_dvs_6axis_table(const struct ia_css_resolution *fra= me_res, =09=09/* Generate UV buffers */ =09=09IA_CSS_LOG("UV W %d H %d", width_uv, height_uv); =20 -=09=09dvs_config->xcoords_uv =3D kvmalloc(width_uv * height_uv * sizeof(ui= nt32_t), +=09=09dvs_config->xcoords_uv =3D kvmalloc(array3_size(width_uv, height_uv, +=09=09=09=09=09=09=09 sizeof(uint32_t)), =09=09=09=09=09=09 GFP_KERNEL); =09=09if (!dvs_config->xcoords_uv) { =09=09=09IA_CSS_ERROR("out of memory"); @@ -85,7 +88,8 @@ alloc_dvs_6axis_table(const struct ia_css_resolution *fra= me_res, =09=09=09goto exit; =09=09} =20 -=09=09dvs_config->ycoords_uv =3D kvmalloc(width_uv * height_uv * sizeof(ui= nt32_t), +=09=09dvs_config->ycoords_uv =3D kvmalloc(array3_size(width_uv, height_uv, +=09=09=09=09=09=09=09 sizeof(uint32_t)), =09=09=09=09=09=09 GFP_KERNEL); =09=09if (!dvs_config->ycoords_uv) { =09=09=09IA_CSS_ERROR("out of memory"); diff --git a/drivers/staging/media/atomisp/pci/sh_css_param_shading.c b/dri= vers/staging/media/atomisp/pci/sh_css_param_shading.c index 5b43cc656..35dce0d44 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_param_shading.c +++ b/drivers/staging/media/atomisp/pci/sh_css_param_shading.c @@ -13,6 +13,8 @@ * more details. */ =20 +#include + #include #include =20 @@ -348,7 +350,8 @@ ia_css_shading_table_alloc( =09me->fraction_bits =3D 0; =09for (i =3D 0; i < IA_CSS_SC_NUM_COLORS; i++) { =09=09me->data[i] =3D -=09=09 kvmalloc(width * height * sizeof(*me->data[0]), +=09=09 kvmalloc(array3_size(width, height, +=09=09=09=09=09 sizeof(*me->data[0])), =09=09=09 GFP_KERNEL); =09=09if (!me->data[i]) { =09=09=09unsigned int j; diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/st= aging/media/atomisp/pci/sh_css_params.c index 760fe9bef..57071c6c3 100644 --- a/drivers/staging/media/atomisp/pci/sh_css_params.c +++ b/drivers/staging/media/atomisp/pci/sh_css_params.c @@ -13,6 +13,8 @@ * more details. */ =20 +#include + #include "gdc_device.h"=09=09/* gdc_lut_store(), ... */ #include "isp.h"=09=09=09/* ISP_VEC_ELEMBITS */ #include "vamem.h" @@ -1390,11 +1392,11 @@ struct ia_css_morph_table *ia_css_morph_table_alloc= ate( =09} =20 =09for (i =3D 0; i < IA_CSS_MORPH_TABLE_NUM_PLANES; i++) { -=09=09me->coordinates_x[i] =3D kvmalloc(height * width * -=09=09=09=09=09=09sizeof(*me->coordinates_x[i]), +=09=09me->coordinates_x[i] =3D kvmalloc(array3_size(height, width, +=09=09=09=09=09=09=09 sizeof(*me->coordinates_x[i])), =09=09=09=09=09=09GFP_KERNEL); -=09=09me->coordinates_y[i] =3D kvmalloc(height * width * -=09=09=09=09=09=09sizeof(*me->coordinates_y[i]), +=09=09me->coordinates_y[i] =3D kvmalloc(array3_size(height, width, +=09=09=09=09=09=09=09 sizeof(*me->coordinates_y[i])), =09=09=09=09=09=09GFP_KERNEL); =20 =09=09if ((!me->coordinates_x[i]) || @@ -4178,13 +4180,17 @@ ia_css_dvs_statistics_allocate(const struct ia_css_= dvs_grid_info *grid) =09=09goto err; =20 =09me->grid =3D *grid; -=09me->hor_proj =3D kvmalloc(grid->height * IA_CSS_DVS_NUM_COEF_TYPES * -=09=09=09=09sizeof(*me->hor_proj), GFP_KERNEL); +=09me->hor_proj =3D kvmalloc(array3_size(grid->height, +=09=09=09=09=09 IA_CSS_DVS_NUM_COEF_TYPES, +=09=09=09=09=09=09sizeof(*me->hor_proj)), +=09=09=09=09GFP_KERNEL); =09if (!me->hor_proj) =09=09goto err; =20 -=09me->ver_proj =3D kvmalloc(grid->width * IA_CSS_DVS_NUM_COEF_TYPES * -=09=09=09=09sizeof(*me->ver_proj), GFP_KERNEL); +=09me->ver_proj =3D kvmalloc(array3_size(grid->width, +=09=09=09=09=09 IA_CSS_DVS_NUM_COEF_TYPES, +=09=09=09=09=09=09sizeof(*me->ver_proj)), +=09=09=09=09GFP_KERNEL); =09if (!me->ver_proj) =09=09goto err; =20 @@ -4451,24 +4457,26 @@ ia_css_dvs2_6axis_config_allocate(const struct ia_c= ss_stream *stream) =09=09=09=09 params->pipe_dvs_6axis_config[IA_CSS_PIPE_ID_VIDEO]->heigh= t_uv; =09IA_CSS_LOG("table Y: W %d H %d", width_y, height_y); =09IA_CSS_LOG("table UV: W %d H %d", width_uv, height_uv); -=09dvs_config->xcoords_y =3D kvmalloc(width_y * height_y * sizeof(uint32_t= ), +=09dvs_config->xcoords_y =3D kvmalloc(array3_size(width_y, height_y, +=09=09=09=09=09=09 sizeof(uint32_t)), =09=09=09=09=09 GFP_KERNEL); =09if (!dvs_config->xcoords_y) =09=09goto err; =20 -=09dvs_config->ycoords_y =3D kvmalloc(width_y * height_y * sizeof(uint32_t= ), +=09dvs_config->ycoords_y =3D kvmalloc(array3_size(width_y, height_y, +=09=09=09=09=09=09 sizeof(uint32_t)), =09=09=09=09=09 GFP_KERNEL); =09if (!dvs_config->ycoords_y) =09=09goto err; =20 -=09dvs_config->xcoords_uv =3D kvmalloc(width_uv * height_uv * -=09=09=09=09=09 sizeof(uint32_t), +=09dvs_config->xcoords_uv =3D kvmalloc(array3_size(width_uv, height_uv, +=09=09=09=09=09=09 sizeof(uint32_t)), =09=09=09=09=09 GFP_KERNEL); =09if (!dvs_config->xcoords_uv) =09=09goto err; =20 -=09dvs_config->ycoords_uv =3D kvmalloc(width_uv * height_uv * -=09=09=09=09=09 sizeof(uint32_t), +=09dvs_config->ycoords_uv =3D kvmalloc(array3_size(width_uv, height_uv, +=09=09=09=09=09=09 sizeof(uint32_t)), =09=09=09=09=09 GFP_KERNEL); =09if (!dvs_config->ycoords_uv) =09=09goto err; --=20 2.43.0