From patchwork Thu Aug 10 08:23:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Chen X-Patchwork-Id: 133881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp335700vqi; Thu, 10 Aug 2023 04:04:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSzEXQTSS+udXKFEmcAxNyg6gm5155lAF0nJZVw/9zq5yhTQLQs76UfzO+kxZ+0pGzI6lu X-Received: by 2002:a05:6870:61d0:b0:1b0:649f:e68a with SMTP id b16-20020a05687061d000b001b0649fe68amr2303328oah.25.1691665469955; Thu, 10 Aug 2023 04:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691665469; cv=none; d=google.com; s=arc-20160816; b=zlpvhx2XekkB+skwIrpJgd1AJ6w+7FXdBY515RceKa1RQxR0TU4atyv6MQbY4v1oDR 6gKdTlUegAM0nv9VyjTr505wREqe1m2alhU+qgatLMzKg113zJDaJWqspKg+qj7qDjuG izbzGw1Evs5YPnr2PM2SF4lrGGXAxEj4L03j+5f+NDRnUodm3c+Mlh9O8w1sXFWu+xNK clccCE4JKhYsNPO/XPTTdtWnHn5mO8x4HiL/otRc6R7U9LHE+OcP91YfMR1Ht4R91ECk Ad98V3HK879CORsvt0qgxRFcRHkgTnHrl2KCQdPXsU/ITn/zjhDU6IlcfHpeFo2j9xd2 /CMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+e1KIdPkZ9W1pyyhd0vEg/XdGpbw4lhXOUhvTsBhFP8=; fh=gvvSaz70YhmGJphtB9zit/cdx/Usmhp83+Eo6lyG8bw=; b=s0LIldqisa+GxlYeKixkOUn2HO4vqDpMvKSAoapjTiDvUE8A7qlomup3AcWtG3Yekn M3wN+AHeHbmkVE9JOWXDP3rpedJz/wzCNTYkGpSEPnZTzdeWYM7jsMAgeXws2+4gihL0 DiZiA1M5Ctm3YKXftztVltsLT8Zzo8XS0xZkdAqQDrJCdQZS8C48Fm1v4oMirIonexJt aFcOkvTQdjTDrL+Z2kbe8PcWTazlID5oY37KJlnw4kFFGtGl00gZsZeXBo/+mSNNSyvR EISgCFfvMT6g7oaw6PjfK+oBu2lkf7wLgwFbAZIms/2Yw4539+u7573hRjq6dBqk7wrC ZSnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=TTOA9ZLE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g28-20020a63565c000000b0056513361b4fsi1363145pgm.741.2023.08.10.04.04.14; Thu, 10 Aug 2023 04:04:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=TTOA9ZLE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234187AbjHJIX5 (ORCPT + 99 others); Thu, 10 Aug 2023 04:23:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234188AbjHJIXm (ORCPT ); Thu, 10 Aug 2023 04:23:42 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6072BDC; Thu, 10 Aug 2023 01:23:41 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-26929bf95b6so367737a91.3; Thu, 10 Aug 2023 01:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691655821; x=1692260621; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+e1KIdPkZ9W1pyyhd0vEg/XdGpbw4lhXOUhvTsBhFP8=; b=TTOA9ZLE7hKSMCbIwQzADz/+r4wuL4LTp2U75XuUd+F7tqRVer2IsUqHdhUTm4I+7e EQ8T8tV3MIvU4c6sNRhK1SsTSBMh1WlNdCP6IDXwOo+G3Eo3XzfSoVGb1TuIUDM66Zx1 phsMLiRCjyZ8YUolNzCy6Je0WdBvVU+G4uZOYQmzc28zHPObIPykgnsBXcDN+SLHqDXC eu6yvHjG8KUj5jEjr3/l1NjOgT99tm3j7cGCYJonYBPcpiQVgIkwRGuEsYrtBPLTk4bV gIlwQebmAvJq8O77JKv26Nws533bFZAx/UULe9hmAWRaOWc4EQ0YSwJERc77jZjot+2D 9RWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691655821; x=1692260621; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+e1KIdPkZ9W1pyyhd0vEg/XdGpbw4lhXOUhvTsBhFP8=; b=QgK0jSHYm5fVc4aqS/hOTy4Hr0rOCRTlGEGBB8rdvwXw6QApU1O1G9zsIETAeisyC2 Lk6cPfzCsAxasLWkxlw8SLcgjwTvjf6m8ljLbXTIp0GV4c81YUNj4P1GPbnSqyXok9YJ i2MddY5hE9ft9l/X61uGAmd3IwlwNmNtJ8yoWOHAQ45b7b32c7KVvVgeMWNZfHeRzXOq t+m7zXLabyThLSuLDdofmJBW/4rX3w8kjPl5bXpma31olCnTYp3KIgnHyMqXMYUUrtpW Vpj/fa3+3EHK8hwY8c5xevdol++o13bg2ZQ31/ZuxPKRrWtepF1JzdQCpN71T/VPzu41 UYfA== X-Gm-Message-State: AOJu0Yy3bsGyRekfa0PiNS2DtLqGHgp2k/hNlCsMhiSEfuWd5C/pKXO0 SNHFvoIzbk/I2hN9xUD+jSuG9rEkrsfiVE5B X-Received: by 2002:a17:90a:384a:b0:268:2b5c:14c with SMTP id l10-20020a17090a384a00b002682b5c014cmr1384067pjf.13.1691655820696; Thu, 10 Aug 2023 01:23:40 -0700 (PDT) Received: from chcpu13.cse.ust.hk (191host119.mobilenet.cse.ust.hk. [143.89.191.119]) by smtp.gmail.com with ESMTPSA id y7-20020a17090a2b4700b0025dc5749b4csm2772243pjc.21.2023.08.10.01.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 01:23:40 -0700 (PDT) From: Wei Chen To: tiffany.lin@mediatek.com Cc: andrew-ct.chen@mediatek.com, yunfei.dong@mediatek.com, mchehab@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Wei Chen , stable@vger.kernel.org Subject: [PATCH v2] media: vcodec: Fix potential array out-of-bounds in encoder queue_setup Date: Thu, 10 Aug 2023 08:23:33 +0000 Message-Id: <20230810082333.972165-1-harperchen1110@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773832599755253999 X-GMAIL-MSGID: 1773839811618617289 variable *nplanes is provided by user via system call argument. The possible value of q_data->fmt->num_planes is 1-3, while the value of *nplanes can be 1-8. The array access by index i can cause array out-of-bounds. Fix this bug by checking *nplanes against the array size. Fixes: 4e855a6efa54 ("[media] vcodec: mediatek: Add Mediatek V4L2 Video Encoder Driver") Signed-off-by: Wei Chen Cc: stable@vger.kernel.org --- Changes in v2: - Add Fixes tag and CC stable email address - Change the title to be more expressive drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c index 9ff439a50f53..9e8817863cb8 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c @@ -821,6 +821,8 @@ static int vb2ops_venc_queue_setup(struct vb2_queue *vq, return -EINVAL; if (*nplanes) { + if (*nplanes != q_data->fmt->num_planes) + return -EINVAL; for (i = 0; i < *nplanes; i++) if (sizes[i] < q_data->sizeimage[i]) return -EINVAL;