From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07CC8C432BE for ; Thu, 26 Aug 2021 11:54:16 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 95D8C61058 for ; Thu, 26 Aug 2021 11:54:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 95D8C61058 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 55C91404DE; Thu, 26 Aug 2021 11:54:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7k8lPlU16FpL; Thu, 26 Aug 2021 11:54:11 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 58AC54012B; Thu, 26 Aug 2021 11:54:11 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 30322C0010; Thu, 26 Aug 2021 11:54:11 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 73DA2C000E for ; Thu, 26 Aug 2021 11:54:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 5CD056066F for ; Thu, 26 Aug 2021 11:54:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3o5FopVfWVn3 for ; Thu, 26 Aug 2021 11:54:08 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by smtp3.osuosl.org (Postfix) with ESMTPS id 75023605FD for ; Thu, 26 Aug 2021 11:54:08 +0000 (UTC) Received: by mail-pg1-x530.google.com with SMTP id y23so2841683pgi.7 for ; Thu, 26 Aug 2021 04:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=nwwI2GDMMB3CQFNBO8bxf/2QLHbDBkcGH58C4VeBtg0=; b=gKN3huvl5kcDKczpggCXGMxnuqiXWW8fyduDS4rxvGSeR1yjnVHPFptFhU99pKy7+d DA7ULgOGgFPZKBA5V1glB2nsPzPXZYBf/4hKN9755PGEiwOFZfejF9SR2MVW7b260k1d rwujXHowYFjJyLvFblkhll1G9Fdokh67JY/0yikyJ6L54Wy3TgDep2R1X88VDQdaZiG3 ftC5B17Zv3HOfaQrMwDtPt2cQizb5plbYAv3ftLxOQo5s26D31knRzhM9o4TieTPziPD FHF859y+zrs4UmWZ8ieuQaYbf3hIGN6Ystn+74XikjSnJVvh6RsZ7QrDtzxnsqTSMneW SORA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=nwwI2GDMMB3CQFNBO8bxf/2QLHbDBkcGH58C4VeBtg0=; b=iMCqY+l9vwQWUwhQVeVjE+JMbm7AUQUevKIy4MSeihLJ37cOpUidDMn19lH6NcPX81 4r2IohBarlWItfF3VONusezTJvLiC3C5x/b/Jl1P2Y8w93vd3RnYQrdTaUluJGARFL37 QED5J/qK9cp/A41z8gWMKnECbMg3roScQev83grS7a4Euc8tZ9D7BRtTBJVze2F+uSif ZCCjtXqFAGIodDzhbu1+GDpwplpTjV6BMs09kCgTcJsaqsGCAXX9DO3Pq1wz8+czoZVJ iYDm//ctNzBiOBhXvGuwxu0VdqMWIMnHsS0yUudvuZW6WUsciV2SOeMLY7XTz+4UkzKc /5PA== X-Gm-Message-State: AOAM532ugz9IY8oJDLO64klTNqERS9Gjj7Y2KakMxrtKwfvlMSzB1M6j Wf17h7Jw4qNfLw7SL9wNHrJAgyAIvJzxJ4RZ68s= X-Google-Smtp-Source: ABdhPJxCZDv240Y19YvqSvce73TS6qqVMaFxktjjoGbA3ZdS52AfCRasNvWnh6gtjIwm6jmT3znelQ== X-Received: by 2002:a05:6a00:24c2:b0:3e2:878d:7e44 with SMTP id d2-20020a056a0024c200b003e2878d7e44mr3420288pfv.22.1629978847425; Thu, 26 Aug 2021 04:54:07 -0700 (PDT) Received: from [192.168.1.237] ([118.200.190.93]) by smtp.gmail.com with ESMTPSA id a15sm2789435pfn.219.2021.08.26.04.53.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Aug 2021 04:54:06 -0700 (PDT) Subject: Re: [PATCH v8 1/7] drm: fix null ptr dereference in drm_master_release To: 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> From: Desmond Cheong Zhi Xi Message-ID: <05f4d472-7a76-598a-e792-a847a3e8516a@gmail.com> Date: Thu, 26 Aug 2021 19:53:58 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" 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. >> --- >> 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 >> > _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees