From: Alexey Dobriyan <adobriyan@gmail.com>
To: Ye Bin <yebin@huaweicloud.com>
Cc: akpm@linux-foundation.org, rick.p.edgecombe@intel.com,
ast@kernel.org, kirill.shutemov@linux.intel.com,
linux-fsdevel@vger.kernel.org, yebin10@huawei.com
Subject: Re: [PATCH] proc: fix use-after-free in proc_get_inode()
Date: Sat, 1 Mar 2025 07:46:13 +0300 [thread overview]
Message-ID: <2cdf3fb7-1b83-4484-b1e6-6508ddb8ed13@p183> (raw)
In-Reply-To: <20250301034024.277290-1-yebin@huaweicloud.com>
On Sat, Mar 01, 2025 at 11:40:24AM +0800, Ye Bin wrote:
> There's a issue as follows:
> BUG: unable to handle page fault for address: fffffbfff80a702b
> Above issue may happen as follows:
> rmmod lookup
> sys_delete_module
> proc_lookup_de
> read_lock(&proc_subdir_lock);
> pde_get(de);
> read_unlock(&proc_subdir_lock);
> proc_get_inode(dir->i_sb, de);
> mod->exit()
> proc_remove
> remove_proc_subtree
> write_lock(&proc_subdir_lock);
> write_unlock(&proc_subdir_lock);
> proc_entry_rundown(de);
> free_module(mod);
>
> if (S_ISREG(inode->i_mode))
> if (de->proc_ops->proc_read_iter)
> --> As module is already freed, will trigger UAF
Hey look, vintage 17.5 year old /proc bug.
This just shows how long I didn't ran rmmod test. :-(
> To solve above issue there's need to get 'in_use' before use proc_dir_entry
> in proc_get_inode().
>
> Fixes: fd5a13f4893c ("proc: add a read_iter method to proc proc_ops")
OK, this is copy of the original sin below.
> Fixes: 778f3dd5a13c ("Fix procfs compat_ioctl regression")
This one is.
Let me think a little.
> --- a/fs/proc/inode.c
> +++ b/fs/proc/inode.c
> @@ -644,6 +644,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
> return inode;
> }
>
> + if (!pde_is_permanent(de) && !use_pde(de)) {
> + pde_put(de);
> + return NULL;
> + }
> +
> if (de->mode) {
> inode->i_mode = de->mode;
> inode->i_uid = de->uid;
> @@ -677,5 +682,9 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
> } else {
> BUG();
> }
> +
> + if (!pde_is_permanent(de))
> + unuse_pde(de);
> +
> return inode;
> }
next prev parent reply other threads:[~2025-03-01 4:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-01 3:40 [PATCH] proc: fix use-after-free in proc_get_inode() Ye Bin
2025-03-01 4:46 ` Alexey Dobriyan [this message]
2025-03-01 11:51 ` Alexey Dobriyan
2025-03-03 2:12 ` yebin
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=2cdf3fb7-1b83-4484-b1e6-6508ddb8ed13@p183 \
--to=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ast@kernel.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=rick.p.edgecombe@intel.com \
--cc=yebin10@huawei.com \
--cc=yebin@huaweicloud.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