From: Sam Ravnborg <sam@ravnborg.org>
To: Wang Hai <wanghai38@huawei.com>
Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm: fix null-ptr-deref in drm_dev_init_release()
Date: Thu, 14 Oct 2021 21:40:57 +0200 [thread overview]
Message-ID: <YWiHyT3abCm10Ces@ravnborg.org> (raw)
In-Reply-To: <20211013114139.4042207-1-wanghai38@huawei.com>
Hi Wang,
On Wed, Oct 13, 2021 at 07:41:39PM +0800, Wang Hai wrote:
> I got a null-ptr-deref report:
>
> [drm:drm_dev_init [drm]] *ERROR* Cannot allocate anonymous inode: -12
> ==================================================================
> BUG: KASAN: null-ptr-deref in iput+0x3c/0x4a0
> ...
> Call Trace:
> dump_stack_lvl+0x6c/0x8b
> kasan_report.cold+0x64/0xdb
> __asan_load8+0x69/0x90
> iput+0x3c/0x4a0
> drm_dev_init_release+0x39/0xb0 [drm]
> drm_managed_release+0x158/0x2d0 [drm]
> drm_dev_init+0x3a7/0x4c0 [drm]
> __devm_drm_dev_alloc+0x55/0xd0 [drm]
> mi0283qt_probe+0x8a/0x2b5 [mi0283qt]
> spi_probe+0xeb/0x130
> ...
> entry_SYSCALL_64_after_hwframe+0x44/0xae
>
> If drm_fs_inode_new() fails in drm_dev_init(), dev->anon_inode will point
> to PTR_ERR(...) instead of NULL. This will result in null-ptr-deref when
> drm_fs_inode_free(dev->anon_inode) is called.
>
> drm_dev_init()
> drm_fs_inode_new() // fail, dev->anon_inode = PTR_ERR(...)
> drm_managed_release()
> drm_dev_init_release()
> drm_fs_inode_free() // access non-existent anon_inode
>
> Define a temp variable and assign it to dev->anon_inode if the temp
> variable is not PTR_ERR.
>
> Fixes: 2cbf7fc6718b ("drm: Use drmm_ for drm_dev_init cleanup")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Wang Hai <wanghai38@huawei.com>
Nice simple fix. Applied to drm-misc-next as I did not see the fix as
urgent. It will show up in -next in 1-2 weeks.
Sam
prev parent reply other threads:[~2021-10-14 19:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 11:41 [PATCH] drm: fix null-ptr-deref in drm_dev_init_release() Wang Hai
2021-10-14 19:40 ` Sam Ravnborg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YWiHyT3abCm10Ces@ravnborg.org \
--to=sam@ravnborg.org \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=tzimmermann@suse.de \
--cc=wanghai38@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox