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: 13387529 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2DD1EED61A for ; Fri, 15 Sep 2023 18:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236464AbjIOSqZ (ORCPT ); Fri, 15 Sep 2023 14:46:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236964AbjIOSp4 (ORCPT ); Fri, 15 Sep 2023 14:45:56 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 936D52D5F; Fri, 15 Sep 2023 11:43:32 -0700 (PDT) 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] drm/gud: Use size_add() in call to struct_size() Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org 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;