From patchwork Mon Mar 11 21:01:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10848301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E580D139A for ; Mon, 11 Mar 2019 21:01:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC0972938A for ; Mon, 11 Mar 2019 21:01:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA0CA292D9; Mon, 11 Mar 2019 21:01:28 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6A7A729396 for ; Mon, 11 Mar 2019 21:01:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 373A889AA6; Mon, 11 Mar 2019 21:01:26 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by gabe.freedesktop.org (Postfix) with ESMTPS id 042A389AA6 for ; Mon, 11 Mar 2019 21:01:25 +0000 (UTC) Received: by mail-qt1-x844.google.com with SMTP id u7so177993qtg.9 for ; Mon, 11 Mar 2019 14:01:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=mwG+zHmuCaPJeXwYvKvLlC56+W7HMjxMgIZATYB69fo=; b=FuqcoYYBQi193iOYk2N+krQ2pmdIePoPe8vpu4RpNrro1x7/Ts4BBS6+Wz8cNr8ovG xdoV2XpKE5YuoESKAlEo7VB+xSvEHw1tHguGCjAjjbLPzAsC+T8QKacs5pB1vkXOGJyv kHUxoBRLk7IoE22WDbyNS47QDMsfXpRfeKVwb9vwdbkx9VIz67+pFU5XUL1JVjnn5TqL eE9dPhzdLGP4Q+OX0KNPQQumAMFr3+vJ08gEcEHNwdOivFzueCQd1oCLE27gWXVJcG1r EDqUr1SqmXhIxgd59renbS+0glMJ0E8/tqb8z8N/6b4E3yy8C4L8R3rYeztSwCLerJ1A ucdQ== X-Gm-Message-State: APjAAAVwbQZIP+UfDoNazkQLqxk+xipeCUo9fkV1N+oD1i2GEz0qbToc IXi5U70gjyZR5S1zD5KWtS0= X-Google-Smtp-Source: APXvYqxfvf7pB1CmraKzqEDgZYhqUMMyrzj1riqxCA/5zcIHpa4KbyAivIyMFKOUEEBDU21RbyhrEg== X-Received: by 2002:ac8:1019:: with SMTP id z25mr8562670qti.85.1552338084040; Mon, 11 Mar 2019 14:01:24 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id z6sm4242504qtb.67.2019.03.11.14.01.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 11 Mar 2019 14:01:23 -0700 (PDT) Date: Mon, 11 Mar 2019 18:01:20 -0300 From: Rodrigo Siqueira To: Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , Gerd Hoffmann Subject: [PATCH] drm/atomic-helper: Validate pointer before dereference Message-ID: <20190311210120.fdixvenmqjoxuoqt@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20180716 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=mwG+zHmuCaPJeXwYvKvLlC56+W7HMjxMgIZATYB69fo=; b=JVMcRPSuJeWepMuYXphIy+1fyq33EmsBtAzVtLw7q3uOvbBbWioDlYI/n2zQt3HYu9 l1BMq5/iichDSb7EvAUSnBH6BoSrVmNQBX7MSf1fGfbbRriBFg+SNz4JEbQJj7ZrYB+6 uSZ1zZp849RLUcCQ13/gYUntW3HKdx9uiQyfsbknYzY70vjgdFuH8WLjsxLMSKXIUf8O Bc4IqlEeverhwdve6eaLRoBl1vwTFy+fxiXkkHDCIOqgaRaI8+9gRBONIx7n1ghDKA+p Gt8jqFn9fBvH1TvFo5JU/wU+vhBQw9z/HYKLm3XZ5y8sHv1fmUBSDttMlgm4B6lGcn6c urrQ== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The function disable_outputs() and drm_atomic_helper_commit_modeset_enables() tries to retrieve helper_private from the target CRTC, for dereferencing some operations. However, the current implementation does not check whether helper_private is null and, if not, if it has a valid pointer to a dpms and commit functions. This commit adds pointer validations before trying to dereference the dpms and commit function. Signed-off-by: Rodrigo Siqueira --- drivers/gpu/drm/drm_atomic_helper.c | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 540a77a2ade9..fbeef7c461fc 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -1028,14 +1028,16 @@ disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) /* Right function depends upon target state. */ - if (new_crtc_state->enable && funcs->prepare) - funcs->prepare(crtc); - else if (funcs->atomic_disable) - funcs->atomic_disable(crtc, old_crtc_state); - else if (funcs->disable) - funcs->disable(crtc); - else - funcs->dpms(crtc, DRM_MODE_DPMS_OFF); + if (funcs) { + if (new_crtc_state->enable && funcs->prepare) + funcs->prepare(crtc); + else if (funcs->atomic_disable) + funcs->atomic_disable(crtc, old_crtc_state); + else if (funcs->disable) + funcs->disable(crtc); + else if (funcs->dpms) + funcs->dpms(crtc, DRM_MODE_DPMS_OFF); + } if (!(dev->irq_enabled && dev->num_crtcs)) continue; @@ -1277,11 +1279,13 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, if (new_crtc_state->enable) { DRM_DEBUG_ATOMIC("enabling [CRTC:%d:%s]\n", crtc->base.id, crtc->name); - - if (funcs->atomic_enable) - funcs->atomic_enable(crtc, old_crtc_state); - else - funcs->commit(crtc); + if (funcs) { + if (funcs->atomic_enable) + funcs->atomic_enable(crtc, + old_crtc_state); + else if (funcs->atomic_enable) + funcs->commit(crtc); + } } }