From patchwork Fri Sep 15 18:43:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13387486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4B93EED62A for ; Fri, 15 Sep 2023 18:42:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BD5210E675; Fri, 15 Sep 2023 18:42:31 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1BD9A10E677 for ; Fri, 15 Sep 2023 18:42:29 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 850E1B82F65; Fri, 15 Sep 2023 18:42:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46BA0C433C7; Fri, 15 Sep 2023 18:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694803346; bh=gNFALD/z17jDo7dWYiHKFKrb9ITT5wkuRQ8TLtfc84k=; h=Date:From:To:Cc:Subject:From; b=XFdl61V6dPWFIZAe1SZcvAqCiTByQo6msIs/RunUOGVbM+9UmWtKYpGeybnSZ8SOf XuiSlgD5sCBzwnqHs7ik7/vc5/PTkdlj0EPs8VmgAdpMuq87WmrxvUSxaQxMJH+iaT qiJRPa3lgh0bTwDxTfqf3UmfuUA2yjEcq6afHwUcZY2nlqnkgGZ6Vq3J9s4iw0kVpa inOeiOkkHnuWQnLsGOlzfTemYM6cdxxwkgNAT12dU+bAf7hl+xs3f21SDfO4ENO9Fu eYlxuGC0AAFoNB38MzF0yTAwrmcxgyZuFuSOX5PmOr04cb3YiUORxnc5AqRRUaKlHk x17yPmOSkJiuA== Date: Fri, 15 Sep 2023 12:43:20 -0600 From: "Gustavo A. R. Silva" To: Noralf =?iso-8859-1?q?Tr=F8nnes?= , David Airlie , Daniel Vetter , Peter Stuge Subject: [PATCH][next] drm/gud: Use size_add() in call to struct_size() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "Gustavo A. R. Silva" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" If, for any reason, the open-coded arithmetic causes a wraparound, the protection that `struct_size()` adds against potential integer overflows is defeated. Fix this by hardening call to `struct_size()` with `size_add()`. Fixes: 40e1a70b4aed ("drm: Add GUD USB Display driver") Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/gpu/drm/gud/gud_pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c index d2f199ea3c11..a02f75be81f0 100644 --- a/drivers/gpu/drm/gud/gud_pipe.c +++ b/drivers/gpu/drm/gud/gud_pipe.c @@ -503,7 +503,7 @@ int gud_pipe_check(struct drm_simple_display_pipe *pipe, return -ENOENT; len = struct_size(req, properties, - GUD_PROPERTIES_MAX_NUM + GUD_CONNECTOR_PROPERTIES_MAX_NUM); + size_add(GUD_PROPERTIES_MAX_NUM, GUD_CONNECTOR_PROPERTIES_MAX_NUM)); req = kzalloc(len, GFP_KERNEL); if (!req) return -ENOMEM;