From: Naresh Kamboju <naresh.kamboju@linaro.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Linux Trace Kernel <linux-trace-kernel@vger.kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
"Arnd Bergmann <arnd@arndb.de>,
naresh.kamboju@linaro.org,
Beau Belgrave <beaub@linux.microsoft.com>,
Ajay Kaher <akaher@vmware.com>,
Andrew Morton" <akpm@linux-foundation.org>
Subject: Re: [PATCH] eventfs: Hold eventfs_mutex when calling callback functions
Date: Tue, 31 Oct 2023 03:11:31 +0530 [thread overview]
Message-ID: <CA+G9fYu5VdDPB25croT8OEFRcfxMSHRduL0EK8ct7EVWN3t5aQ@mail.gmail.com> (raw)
In-Reply-To: <20231030114047.759c7bdf@gandalf.local.home>
On Mon, 30 Oct 2023 at 21:10, Steven Rostedt <rostedt@goodmis.org> wrote:
>
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
>
> The callback function that is used to create inodes and dentries is not
> protected by anything and the data that is passed to it could become
> stale. After eventfs_remove_dir() is called by the tracing system, it is
> free to remove the events that are associated to that directory.
> Unfortunately, that means the callbacks must not be called after that.
>
> CPU0 CPU1
> ---- ----
> eventfs_root_lookup() {
> eventfs_remove_dir() {
> mutex_lock(&event_mutex);
> ei->is_freed = set;
> mutex_unlock(&event_mutex);
> }
> kfree(event_call);
>
> for (...) {
> entry = &ei->entries[i];
> r = entry->callback() {
> call = data; // call == event_call above
> if (call->flags ...)
>
> [ USE AFTER FREE BUG ]
>
> The safest way to protect this is to wrap the callback with:
>
> mutex_lock(&eventfs_mutex);
> if (!ei->is_freed)
> r = entry->callback();
> else
> r = -1;
> mutex_unlock(&eventfs_mutex);
>
> This will make sure that the callback will not be called after it is
> freed. But now it needs to be known that the callback is called while
> holding internal eventfs locks, and that it must not call back into the
> eventfs / tracefs system. There's no reason it should anyway, but document
> that as well.
>
> Link: https://lore.kernel.org/all/CA+G9fYu9GOEbD=rR5eMR-=HJ8H6rMsbzDC2ZY5=Y50WpWAE7_Q@mail.gmail.com/
>
> Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> ---
> fs/tracefs/event_inode.c | 22 ++++++++++++++++++--
> include/linux/tracefs.h | 43 ++++++++++++++++++++++++++++++++++++++++
--
Linaro LKFT
https://lkft.linaro.org
prev parent reply other threads:[~2023-10-30 21:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-30 15:40 [PATCH] eventfs: Hold eventfs_mutex when calling callback functions Steven Rostedt
2023-10-30 15:50 ` Steven Rostedt
2023-10-30 21:41 ` Naresh Kamboju [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=CA+G9fYu5VdDPB25croT8OEFRcfxMSHRduL0EK8ct7EVWN3t5aQ@mail.gmail.com \
--to=naresh.kamboju@linaro.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/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;
as well as URLs for NNTP newsgroup(s).