mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zach Wade <zachwade.k@gmail.com>
To: Kees Cook <kees@kernel.org>
Cc: tony.luck@intel.com, gpiccoli@igalia.com,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, lixingyang1@qq.com
Subject: Re: [PATCH] pstore: Fix uaf when backend is unregistered
Date: Wed, 9 Oct 2024 21:36:33 +0800	[thread overview]
Message-ID: <6077c924-f975-49a0-8ee4-4e481664ac38@gmail.com> (raw)
In-Reply-To: <202410081019.0E9DE76A@keescook>



On 2024/10/9 1:23, Kees Cook wrote:
> On Wed, Oct 09, 2024 at 01:10:14AM +0800, Zach Wade wrote:
>> when unload pstore_blk, we will unlink the pstore file and
>> set pos->dentry to NULL, but simple_unlink(d_inode(root), pos->dentry)
>> may free inode of pos->dentry and free pos by free_pstore_private,
>> this may trigger uaf. kasan report:
> 
> Thanks for this! I need to double check what happening here a bit more
> closely, as maybe some ordering changed after a43e0fc5e913 ("pstore:
> inode: Only d_invalidate() is needed")
> 
>> @@ -316,9 +316,10 @@ int pstore_put_backend_records(struct pstore_info *psi)
>>   		list_for_each_entry_safe(pos, tmp, &records_list, list) {
>>   			if (pos->record->psi == psi) {
>>   				list_del_init(&pos->list);
>> -				d_invalidate(pos->dentry);
>> -				simple_unlink(d_inode(root), pos->dentry);
>> +				unlink_dentry = pos->dentry;
>>   				pos->dentry = NULL;
>> +				d_invalidate(unlink_dentry);
>> +				simple_unlink(d_inode(root), unlink_dentry);
> 
> But on the face of it, this does solve the UAF. I'll double-check that
> this isn't a result of the mentioned commit.

Hi Cook,

However, I think a more appropriate solution to the problem here is to
check the reference count when uninstalling the mount point.

At the same time, the test script is attached:
#!/bin/bash
modprobe pstore_blk
blkdev=/dev/sda2
best_effort=on
mount -t pstore pstore /sys/fs/pstore
sleep 2
umount /sys/fs/pstore
modprobe -r pstore_blk

Thanks,
Zach

> 

> -Kees
> 


  reply	other threads:[~2024-10-09 13:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08 17:10 Zach Wade
2024-10-08 17:23 ` Kees Cook
2024-10-09 13:36   ` Zach Wade [this message]
2024-10-15 14:45     ` Zach Wade
  -- strict thread matches above, loose matches on Subject: below --
2024-09-29 12:43 Li XingYang
2024-09-29 12:47 ` Li XingYang
2024-09-30 13:12 ` Greg KH

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=6077c924-f975-49a0-8ee4-4e481664ac38@gmail.com \
    --to=zachwade.k@gmail.com \
    --cc=gpiccoli@igalia.com \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lixingyang1@qq.com \
    --cc=stable@vger.kernel.org \
    --cc=tony.luck@intel.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

all inboxes | Powered by JetHome®