Re: [PATCH v2] ima: define ima_post_create_tmpfile() hook and add missing call

From: Amir Goldstein
Date: Mon Jan 21 2019 - 07:30:07 EST


On Mon, Jan 21, 2019 at 2:00 PM Mimi Zohar <zohar@xxxxxxxxxxxxx> wrote:
>
> On Thu, 2019-01-17 at 15:34 -0600, Goldwyn Rodrigues wrote:
> > On 13:47 18/12, Mimi Zohar wrote:
> > > If tmpfiles can be made persistent, then newly created tmpfiles need to
> > > be treated like any other new files in policy.
> > >
> > > This patch indicates which newly created tmpfiles are in policy, causing
> > > the file hash to be calculated on __fput().
> >
> > Discussed in overlayfs, this would be better if we use this on inode
> > and called from vfs_tmpfile() instead of do_tmpfile(). This will cover
> > the overlayfs case which uses tmpfiles while performing copy_up().
> > The patch is attached.
> >
> > Here is the updated patch which works for my cases.
> > However, it is the the failure case after setting the IMA flags
> > I am concerned about, though I don't think that should be as harmful.
>
> Right. The new IMA hook allocates memory for storing the flags, which
> needs to be cleaned up on failure. For this reason, the IMA call is
> deferred until after the transition from locally freeing memory on
> failure to relying on __fput(). In "do_last", the call to IMA is
> after "opened"; and in the original version of this patch the call to
> IMA is after finish_open().
>

Not sure I understand the concern.
The integrity context is associated with the inode and will be freed
on destroy_inode() no matter which error path is taken.
Am I missing something?

Thanks,
Amir.