Received: by 10.223.185.116 with SMTP id b49csp3817367wrg; Mon, 19 Feb 2018 06:32:16 -0800 (PST) X-Google-Smtp-Source: AH8x224uVKX4Srw/xBICBBGz6Fjgl4wyPlEstef4uRBbv/vcM9HVEKGPuvmyuweGzB5e97bv2cwJ X-Received: by 2002:a17:902:a517:: with SMTP id s23-v6mr14201840plq.1.1519050736745; Mon, 19 Feb 2018 06:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519050736; cv=none; d=google.com; s=arc-20160816; b=CDUOqiENPX0Jpzna12nkKMO1c1j/RiequCkxQhLq/uPF3KfpI+8jbWnGTXfSI0w2N/ bkLakCG7rxBZL7g+/tP1k9WnLLPmOSwsrTmhW9EF0ox58W1GZ0jky8iOM7xtHsltweO4 LvNbR+PgwC3IEy1VIko3w/ywa9WRFanUm0NLx5KlbvB8zAwx4Vuhcnz56eYTOCWQ4hyb dk7Z3dQCr+cR/krRhzoFjeISsHRljQpZkIwKN9EAtQDOTrqwYWcFNgUuw9V3GS2lG07S V/Gl9jUAzFiOuIgN1XPjlnXS9i6jfoPGgZZ1hTN6LF0x9kX9BdPZbeQS5pQOg41oPP6x bZnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=xEzs8yA1I1hsSz7OBfdyYbqlG4khZiyRw7WpWJBW+kQ=; b=O8fo06xZ3toC4tgFjtJqawlpET+8f9koGW8mcSkaNOZj73OUdowEDaH7aq2WBhUe3C +819yfxIxislGfesd+v6x6niiqhD0EDV1THhs6HzOcM5cWGw0S3lvB5Os30qdjamh/D8 Z2H29ZDB+nedDE5juMlEfRa8YsvY1Zhp2XavtaSGvHJVwAVURpguUVoyMpRdtxlTRdiM /A3NyhdxTOLb43fzrjlqXFZvDJHcr0gOXnUEox6lyUm0Xsq0xVanep2Ll0ZDK9qwpZVK MJbGMCKGYnkg5SBJ6AFbCyJ9crA6VshB25Z5IYLcFZkD0pjUsCL6NMdSq3z8y5dOC5WI Ppjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=NoY+UyCl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o2-v6si4725317pls.366.2018.02.19.06.32.00; Mon, 19 Feb 2018 06:32:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=NoY+UyCl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752474AbeBSOaI (ORCPT + 99 others); Mon, 19 Feb 2018 09:30:08 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:53520 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751447AbeBSOaG (ORCPT ); Mon, 19 Feb 2018 09:30:06 -0500 Received: by mail-wm0-f68.google.com with SMTP id t74so15588789wme.3 for ; Mon, 19 Feb 2018 06:30:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=sender:date:from:to:cc:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=xEzs8yA1I1hsSz7OBfdyYbqlG4khZiyRw7WpWJBW+kQ=; b=NoY+UyClW1wvQls5vOW2A+WSByfcWJR5LFY1stDGSC762lu1+ZBojy7suHqsAonwt+ JnQd6M99UKQpLXzLbZUBHT3N3gy4QmJcsiVIvTQ1OiGusiivZJZ/TVbL+SqEQmKr8fn+ BfaIbcrrYvH1tR87J+7OTHJAnqkXQUqNCgWEM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=xEzs8yA1I1hsSz7OBfdyYbqlG4khZiyRw7WpWJBW+kQ=; b=Yqybx+P7IvgMI94pW9xHr5fyW8+dDQ424/SnaL5tBolzlkiSNhfU6zEjyZevdqDXqN FKHx7FnJpk/msxcZcaBxCD6lJ3WKdPaBrl4flOdpFUxwD4O7RA+Qr3l12dNv+5+EBQCP 8JGuRTc3Txva3gujj32aKiDQfl5ystXOeJ7BVrh/UDRozjFA/P7L4Mrdp6mdmshhEINQ 3ZCIECYwDcj9t520GUEQboxwgne2s6ivkorxteP9CoLvaz3Rl1o2ZlQioGt6e7WZGcnF M+dVwXa8E624PoizfCHd6J0mVm0EkAANg+G/qPlrs0WNM9pbIIDggb4loT98ziqxxyPS Bekg== X-Gm-Message-State: APf1xPDu5JcPLv7Mg+9IHjWsLOAG8oykT21GjOaGgI5enqiN4MTW6UVl oOXmtcNv8RqFP0jDyjVh1OnxZQ== X-Received: by 10.80.192.68 with SMTP id u4mr19476161edd.109.1519050605822; Mon, 19 Feb 2018 06:30:05 -0800 (PST) Received: from phenom.ffwll.local (212-51-149-109.fiber7.init7.net. [212.51.149.109]) by smtp.gmail.com with ESMTPSA id q11sm18760143edj.64.2018.02.19.06.30.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Feb 2018 06:30:04 -0800 (PST) Date: Mon, 19 Feb 2018 15:30:02 +0100 From: Daniel Vetter To: Oleksandr Andrushchenko Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, airlied@linux.ie, daniel.vetter@intel.com, Oleksandr Andrushchenko Subject: Re: [PATCH] drm/simple_kms_helper: Fix NULL pointer dereference with no active CRTC Message-ID: <20180219143002.GC22199@phenom.ffwll.local> Mail-Followup-To: Oleksandr Andrushchenko , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, airlied@linux.ie, daniel.vetter@intel.com, Oleksandr Andrushchenko References: <1518511456-28257-1-git-send-email-andr2000@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1518511456-28257-1-git-send-email-andr2000@gmail.com> X-Operating-System: Linux phenom 4.14.0-3-amd64 User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 13, 2018 at 10:44:16AM +0200, Oleksandr Andrushchenko wrote: > From: Oleksandr Andrushchenko > > It is possible that drm_simple_kms_plane_atomic_check called > with no CRTC set, e.g. when user-space application sets CRTC_ID/FB_ID > to 0 before doing any actual drawing. This leads to NULL pointer > dereference because in this case new CRTC state is NULL and must be > checked before accessing. > > Signed-off-by: Oleksandr Andrushchenko > --- > drivers/gpu/drm/drm_simple_kms_helper.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/drm_simple_kms_helper.c b/drivers/gpu/drm/drm_simple_kms_helper.c > index 9ca8a4a59b74..a05eca9cec8b 100644 > --- a/drivers/gpu/drm/drm_simple_kms_helper.c > +++ b/drivers/gpu/drm/drm_simple_kms_helper.c > @@ -121,8 +121,10 @@ static int drm_simple_kms_plane_atomic_check(struct drm_plane *plane, > pipe = container_of(plane, struct drm_simple_display_pipe, plane); > crtc_state = drm_atomic_get_new_crtc_state(plane_state->state, > &pipe->crtc); > - if (!crtc_state->enable) > - return 0; /* nothing to check when disabling or disabled */ > + > + if (!crtc_state || !crtc_state->enable) > + /* nothing to check when disabling or disabled or no CRTC set */ > + return 0; > > if (crtc_state->enable) > drm_mode_get_hv_timing(&crtc_state->mode, Hm, this is a bit annoying, since the can_position = false parameter to drm_atomic_helper_check_plane_state is supposed to catch all this. Would moving all the checks after the call to that helper, and gating them on plane_state->visible also work? We'd need to add a guarantee to drm_atomic_helper_check_plane_state that it can cope with crtc_state == NULL, but I think that's a good idea anyway. Atm it shouldn't end up looking at the crtc_state pointer in that case. Otherwise we'll just go with your fix, but it feels all a bit too fragile, hence why I want to explore more robust options a bit. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch