From: Tyler C Hicks <tyhicks@canonical.com>
To: Douglas Leeder <douglas.leeder@sophos.com>
Cc: Florian Westphal <Florian.Westphal@sophos.com>,
Dustin Kirkland <dustin.kirkland@gazzang.com>,
Eric Paris <eparis@redhat.com>,
"malware-list@dmesg.printk.net" <malware-list@dmesg.printk.net>,
Eddie Garcia <eddie.garcia@gazzang.com>,
Sergio Pena <sergio.pena@gazzang.com>,
"ecryptfs@vger.kernel.org" <ecryptfs@vger.kernel.org>
Subject: Re: ecryptfs and fanotify
Date: Tue, 14 Aug 2012 13:27:40 -0700 [thread overview]
Message-ID: <20120814202739.GD5215@boyd> (raw)
In-Reply-To: <94863d0d-4a43-427e-8c75-a6f8ced15ffa@ABN-EXCH1A.green.sophos>
[-- Attachment #1: Type: text/plain, Size: 4142 bytes --]
On 2012-08-14 17:01:14, Douglas Leeder wrote:
> On 14/08/12 11:50, Douglas Leeder wrote:
> >On 14/08/12 10:31, Florian Westphal wrote:
> >>Douglas Leeder <douglas.leeder@sophos.com> wrote:
> >>>So as, I sent later, making fanotify only return one file event per
> >>>fanotify read(), So that suggests that the request is getting stuck
> >>>in a cycle or adding a request.
> >>>
> >>>Florian has also been looking at this problem, and has pointed out
> >>>that FMODE_NONOTIFY should prevent the loop seen in the backtrace, so
> >>>I'm wondering if it's getting lost somewhere in ecryptfs. Or perhaps
> >>>it needs to be explicitly propagated to the open request for the
> >>>lower file?
> >>
> >>Douglas, can you reproduce the problem with this patch applied?
> >>
> >>diff --git a/fs/ecryptfs/kthread.c b/fs/ecryptfs/kthread.c
> >>index 809e67d..1d8a53b 100644
> >>--- a/fs/ecryptfs/kthread.c
> >>+++ b/fs/ecryptfs/kthread.c
> >>@@ -74,7 +74,7 @@ static int ecryptfs_threadfn(void *ignored)
> >> kthread_ctl_list);
> >> list_del(&req->kthread_ctl_list);
> >> *req->lower_file = dentry_open(&req->path,
> >>- (O_RDWR | O_LARGEFILE), current_cred());
> >>+ (O_RDWR | O_LARGEFILE | FMODE_NONOTIFY),
> >>current_cred());
> >> complete(&req->done);
> >> }
> >> mutex_unlock(&ecryptfs_kthread_ctl.mux);
> >>@@ -133,7 +133,7 @@ int ecryptfs_privileged_open(struct file
> >>**lower_file,
> >> const struct cred *cred)
> >> {
> >> struct ecryptfs_open_req req;
> >>- int flags = O_LARGEFILE;
> >>+ int flags = O_LARGEFILE|FMODE_NONOTIFY;
> >> int rc = 0;
> >>
> >> init_completion(&req.done);
> >>
> >
> >That patch also seems to fix the problem - at least for AV scanning:
> >1) The encrypted files don't show up in the user-space test program.
> >2) Using the FanotifyMultiThreadScanner (old) from the git tree doesn't
> >lock up. (With the single event read() patch removed for the moment).
> >
> >
> >However I don't think this is a sufficient solution for general fanotify.
> >For example an HSM may need to get the fanotify event to restore the
> >encrypted file to disk.
> >Or a file-access recorder (e.g. http://www.piware.de/tag/fanotify/ )
> >will want all the accesses, including those 'generated' by the
> >fanotify_read() call itself.
> >
> >Talpa, in this case, has it easier, since it is only used for AV, it can
> >ignore any accesses that it's caused.
> >
> >What we might be able to do is set FMODE_NONOTIFY for the lower access
> >if the upper access had it set? Since HSM and fatrace don't want to
> >access the contents when they intercept.
> >
> >I guess HSM and fatrace might not intercept ecryptfs mounts anyway,
> >since they don't directly access the disk?
> >
>
> So I've looked at the path required for that and I guess it involves
> passing file->f_flags from ecryptfs_open through:
> * ecryptfs_get_lower_file (main.c)
> * ecryptfs_init_lower_file (main.c)
> * ecryptfs_privileged_open (kthread.c)
>
> Does that look like the correct to you, Tyler?
Yeah, that should be the full list.
However, I don't think this approach will work with the current
eCryptfs design. eCryptfs only keeps one lower file open per inode. That
means that there could be 10 file descriptors opened for a given
eCryptfs file but there is still only one lower file opened that
everything is multiplexed through.
I don't like the design, but it has been that way for years and I
haven't touched it. For your approach to work, I think eCryptfs would
need to be changed to have a 1-to-1 mapping of upper files to lower
files.
Tyler
>
> I think HSM and fatrace usages won't request the file be opened, so
> won't trigger that path though fanotify.
>
> --
> Douglas Leeder, Senior Software Engineer
>
> ________________________________
>
> Sophos Limited, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom.
> Company Reg No 2096520. VAT Reg No GB 991 2418 08.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-08-14 20:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <5d3d0cdc-50db-4d60-8f9d-701acdbb86b0@ABN-EXCH1A.green.sophos>
[not found] ` <CANT6BaPhaAOv3hg9CgoDa9JTp9vN60zf8bdAQX+dFp6YLSUwnA@mail.gmail.com>
2012-08-14 9:00 ` ecryptfs and fanotify Douglas Leeder
[not found] ` <F85176E33E12BA45BD553324E7858B300CE0A5@abn-exch1b.green.sophos>
[not found] ` <F85176E33E12BA45BD553324E7858B300CE0A5-wyMY/JD5BThOaAOxIYwbkpbnZX9N9W2w@public.gmane.org>
2012-08-14 9:31 ` Florian Westphal
[not found] ` <20120814093124.GA12898@astaro.com>
[not found] ` <20120814093124.GA12898-OOs/4mkCeqbQT0dZR+AlfA@public.gmane.org>
2012-08-14 10:50 ` Douglas Leeder
[not found] ` <502A2D77.50805@sophos.com>
2012-08-14 16:01 ` Douglas Leeder
2012-08-14 20:27 ` Tyler C Hicks [this message]
2012-08-20 8:46 ` Douglas Leeder
2012-08-20 14:53 ` Douglas Leeder
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=20120814202739.GD5215@boyd \
--to=tyhicks@canonical.com \
--cc=Florian.Westphal@sophos.com \
--cc=douglas.leeder@sophos.com \
--cc=dustin.kirkland@gazzang.com \
--cc=ecryptfs@vger.kernel.org \
--cc=eddie.garcia@gazzang.com \
--cc=eparis@redhat.com \
--cc=malware-list@dmesg.printk.net \
--cc=sergio.pena@gazzang.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