From patchwork Tue Sep 5 12:23:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maciej Purski X-Patchwork-Id: 9938537 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 527B66038C for ; Tue, 5 Sep 2017 12:23:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 444CC28991 for ; Tue, 5 Sep 2017 12:23:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 388F428985; Tue, 5 Sep 2017 12:23:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 915DA28973 for ; Tue, 5 Sep 2017 12:23:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750805AbdIEMXO (ORCPT ); Tue, 5 Sep 2017 08:23:14 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:58513 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750731AbdIEMXN (ORCPT ); Tue, 5 Sep 2017 08:23:13 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20170905122311euoutp02d4d99f8534e469451fcdde5c8e8ec17c~hdqKdEHFb2118121181euoutp02U; Tue, 5 Sep 2017 12:23:11 +0000 (GMT) Received: from eusmges5.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170905122310eucas1p19c2fe68c079a23739a295585e42437f2~hdqJ0K1Mn0738007380eucas1p1p; Tue, 5 Sep 2017 12:23:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges5.samsung.com (EUCPMTA) with SMTP id 09.BC.12743.E279EA95; Tue, 5 Sep 2017 13:23:10 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170905122309eucas1p15739d5191e6471e9bfc05aa32b334f2e~hdqJE24Yl0721207212eucas1p13; Tue, 5 Sep 2017 12:23:09 +0000 (GMT) X-AuditID: cbfec7f5-f79d06d0000031c7-dc-59ae972ef0f8 Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 8A.E4.18832.D279EA95; Tue, 5 Sep 2017 13:23:09 +0100 (BST) Received: from AMDC2075.DIGITAL.local ([106.120.51.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OVT00JQ23QHCZ50@eusync4.samsung.com>; Tue, 05 Sep 2017 13:23:09 +0100 (BST) From: Maciej Purski To: dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Cc: Inki Dae , Joonyoung Shim , Seung-Woo Kim , Kyungmin Park , David Airlie , Kukjin Kim , Krzysztof Kozlowski , Maciej Purski Subject: [PATCH] drm/exynos/hdmi: Fix unsafe list iteration Date: Tue, 05 Sep 2017 14:23:02 +0200 Message-id: <1504614182-1509-1-git-send-email-m.purski@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrBIsWRmVeSWpSXmKPExsWy7djPc7p609dFGqx7IWbRe+4kk8WVr+/Z LCbdn8Bi8eLeRRaL/sevmS3On9/AbnG26Q27xabH11gtZpzfx2Sx4OUtFosZk1+yOXB7bFrV ye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BhEYE8iUVLD7CC1DMLbGWSmLrlEVi9sIC1xPkFEENZBFQl1m5ZyQhi8wo4Sxxb 2AK1TE7i5rlO5gmM3AsYGVYxiqSWFuem5xYb6hUn5haX5qXrJefnbmIEhtS2Yz8372C8tDH4 EKMAB6MSDy9H1NpIIdbEsuLK3EOMEhzMSiK8ByavixTiTUmsrEotyo8vKs1JLT7EKM3BoiTO 27tndaSQQHpiSWp2ampBahFMlomDU6qBsX4+o+dOidcHVfLVKnIUbpp7Htt/jel06afEtcd2 f3dMPSLam7F/xZ7UjamSyYLdMbU35jdlzrNgc5zku+K0++GpG3wbauO9fVztH6+YVvLH5VWF WXjxzXr3sPvH/8XtO3X52Ysmg1fr7ea903qRxl1/8vNcjcty0QIZPc6svuK9FxhFUwpClViK MxINtZiLihMBLX6lNSUCAAA= X-CMS-MailID: 20170905122309eucas1p15739d5191e6471e9bfc05aa32b334f2e X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?TWFjaWVqIFB1cnNraRtTZWN1cml0eSAoVFApG1NhbXN1bmcg?= =?UTF-8?B?RWxlY3Ryb25pY3MbVHJhaW5lZSAoKQ==?= X-Global-Sender: =?UTF-8?B?TWFjaWVqIFB1cnNraRtTZWN1cml0eSAoVFApG1NhbXN1bmcg?= =?UTF-8?B?RWxlY3Ryb25pY3MbVHJhaW5lZSAoKQ==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTU=?= CMS-TYPE: 201P X-CMS-RootMailID: 20170905122309eucas1p15739d5191e6471e9bfc05aa32b334f2e X-RootMTR: 20170905122309eucas1p15739d5191e6471e9bfc05aa32b334f2e References: Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Function hdmi_mode_fixup() used bare list_for_each entry, which was unsafe and caused memory corruption detected by kasan. It now uses drm_for_each_connector_iter macro, which is now recommended by the documentation and safe. Signed-off-by: Maciej Purski --- drivers/gpu/drm/exynos/exynos_hdmi.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_hdmi.c b/drivers/gpu/drm/exynos/exynos_hdmi.c index 214fa5e..0109ff4 100644 --- a/drivers/gpu/drm/exynos/exynos_hdmi.c +++ b/drivers/gpu/drm/exynos/exynos_hdmi.c @@ -944,22 +944,27 @@ static bool hdmi_mode_fixup(struct drm_encoder *encoder, struct drm_device *dev = encoder->dev; struct drm_connector *connector; struct drm_display_mode *m; + struct drm_connector_list_iter conn_iter; int mode_ok; drm_mode_set_crtcinfo(adjusted_mode, 0); - list_for_each_entry(connector, &dev->mode_config.connector_list, head) { + drm_connector_list_iter_begin(dev, &conn_iter); + drm_for_each_connector_iter(connector, &conn_iter) { if (connector->encoder == encoder) break; } + if (connector) + drm_connector_get(connector); + drm_connector_list_iter_end(&conn_iter); - if (connector->encoder != encoder) + if (!connector) return true; mode_ok = hdmi_mode_valid(connector, adjusted_mode); if (mode_ok == MODE_OK) - return true; + goto cleanup; /* * Find the most suitable mode and copy it to adjusted_mode. @@ -979,6 +984,9 @@ static bool hdmi_mode_fixup(struct drm_encoder *encoder, } } +cleanup: + drm_connector_put(connector); + return true; }