From: Paul Moore <paul@paul-moore.com>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: audit@vger.kernel.org,
Andreas Steinmetz <anstein99@googlemail.com>,
John Johansen <john.johansen@canonical.com>
Subject: Re: [PATCH] audit: use mmget() instead of get_task_exe_file() when auditing @current
Date: Tue, 24 Oct 2023 11:44:15 -0400 [thread overview]
Message-ID: <CAHC9VhQPCX_OoNgXUR--gjx8Pi2be=h1swt4cSOKnJA0aAdjLg@mail.gmail.com> (raw)
In-Reply-To: <CAGudoHHwH1nJzQfS1OynoKmp--58CtiVB+BX9j46K6hwYxvJeA@mail.gmail.com>
On Sat, Oct 21, 2023 at 9:51 AM Mateusz Guzik <mjguzik@gmail.com> wrote:
> On 10/19/23, Paul Moore <paul@paul-moore.com> wrote:
> > On Thu, Oct 19, 2023 at 12:56 PM Mateusz Guzik <mjguzik@gmail.com> wrote:
> >> On 10/19/23, Paul Moore <paul@paul-moore.com> wrote:
> >> > On Thu, Oct 19, 2023 at 10:52 AM Mateusz Guzik <mjguzik@gmail.com>
> >> > wrote:
> >> >> On 10/19/23, Paul Moore <paul@paul-moore.com> wrote:
> >> >> > Thinking about it a bit more this morning, I think we can safely
> >> >> > ignore the non-@current case in audit_exe_compare() as the whole
> >> >> > point
> >> >> > of the audit exe filter is to record the actions of processes
> >> >> > instantiated from that executable file; if the @current task is not
> >> >> > being logged/filtered, we shouldn't have to worry about the exe
> >> >> > filter.
> >> >>
> >> >> I did a quick stab at figuring out whether one can get there with
> >> >> non-current to begin with, but did not convince myself it is not
> >> >> possible.
> >> >>
> >> >> That said, should you repost, I think refing and unrefing mm should be
> >> >> a
> >> >> voided.
> >> >
> >> > We have to deref current->mm to get the exe_file, but so long as we
> >> > get a reference with mmget()/mmput() it should be safe, no?
> >>
> >> For task == current the very condition which allows you to safely
> >> mmget also makes the operation redundant -- current already has a ref
> >> on mm for as long as it executes.
> >
> > I've been using the move_pages(2) syscall code as an example and in
> > the find_mm_struct() function the code either does a mmget() if
> > accessing current->mm or a get_task_mm() if accessing an arbitrary
> > task.
> >
> > -> SYSCALL_DEFINE6(move_pages, ...)
> > -> kernel_move_pages(...)
> > -> find_mm_struct(...)
> >
> > What am I missing?
> >
>
> To my reading they did not want to special-case it in the caller --
> they just mmput regardless of what task is.
>
> Again, you may notice there are no locks held in that usecase. The
> pointer is blindly derefed and a refcount bumped. For this to be safe,
> it has to be guaranteed > 0 already, which it is for a task accessing
> it's own mm struct. You can find the releasing mmput in exit ->
> do_exit -> exit_mm callchain.
I'll have a v2 out soon (later today?).
--
paul-moore.com
prev parent reply other threads:[~2023-10-24 15:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 22:20 [PATCH] audit: use mmget() instead of get_task_exe_file() when auditing @current Paul Moore
2023-10-18 22:22 ` Paul Moore
2023-10-19 0:22 ` Mateusz Guzik
2023-10-19 1:29 ` Paul Moore
2023-10-19 2:14 ` Mateusz Guzik
2023-10-19 2:18 ` Mateusz Guzik
2023-10-19 14:42 ` Paul Moore
2023-10-19 14:52 ` Mateusz Guzik
2023-10-19 16:07 ` Paul Moore
2023-10-19 16:55 ` Mateusz Guzik
2023-10-19 18:15 ` Paul Moore
2023-10-21 13:51 ` Mateusz Guzik
2023-10-24 15:44 ` Paul Moore [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='CAHC9VhQPCX_OoNgXUR--gjx8Pi2be=h1swt4cSOKnJA0aAdjLg@mail.gmail.com' \
--to=paul@paul-moore.com \
--cc=anstein99@googlemail.com \
--cc=audit@vger.kernel.org \
--cc=john.johansen@canonical.com \
--cc=mjguzik@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).