diff mbox series

[7/9,linux-next] fanotify: don't write with zero size

Message ID 20200511180227.215152-1-fabf@skynet.be (mailing list archive)
State New, archived
Headers show
Series fs/notify: cleanup | expand

Commit Message

Fabian Frederick May 11, 2020, 6:02 p.m. UTC
check count in fanotify_write() and return -EINVAL when 0

Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/notify/fanotify/fanotify_user.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Amir Goldstein May 11, 2020, 9:49 p.m. UTC | #1
On Mon, May 11, 2020 at 9:02 PM Fabian Frederick <fabf@skynet.be> wrote:
>
> check count in fanotify_write() and return -EINVAL when 0
>
> Signed-off-by: Fabian Frederick <fabf@skynet.be>
> ---
>  fs/notify/fanotify/fanotify_user.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index 02a314acc757..6e19dacb2475 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -485,6 +485,9 @@ static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t
>         if (!IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS))
>                 return -EINVAL;
>
> +       if (!count)
> +               return -EINVAL;
> +

Maybe even (count < sizeof(response)) ?

>         group = file->private_data;
>
>         if (count > sizeof(response))
> --
> 2.26.2
>
diff mbox series

Patch

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 02a314acc757..6e19dacb2475 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -485,6 +485,9 @@  static ssize_t fanotify_write(struct file *file, const char __user *buf, size_t
 	if (!IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS))
 		return -EINVAL;
 
+	if (!count)
+		return -EINVAL;
+
 	group = file->private_data;
 
 	if (count > sizeof(response))