diff mbox

[Trusty,SRU] fanotify: fix -EOVERFLOW with large files on 64-bit

Message ID 1450443589-23775-1-git-send-email-tim.gardner@canonical.com
State New
Headers show

Commit Message

Tim Gardner Dec. 18, 2015, 12:59 p.m. UTC
From: Will Woods <wwoods@redhat.com>

BugLink: http://bugs.launchpad.net/bugs/1527039

On 64-bit systems, O_LARGEFILE is automatically added to flags inside
the open() syscall (also openat(), blkdev_open(), etc).  Userspace
therefore defines O_LARGEFILE to be 0 - you can use it, but it's a
no-op.  Everything should be O_LARGEFILE by default.

But: when fanotify does create_fd() it uses dentry_open(), which skips
all that.  And userspace can't set O_LARGEFILE in fanotify_init()
because it's defined to 0.  So if fanotify gets an event regarding a
large file, the read() will just fail with -EOVERFLOW.

This patch adds O_LARGEFILE to fanotify_init()'s event_f_flags on 64-bit
systems, using the same test as open()/openat()/etc.

Addresses https://bugzilla.redhat.com/show_bug.cgi?id=696821

Signed-off-by: Will Woods <wwoods@redhat.com>
Acked-by: Eric Paris <eparis@redhat.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(back ported from commit 1e2ee49f7f1b79f0b14884fe6a602f0411b39552)
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---
 fs/notify/fanotify/fanotify_user.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Kamal Mostafa Dec. 18, 2015, 7:13 p.m. UTC | #1
On Fri, 2015-12-18 at 05:59 -0700, tim.gardner@canonical.com wrote:
> From: Will Woods <wwoods@redhat.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1527039
> 
> On 64-bit systems, O_LARGEFILE is automatically added to flags inside
> the open() syscall (also openat(), blkdev_open(), etc).  Userspace
> therefore defines O_LARGEFILE to be 0 - you can use it, but it's a
> no-op.  Everything should be O_LARGEFILE by default.
> 
> But: when fanotify does create_fd() it uses dentry_open(), which skips
> all that.  And userspace can't set O_LARGEFILE in fanotify_init()
> because it's defined to 0.  So if fanotify gets an event regarding a
> large file, the read() will just fail with -EOVERFLOW.
> 
> This patch adds O_LARGEFILE to fanotify_init()'s event_f_flags on 64-bit
> systems, using the same test as open()/openat()/etc.
> 
> Addresses https://bugzilla.redhat.com/show_bug.cgi?id=696821
> 
> Signed-off-by: Will Woods <wwoods@redhat.com>
> Acked-by: Eric Paris <eparis@redhat.com>
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> (back ported from commit 1e2ee49f7f1b79f0b14884fe6a602f0411b39552)
> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
> ---
>  fs/notify/fanotify/fanotify_user.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index cc80b0a..864bd62 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -727,6 +727,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
>  	group->fanotify_data.user = user;
>  	atomic_inc(&user->fanotify_listeners);
>  
> +	if (force_o_largefile())
> +		event_f_flags |= O_LARGEFILE;
>  	group->fanotify_data.f_flags = event_f_flags;
>  #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
>  	mutex_init(&group->fanotify_data.access_mutex);
> -- 
> 1.9.1
> 
> 

Looks fine.

 -Kamal
Andy Whitcroft Dec. 20, 2015, 2:43 p.m. UTC | #2
On Fri, Dec 18, 2015 at 05:59:49AM -0700, tim.gardner@canonical.com wrote:
> From: Will Woods <wwoods@redhat.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1527039
> 
> On 64-bit systems, O_LARGEFILE is automatically added to flags inside
> the open() syscall (also openat(), blkdev_open(), etc).  Userspace
> therefore defines O_LARGEFILE to be 0 - you can use it, but it's a
> no-op.  Everything should be O_LARGEFILE by default.
> 
> But: when fanotify does create_fd() it uses dentry_open(), which skips
> all that.  And userspace can't set O_LARGEFILE in fanotify_init()
> because it's defined to 0.  So if fanotify gets an event regarding a
> large file, the read() will just fail with -EOVERFLOW.
> 
> This patch adds O_LARGEFILE to fanotify_init()'s event_f_flags on 64-bit
> systems, using the same test as open()/openat()/etc.
> 
> Addresses https://bugzilla.redhat.com/show_bug.cgi?id=696821
> 
> Signed-off-by: Will Woods <wwoods@redhat.com>
> Acked-by: Eric Paris <eparis@redhat.com>
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> (back ported from commit 1e2ee49f7f1b79f0b14884fe6a602f0411b39552)
> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
> ---
>  fs/notify/fanotify/fanotify_user.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index cc80b0a..864bd62 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -727,6 +727,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
>  	group->fanotify_data.user = user;
>  	atomic_inc(&user->fanotify_listeners);
>  
> +	if (force_o_largefile())
> +		event_f_flags |= O_LARGEFILE;
>  	group->fanotify_data.f_flags = event_f_flags;
>  #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
>  	mutex_init(&group->fanotify_data.access_mutex);


Looks to do what is claimed.

Acked-by: Andy Whitcroft <apw@canonical.com>

-apw
Kamal Mostafa Dec. 21, 2015, 7:47 p.m. UTC | #3

diff mbox

Patch

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index cc80b0a..864bd62 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -727,6 +727,8 @@  SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
 	group->fanotify_data.user = user;
 	atomic_inc(&user->fanotify_listeners);
 
+	if (force_o_largefile())
+		event_f_flags |= O_LARGEFILE;
 	group->fanotify_data.f_flags = event_f_flags;
 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
 	mutex_init(&group->fanotify_data.access_mutex);