Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp314477pxb; Wed, 18 Aug 2021 03:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0yfReRYHuBHPJMMWZiWzxddPE0WDJ73948EtQFtaQoPdSsKLNm641GLYrHETpUiF/x4hR X-Received: by 2002:a17:906:2bc2:: with SMTP id n2mr8892000ejg.455.1629281190029; Wed, 18 Aug 2021 03:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629281190; cv=none; d=google.com; s=arc-20160816; b=cnOO4vLB1PmRIdsbVGruAGAPEMBkL9T6zO1/v09PMpeQhaLAE6ouq/jD8GZW3tpgeY eWGvq2i5O3gmddQCL9KJb/v/XpwxHqblKLb5iZJiedlnmhVYdH/81UEYJqK33Qt50t+u /oGDD4SXmDAI4/ilt311gZyL3h22hS8OJNU8Hiw4ViT+bB1JdTW75A3eQ9dwKhVvJxEP 9URH0q4EXTBSedSGceGE5TlyU3syiKrtBknZfUIwvx1HW2oL3Gcvgj5P8wOQ714gGS50 DCuAO0otiHPmdSiRDO4sSFgzMa3UXO5kQu+DXfadj3ORFHbzVsIWfGGMJaK2Ww49MWES Jwng== 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=aMU29SN6YoovEcOrsusWnZbE8h+1MpQpJA0/wZfLGeE=; b=QIuUMAqgb5213en7ka4FLcaYrY66YPWpwd0iBcg9jtb4ZtFrJ4WgmuyhBPVutuyCYh VUsnQN0llb8A/Yhqzxm4MLWBdwphzIquJWgIy2K8Q319kdu9MpnAEa04DP41+J96TWOb biwxxIdZ7muhtdSHvt5QzhYTbvw1+gb+TP8IXdVY1ZAAmC72xg7u4Oy3jPMZ8hPm3sng cFHa6/QLGrRs5RsWbSeJUv69tZY2zl3iTH32+a5a76EldaIl6X/TmL5fkts4czZe+Xeb xPKpOm11FtDsfOSdA+DUIbGcKbsWG4rbcH0tzFWX23cAp5jBGY4L0OEzBMrYcNg79GUk 3vKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=VuWlpnTG; 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 p20si5165825edx.414.2021.08.18.03.06.05; Wed, 18 Aug 2021 03:06:30 -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=VuWlpnTG; 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 S234234AbhHRKEw (ORCPT + 99 others); Wed, 18 Aug 2021 06:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234243AbhHRKEs (ORCPT ); Wed, 18 Aug 2021 06:04:48 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 544EDC0613A4 for ; Wed, 18 Aug 2021 03:04:10 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id v2so2237590edq.10 for ; Wed, 18 Aug 2021 03:04:10 -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=aMU29SN6YoovEcOrsusWnZbE8h+1MpQpJA0/wZfLGeE=; b=VuWlpnTGk6pLgRyLxLDnxv4NkP9nRhdxy0N90/5pUe8bPs6Uj9DlrqMj6WsvKlpXXI 111QEnOZPfJS/mHK8sfTzq5rrN40iXdDm7HI7rmq/xmBL8FDwz+BFyPzr5yB3ovwv8zV 0GGNgLYV0nqj01x2rcDXp61Hl2zl/sKi6V54I= 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=aMU29SN6YoovEcOrsusWnZbE8h+1MpQpJA0/wZfLGeE=; b=jJPJMi6rgsocZ4As28CkCSeRHiHdFvSQoo2Gvf4/zEhkLy0pgZ9qUZ04jri2fjTEWr tb22rx2AaGRWuYjW8kKiNm4OUI039IWmt+0goVMxPZQ8nsgjJWfOEHeF7KgnCsXM6zI5 r+2TkSRdQVUNnQsIZHVtaB/bAm5p96jXLK+yBYqP2dx4Y8N0PmI8avNG7ztJSKjxVuX7 XwLED+MSOWJGlhHY9T0Kn1BQJRlxqWX0Ff5A4IzQpm3gE2nlK33wChaYf7jxVeptbT0e ifLUQKIcqYxAAs/BBobOHhRMm8tOgjcI9tUqdKQcJ+P5pHjoAffgbcxGoSbz/WPfa5Rw skOw== X-Gm-Message-State: AOAM531ptFMNxYydDVZ35MKjEykLL4Bs9XtCsj2/RhhrK1/r8sAvBPAF mOD6ETIopsa/y0kizdWWnsuOKg== X-Received: by 2002:a05:6402:14d9:: with SMTP id f25mr9279034edx.343.1629281048926; Wed, 18 Aug 2021 03:04:08 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id d16sm2384140edu.8.2021.08.18.03.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 03:04:08 -0700 (PDT) Date: Wed, 18 Aug 2021 12:04:06 +0200 From: Daniel Vetter To: Desmond Cheong Zhi Xi Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch, sumit.semwal@linaro.org, christian.koenig@amd.com, axboe@kernel.dk, oleg@redhat.com, tglx@linutronix.de, dvyukov@google.com, walter-zh.wu@mediatek.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: [PATCH v3 3/9] drm: check for null master in drm_is_current_master_locked 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, axboe@kernel.dk, oleg@redhat.com, tglx@linutronix.de, dvyukov@google.com, walter-zh.wu@mediatek.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: <20210818073824.1560124-1-desmondcheongzx@gmail.com> <20210818073824.1560124-4-desmondcheongzx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210818073824.1560124-4-desmondcheongzx@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 Wed, Aug 18, 2021 at 03:38:18PM +0800, Desmond Cheong Zhi Xi wrote: > There is a window after calling drm_master_release, and before a file > is freed, where drm_file can have is_master set to true, but both the > drm_file and drm_device have no master. > > This could result in wrongly approving permissions in > drm_is_current_master_locked. Add a check that fpriv->master is > non-NULl to guard against this scenario. > > Signed-off-by: Desmond Cheong Zhi Xi This should be impossible, drm_master_release is only called when the struct file is released, which means all ioctls and anything else have finished (they hold a temporary reference). fpriv->master can change (if the drm_file becomes newly minted master and wasnt one before through the setmaster ioctl), but it cannot become NULL before it's completely gone from the system. -Daniel > --- > drivers/gpu/drm/drm_auth.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c > index 8c0e0dba1611..f9267b21556e 100644 > --- a/drivers/gpu/drm/drm_auth.c > +++ b/drivers/gpu/drm/drm_auth.c > @@ -66,7 +66,8 @@ static bool drm_is_current_master_locked(struct drm_file *fpriv) > lockdep_assert_once(lockdep_is_held(&fpriv->minor->dev->master_lookup_lock) || > lockdep_is_held(&fpriv->minor->dev->master_mutex)); > > - return fpriv->is_master && drm_lease_owner(fpriv->master) == fpriv->minor->dev->master; > + return (fpriv->is_master && fpriv->master && > + drm_lease_owner(fpriv->master) == fpriv->minor->dev->master); > } > > /** > -- > 2.25.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch