From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: tejas bharambe <tejas.bharambe@outlook.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Tejas Bharambe <thbharam@gmail.com>,
"ocfs2-devel@lists.linux.dev" <ocfs2-devel@lists.linux.dev>,
"mark@fasheh.com" <mark@fasheh.com>,
"jlbec@evilplan.org" <jlbec@evilplan.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"syzbot+a49010a0e8fcdeea075f@syzkaller.appspotmail.com"
<syzbot+a49010a0e8fcdeea075f@syzkaller.appspotmail.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v4] ocfs2: fix use-after-free in ocfs2_fault() when VM_FAULT_RETRY
Date: Wed, 8 Apr 2026 13:46:47 +0800 [thread overview]
Message-ID: <214f9901-a153-47d8-a099-847fb2c97aa4@linux.alibaba.com> (raw)
In-Reply-To: <JH0PR06MB6632F1A4381AB798FED980CE895BA@JH0PR06MB6632.apcprd06.prod.outlook.com>
On 4/8/26 11:50 AM, tejas bharambe wrote:
> Hi Andrew,
>
> You're right, I missed that scenario.
>
> The inode can be freed if the file descriptor is closed after mmap() and munmap() races with the fault handler.
>
> I can do one of the following:
> 1. I can skip the trace firing when VM_FAULT_RETRY is set as I did in v1. It was changed to v4 after Joseph's suggestion to keep traces.
> 2. If we want to keep traces, we can use ihold()/iput() as shown below:
>
> ihold(inode); //pin inode
> ret = filemap_fault(vmf);
> trace_ocfs2_fault(OCFS2_I(inode)->ip_blkno, ...); // safe, refcount held
> iput(inode); //release inode
>
>
> Which approach do you prefer?
>
It seems theoretically possible.
Since we only want to trace ip_blkno here, not inode itself, we can
simply save it at first.
Thanks,
Joseph
> Thanks,
> Tejas
> ________________________________________
> From: Andrew Morton <akpm@linux-foundation.org>
> Sent: Saturday, April 4, 2026 5:50 PM
> To: tejas bharambe <tejas.bharambe@outlook.com>
> Cc: Tejas Bharambe <thbharam@gmail.com>; ocfs2-devel@lists.linux.dev <ocfs2-devel@lists.linux.dev>; mark@fasheh.com <mark@fasheh.com>; jlbec@evilplan.org <jlbec@evilplan.org>; joseph.qi@linux.alibaba.com <joseph.qi@linux.alibaba.com>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>; syzbot+a49010a0e8fcdeea075f@syzkaller.appspotmail.com <syzbot+a49010a0e8fcdeea075f@syzkaller.appspotmail.com>; stable@vger.kernel.org <stable@vger.kernel.org>
> Subject: Re: [PATCH v4] ocfs2: fix use-after-free in ocfs2_fault() when VM_FAULT_RETRY
>
> On Sun, 5 Apr 2026 00:30:14 +0000 tejas bharambe <tejas.bharambe@outlook.com> wrote:
>
>> Following is my response for question posted on https://sashiko.dev/#/patchset/20260403035333.136824-1-tejas.bharambe%40outlook.com
>>
>>
>> No. For ocfs2_fault() to be executing, the file must be open and
>> the process holds an active file descriptor. The inode's lifetime
>> is tied to the file's reference count, which remains held by the
>> file descriptor for the duration of the fault handler. munmap()
>> can free the VMA (decrementing vm_file's refcount) but cannot
>> free the inode as long as the file descriptor is open. The faulting
>> thread cannot call close() while it is inside the fault handler,
>> so the inode is guaranteed to outlive the trace call.
>
> I don't think that's the scenario which Sashiko is suggesting.
>
> Suppose userspace does
>
> fd = open(...);
> p = mmap(fd, ...);
> close(fd);
>
> Now, that mmap is the only ref against fd.
>
> Now, suppose that userspace does munmap() while another thread is in
> the fault handler.
next prev parent reply other threads:[~2026-04-08 5:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-03 3:53 [PATCH v4] ocfs2: fix use-after-free in ocfs2_fault() when VM_FAULT_RETRY Tejas Bharambe
2026-04-03 19:29 ` Andrew Morton
2026-04-05 0:30 ` tejas bharambe
2026-04-05 0:50 ` Andrew Morton
2026-04-08 3:50 ` tejas bharambe
2026-04-08 5:46 ` Joseph Qi [this message]
2026-04-08 20:12 ` Andrew Morton
2026-04-10 8:01 ` Tejas Bharambe
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=214f9901-a153-47d8-a099-847fb2c97aa4@linux.alibaba.com \
--to=joseph.qi@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=jlbec@evilplan.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=syzbot+a49010a0e8fcdeea075f@syzkaller.appspotmail.com \
--cc=tejas.bharambe@outlook.com \
--cc=thbharam@gmail.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