Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp395841pxb; Thu, 26 Aug 2021 05:52:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvYAYx9Kth2gN+zlzQPNSeCNptujHNl3vbqz9NtAVvqEcOZnvayfrSGWJ7T3rnW4WTfP0d X-Received: by 2002:a5d:824e:: with SMTP id n14mr2898264ioo.134.1629982354167; Thu, 26 Aug 2021 05:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629982354; cv=none; d=google.com; s=arc-20160816; b=aMFCh93mSWeg1YDo5YjvHsaD/vrzN+77OkrE8TyDFliFnCh9Bye4mFGRvnWdon+jsK yn00BHVbUi9bGqtVezRRtXZJhSyV4hpMQohQ7GbcsmO2YXFY7REotJQg3lITrqZqeBH6 RJoLbWdXVmwJJrLIDdzX5cbruA1E/ZziaqbRpQU7THbERLBgK/yNjFqi084EihqIaGL4 l328zHclu55SnYZAEsV1INjZluolJSjx7dACci62vEzMOcIFLweo+zPcVOMmXznYpe1s +ls55+LOCFEZDv+adwVlFggNo2fIgg3a96CKhHrTYYR9FyEv2cBwoiMPxsiXCb964VEW DJJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=FpiPnansJu8DUu+/nHhIKk3mLIrXLuVC7r4JsYSdoWk=; b=rx72FzMFUBOgSqXgEHr09AxV2EIlQos3/7Zj7B0RZL2CCVSGBqpHDqLTu3NnsV2O0j 5yPfNBNsfVFmGEdgG2rUh2rYNBlMJr86Z4DIdDFRa4/uVRnuKi2ngFn3swCZMJGv2gae iAYQjAu8tCh9FvxgExdsu5OzgnJtdts0UmjH0y2ZiqU1pq09NSwYJrqKArBIFuugcck2 +PT+qSr8DHD51mtoG/iH9kRJ4LWJvTR0J2d+6IUwDPzOofqQ9or0XBHU9C6ve11ec8zF V/WSRpUM3eR02690xPJGwFhnUT5x4OZfXjyQODlHg/q0j5yh7zZawRVJK/3TxTw0xYLN 4CVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=ftuxs5ZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v11si2882788iol.46.2021.08.26.05.52.21; Thu, 26 Aug 2021 05:52:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=ftuxs5ZJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242483AbhHZMwF (ORCPT + 99 others); Thu, 26 Aug 2021 08:52:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240886AbhHZMwE (ORCPT ); Thu, 26 Aug 2021 08:52:04 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21960C061757 for ; Thu, 26 Aug 2021 05:51:17 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a25so6029064ejv.6 for ; Thu, 26 Aug 2021 05:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=FpiPnansJu8DUu+/nHhIKk3mLIrXLuVC7r4JsYSdoWk=; b=ftuxs5ZJnnCztKpDs1pIMs0oUtnLWsyEXzaS2DrIYBCSzQ24ijdkVP5Max2f76G1/Y aK5Tpqc8weHkVwlG3lxMhCnRlCLBnvlO3YhanwRSGhdrr7uIabDMFcOi0p17/+CXJSW6 ej/XHYGU+xOQfkQcnBxPFqwJ1+c3hJneZ6xL0= 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 :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=FpiPnansJu8DUu+/nHhIKk3mLIrXLuVC7r4JsYSdoWk=; b=DeHIcQPYesW5dR2HWZKDflw5+MCaIaoqu0Fk4k1gk1ISpI/zZHlNBqK75iH4VheWIN IzkzXDSmAdE125CNhzWze3rtY9/7TW3FHiPXiqFLIwAA8ZP230intbtPzxV3pnsHL1wA WZUFIP6UBtsoyWOp9+jiDSksRmxO/O0+z2mqSFTtpYrXZZhL7vEnnTIW41IsPzDSEYYu UUJF5IJnpvl3corPadtAQY/fjGipAfpxKyq04wIUykJlQHem2XEBqon+Vi54tz2R8nEr 4x6tb0GXOjcGTO3JmKbSs7oKtGQz6yIrJGNIjFA6bzaCC3XTd5Doek8OvNsKK9XqxDcI URVg== X-Gm-Message-State: AOAM533jcwDNcIIoVk49TI3s5qE70xSpQWBtheFzEXn6RtSNzBvLjNqx zsBQTyR2eJ3nvGa3XHvS/3zBzQ== X-Received: by 2002:a17:907:8693:: with SMTP id qa19mr2224090ejc.95.1629982275725; Thu, 26 Aug 2021 05:51:15 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id gz22sm1462270ejb.15.2021.08.26.05.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 05:51:15 -0700 (PDT) Date: Thu, 26 Aug 2021 14:51:12 +0200 From: Daniel Vetter To: Desmond Cheong Zhi Xi Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, sumit.semwal@linaro.org, christian.koenig@amd.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, ville.syrjala@linux.intel.com, matthew.auld@intel.com, dan.carpenter@oracle.com, tvrtko.ursulin@intel.com, matthew.d.roper@intel.com, lucas.demarchi@intel.com, karthik.b.s@intel.com, jose.souza@intel.com, manasi.d.navare@intel.com, airlied@redhat.com, aditya.swarup@intel.com, andrescj@chromium.org, linux-graphics-maintainer@vmware.com, zackr@vmware.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: Re: [Intel-gfx] [PATCH v8 1/7] drm: fix null ptr dereference in drm_master_release Message-ID: Mail-Followup-To: Desmond Cheong Zhi Xi , maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, sumit.semwal@linaro.org, christian.koenig@amd.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, ville.syrjala@linux.intel.com, matthew.auld@intel.com, dan.carpenter@oracle.com, tvrtko.ursulin@intel.com, matthew.d.roper@intel.com, lucas.demarchi@intel.com, karthik.b.s@intel.com, jose.souza@intel.com, manasi.d.navare@intel.com, airlied@redhat.com, aditya.swarup@intel.com, andrescj@chromium.org, linux-graphics-maintainer@vmware.com, zackr@vmware.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org References: <20210826020122.1488002-1-desmondcheongzx@gmail.com> <20210826020122.1488002-2-desmondcheongzx@gmail.com> <05f4d472-7a76-598a-e792-a847a3e8516a@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <05f4d472-7a76-598a-e792-a847a3e8516a@gmail.com> X-Operating-System: Linux phenom 5.10.0-7-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 26, 2021 at 07:53:58PM +0800, Desmond Cheong Zhi Xi wrote: > On 26/8/21 5:53 pm, Daniel Vetter wrote: > > On Thu, Aug 26, 2021 at 10:01:16AM +0800, Desmond Cheong Zhi Xi wrote: > > > drm_master_release can be called on a drm_file without a master, which > > > results in a null ptr dereference of file_priv->master->magic_map. The > > > three cases are: > > > > > > 1. Error path in drm_open_helper > > > drm_open(): > > > drm_open_helper(): > > > drm_master_open(): > > > drm_new_set_master(); <--- returns -ENOMEM, > > > drm_file.master not set > > > drm_file_free(): > > > drm_master_release(); <--- NULL ptr dereference > > > (file_priv->master->magic_map) > > > > > > 2. Error path in mock_drm_getfile > > > mock_drm_getfile(): > > > anon_inode_getfile(); <--- returns error, drm_file.master not set > > > drm_file_free(): > > > drm_master_release(); <--- NULL ptr dereference > > > (file_priv->master->magic_map) > > > > > > 3. In drm_client_close, as drm_client_open doesn't set up a master > > > > > > drm_file.master is set up in drm_open_helper through the call to > > > drm_master_open, so we mirror it with a call to drm_master_release in > > > drm_close_helper, and remove drm_master_release from drm_file_free to > > > avoid the null ptr dereference. > > > > > > Signed-off-by: Desmond Cheong Zhi Xi > > > > Reviewed-by: Daniel Vetter > > > > I guess we should also have a cc: stable on this one? I think this bug > > existed since pretty much forever, but maybe more prominent with the > > drm_client stuff added a while ago. > > -Daniel > > > > Thanks for the reviews, Daniel. > > Took a closer look. I think if we cc: stable, this fix should accompany > commit 7eeaeb90a6a5 ("drm/file: Don't set master on in-kernel clients") > which moves the drm_master_open out from drm_file_alloc into > drm_open_helper. Ah right, please reference that commit with a Fixes: line. -Daniel > > > > --- > > > drivers/gpu/drm/drm_file.c | 6 +++--- > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c > > > index ed25168619fc..90b62f360da1 100644 > > > --- a/drivers/gpu/drm/drm_file.c > > > +++ b/drivers/gpu/drm/drm_file.c > > > @@ -282,9 +282,6 @@ void drm_file_free(struct drm_file *file) > > > drm_legacy_ctxbitmap_flush(dev, file); > > > - if (drm_is_primary_client(file)) > > > - drm_master_release(file); > > > - > > > if (dev->driver->postclose) > > > dev->driver->postclose(dev, file); > > > @@ -305,6 +302,9 @@ static void drm_close_helper(struct file *filp) > > > list_del(&file_priv->lhead); > > > mutex_unlock(&dev->filelist_mutex); > > > + if (drm_is_primary_client(file_priv)) > > > + drm_master_release(file_priv); > > > + > > > drm_file_free(file_priv); > > > } > > > -- > > > 2.25.1 > > > > > > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch