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 89ABF12C81F; Thu, 13 Jun 2024 12:33:23 +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=1718282003; cv=none; b=O8wgP1Hvb/hsT1pg2W8zq+lbx2uSIKjXTGsZLYb+ngAtnW0CmjjFwOusoNkb3eQQBEvMfCejVDBy0f6Jo6774HzUqVf7Q8TaoCmWbWsMn8Nddwb6Keq+QYIvXnm6MdZikT4jmBvhrHFw44d544cdQoJmhvXpkHgMKt3fT2Qspe4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718282003; c=relaxed/simple; bh=GB4FgU0RZ7+SVJ+IL1DcZvP9fi16DeyoiXS5Q2nQX90=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d5hJV2RKDNxJdPh+3pJTk0J2EhXwEV83pl0zHggqkMoUnQ1DwMZYaJjfuRScHW6M6gMX3LZWtR1kP5HebWYvDY9eZYLGR6E4+r+9F0ttte8kRs+RAI/BX1i7LBRBW/bHEY2dxeDRYt6YXUdkNrHI3L/FeW+GFukktYHk9oBtMOs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PfcB3P0i; 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="PfcB3P0i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12000C2BBFC; Thu, 13 Jun 2024 12:33:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718282003; bh=GB4FgU0RZ7+SVJ+IL1DcZvP9fi16DeyoiXS5Q2nQX90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PfcB3P0i9pLcr6oF2Ll2QR+0J1wf0CasEiWMLLIySMLM9UBmBUi8nCUK9q8d75u0i BEpJdES8oUDfapSgIUf7aE96rb76K2NTfsVfOTzpcsJa7YhTAicFTcEjK1e8RJdE+V KDCg7qbD2o51k5UNBihkYaxP7mLb5xBfkeXpxzU4= 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 5.15 130/402] drm/mediatek: Add 0 size check to mtk_drm_gem_obj Date: Thu, 13 Jun 2024 13:31:27 +0200 Message-ID: <20240613113307.210472867@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240613113302.116811394@linuxfoundation.org> References: <20240613113302.116811394@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-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 b983adffa3929..88bdb8eeba81a 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c @@ -33,6 +33,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