Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp76766rwi; Wed, 2 Nov 2022 09:29:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM77XajfR+byl3XZpTNyvrMfx+SvJPHfbnMyYRF5TuvLroYbJnqm0nunzM6zPwpmF1AFrB/s X-Received: by 2002:a17:902:d64d:b0:186:634e:5517 with SMTP id y13-20020a170902d64d00b00186634e5517mr25424790plh.3.1667406565339; Wed, 02 Nov 2022 09:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667406565; cv=none; d=google.com; s=arc-20160816; b=dzbM6opjIUk0HuxxsRVBboO7OpIpgeHCCRq1id+rSS2CrNeoy7/heG4d+g2xShA02C +bngoSd2iso77ixu8T/i8M83FhYs79CzoZclLD/Opw8BRJQvFJe5MOAH2/uIIEeK/Js7 37AIu66l05ojj7zxQpEEYH1E0MxEYpZWKVjc7amIWwznvLyll1+ZlSd++zQVs9dd7c/+ koc72ghYIxHJG5vcmEV4CxniDY5v47HZNSrIwjaqR6BpGv+HioRefIGAcmLmnTMUbW5q bEYvz9Q7Esm9ksuovisaFqTUguv5FfDe5SmJ8SQf5S/qiU6AnhT+gF8DTjE29Cu7MwVY inZw== 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=VKlBMFIVE43BlycfBfmggWALRJ7ZosfBFIYwuDrNnzE=; b=QtQvKhcjsK3hjV/tIf9aZUfpbNusWT5yQtDs3hF1XlG0KHhe/SiI9XMmX9XtK/kUtQ H3aoINBz6xbJH6mp1xBgmtSDQx9avBzFxfHpt8BvNvR90Eb5rO/+htGzzaNpLXxrwbeD dXs7J1aC03A6jHDXvKFe0toHpP3dlTQJC1stYzaqoYG6oKpU3J4AXLfzhjvBRdmnNens zptrDhYjhbfdyKWzeDg22DjuS6AyjaNu+Kplx/aTbNs48LpncwAxkvz/3jx6FeA5QhB9 2q2POjBfq48k4Ltn97Fy/xxm8o63+r+NaA0IxCL5/p7604rN1giYeOPxPspdP0FJJbne V4cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QEeIJzQh; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 189-20020a6205c6000000b005480167b913si14033398pff.282.2022.11.02.09.28.38; Wed, 02 Nov 2022 09:29:25 -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=@kernel.org header.s=k20201202 header.b=QEeIJzQh; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230518AbiKBP4s (ORCPT + 99 others); Wed, 2 Nov 2022 11:56:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbiKBP4q (ORCPT ); Wed, 2 Nov 2022 11:56:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C24572A70A for ; Wed, 2 Nov 2022 08:56:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6934461458 for ; Wed, 2 Nov 2022 15:56:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37357C433C1; Wed, 2 Nov 2022 15:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667404604; bh=eKbd97vkxuefqY9NLXZOBScngwsvyodqrMGr4osaqpM=; h=From:To:Cc:Subject:Date:From; b=QEeIJzQhBQ0ln9r6jspxi/JHuDxERVJXeR34L8KMxzb/iBI3vxKYohDDJ5qi0SYMh 5birGEcLTZ8O9M+cAd5L5Ya9X0cQ8d/Yc2lBgAYQXjjoi4gcu5d5ocS8PCOoBmYASQ dESAVUO0KimN/Y9WfRtKkArsURnmszVYxZRDWnNUJObyvmCZNSPnvOD6EMl4UUHQnM iisuG7rROiDFJoYFAN3n0/3hrDkgL3OHXAxZpxJaBCQJ3Q+mU4Imo/pQFFQuAYLinl +RbZdgAhoCLLG+O0WCsb/0mva65O5md/nL4ajIjRqRyePp2bYtSPQoyasJZUIOoFsi 6SzHRb+oEOGsQ== From: Nathan Chancellor To: Alain Volmat Cc: dri-devel@lists.freedesktop.org, Nick Desaulniers , Tom Rix , Kees Cook , Sami Tolvanen , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Nathan Chancellor Subject: [PATCH] drm/sti: Fix return type of sti_{dvo,hda,hdmi}_connector_mode_valid() Date: Wed, 2 Nov 2022 08:56:23 -0700 Message-Id: <20221102155623.3042869-1-nathan@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals: drivers/gpu/drm/sti/sti_hda.c:637:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict] .mode_valid = sti_hda_connector_mode_valid, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/sti/sti_dvo.c:376:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict] .mode_valid = sti_dvo_connector_mode_valid, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/sti/sti_hdmi.c:1035:16: error: incompatible function pointer types initializing 'enum drm_mode_status (*)(struct drm_connector *, struct drm_display_mode *)' with an expression of type 'int (struct drm_connector *, struct drm_display_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict] .mode_valid = sti_hdmi_connector_mode_valid, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ->mode_valid() in 'struct drm_connector_helper_funcs' expects a return type of 'enum drm_mode_status', not 'int'. Adjust the return type of sti_{dvo,hda,hdmi}_connector_mode_valid() to match the prototype's to resolve the warning and CFI failure. Link: https://github.com/ClangBuiltLinux/linux/issues/1750 Signed-off-by: Nathan Chancellor --- drivers/gpu/drm/sti/sti_dvo.c | 5 +++-- drivers/gpu/drm/sti/sti_hda.c | 5 +++-- drivers/gpu/drm/sti/sti_hdmi.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/sti/sti_dvo.c b/drivers/gpu/drm/sti/sti_dvo.c index b6ee8a82e656..076d5f30a09c 100644 --- a/drivers/gpu/drm/sti/sti_dvo.c +++ b/drivers/gpu/drm/sti/sti_dvo.c @@ -346,8 +346,9 @@ static int sti_dvo_connector_get_modes(struct drm_connector *connector) #define CLK_TOLERANCE_HZ 50 -static int sti_dvo_connector_mode_valid(struct drm_connector *connector, - struct drm_display_mode *mode) +static enum drm_mode_status +sti_dvo_connector_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) { int target = mode->clock * 1000; int target_min = target - CLK_TOLERANCE_HZ; diff --git a/drivers/gpu/drm/sti/sti_hda.c b/drivers/gpu/drm/sti/sti_hda.c index 03cc401ed593..a53b5a15c2a9 100644 --- a/drivers/gpu/drm/sti/sti_hda.c +++ b/drivers/gpu/drm/sti/sti_hda.c @@ -601,8 +601,9 @@ static int sti_hda_connector_get_modes(struct drm_connector *connector) #define CLK_TOLERANCE_HZ 50 -static int sti_hda_connector_mode_valid(struct drm_connector *connector, - struct drm_display_mode *mode) +static enum drm_mode_status +sti_hda_connector_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) { int target = mode->clock * 1000; int target_min = target - CLK_TOLERANCE_HZ; diff --git a/drivers/gpu/drm/sti/sti_hdmi.c b/drivers/gpu/drm/sti/sti_hdmi.c index cb82622877d2..09e0cadb6368 100644 --- a/drivers/gpu/drm/sti/sti_hdmi.c +++ b/drivers/gpu/drm/sti/sti_hdmi.c @@ -1004,8 +1004,9 @@ static int sti_hdmi_connector_get_modes(struct drm_connector *connector) #define CLK_TOLERANCE_HZ 50 -static int sti_hdmi_connector_mode_valid(struct drm_connector *connector, - struct drm_display_mode *mode) +static enum drm_mode_status +sti_hdmi_connector_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) { int target = mode->clock * 1000; int target_min = target - CLK_TOLERANCE_HZ; base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780 -- 2.38.1