From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A71DDDB1; Thu, 13 Jun 2024 11:39:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718278784; cv=none; b=cgTOPHs5HHbTVYfhu9SfY6ceVyNsaa/rml+rvvhjkD/lr1fHtHQ4PBsk/27dMPnWaOw6yVyAhTN79CSjp2zcHPDxp904nAfNCBVyD1FPlCFv0uJsk0Ah/BhT6QHRkM/7kisEqMN0G/nMXH343ltm2Ql+VkvptZfNWB3odpkS6hM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718278784; c=relaxed/simple; bh=G4SS4Oga/bJUe6cYpG/YodASrvXM2dqk00TJs3/hmEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NT6rKqrNguWfi/qNnYTbyGua511XvxP8iBD/iqGj5Liny38aFtcjFhN/c2xIuc1vhQrCJEi2BdgLySDtV6JyeLlC449Ae4goOMsKiyMt0Rpm7ZisDl706wKE+Z+BMPhpd9hNKoeY4Xs3hwxMy6a8zil7eGX41Yk7HjiUZWTGhYY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oKAP3bru; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="oKAP3bru" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8486C2BBFC; Thu, 13 Jun 2024 11:39:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718278784; bh=G4SS4Oga/bJUe6cYpG/YodASrvXM2dqk00TJs3/hmEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oKAP3bruP/GENW0kkIbbZv6nS2F5GM3ZLW2tb+YmNaLOfgFexat0y3girO3edjBOi bsloxQca/OOKzqtFYKSGs4qMnEHVgcGBn9PoMY4S90DRVLphQgBIECYTvBQkACI4ha xJRvHDn+ot45Fs/mOOEykUvn6vyTVw8TWVLGhPsQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Justin Green , AngeloGioacchino Del Regno , CK Hu , Chun-Kuang Hu , Sasha Levin Subject: [PATCH 4.19 068/213] drm/mediatek: Add 0 size check to mtk_drm_gem_obj Date: Thu, 13 Jun 2024 13:31:56 +0200 Message-ID: <20240613113230.630996204@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240613113227.969123070@linuxfoundation.org> References: <20240613113227.969123070@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Justin Green [ Upstream commit 1e4350095e8ab2577ee05f8c3b044e661b5af9a0 ] Add a check to mtk_drm_gem_init if we attempt to allocate a GEM object of 0 bytes. Currently, no such check exists and the kernel will panic if a userspace application attempts to allocate a 0x0 GBM buffer. Tested by attempting to allocate a 0x0 GBM buffer on an MT8188 and verifying that we now return EINVAL. Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.") Signed-off-by: Justin Green Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: CK Hu Link: https://patchwork.kernel.org/project/dri-devel/patch/20240307180051.4104425-1-greenjustin@chromium.org/ Signed-off-by: Chun-Kuang Hu Signed-off-by: Sasha Levin --- drivers/gpu/drm/mediatek/mtk_drm_gem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c index b09a37a38e0ae..079df67892df5 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c @@ -26,6 +26,9 @@ static struct mtk_drm_gem_obj *mtk_drm_gem_init(struct drm_device *dev, size = round_up(size, PAGE_SIZE); + if (size == 0) + return ERR_PTR(-EINVAL); + mtk_gem_obj = kzalloc(sizeof(*mtk_gem_obj), GFP_KERNEL); if (!mtk_gem_obj) return ERR_PTR(-ENOMEM); -- 2.43.0