diff mbox series

[v2,09/10] syscalls/fanotify20: Test file event with broken inode

Message ID 20211026184239.151156-10-krisman@collabora.com
State Superseded
Headers show
Series Test the new fanotify FAN_FS_ERROR event | expand

Commit Message

Gabriel Krisman Bertazi Oct. 26, 2021, 6:42 p.m. UTC
This test corrupts an inode entry with an invalid mode through debugfs
and then tries to access it.  This should result in a ext4 error, which
we monitor through the fanotify group.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
---
 .../kernel/syscalls/fanotify/fanotify20.c     | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Amir Goldstein Oct. 27, 2021, 9:57 a.m. UTC | #1
On Tue, Oct 26, 2021 at 9:44 PM Gabriel Krisman Bertazi
<krisman@collabora.com> wrote:
>
> This test corrupts an inode entry with an invalid mode through debugfs
> and then tries to access it.  This should result in a ext4 error, which
> we monitor through the fanotify group.
>
> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>

Reviewed-by: Amir Goldstein <amir73il@gmail.com>

> ---
>  .../kernel/syscalls/fanotify/fanotify20.c     | 22 +++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c
> index 5c5ee3c6fb74..7bcddcaa98cb 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify20.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify20.c
> @@ -38,6 +38,10 @@
>  #define        FILEID_INVALID          0xff
>  #endif
>
> +#ifndef EFSCORRUPTED
> +#define EFSCORRUPTED    EUCLEAN         /* Filesystem is corrupted */
> +#endif
> +
>  #define BUF_SIZE 256
>  static char event_buf[BUF_SIZE];
>  int fd_notify;
> @@ -63,6 +67,17 @@ static void trigger_fs_abort(void)
>                    MS_REMOUNT|MS_RDONLY, "abort");
>  }
>
> +static void tcase2_trigger_lookup(void)
> +{
> +       int ret;
> +
> +       /* SAFE_OPEN cannot be used here because we expect it to fail. */
> +       ret = open(MOUNT_PATH"/"BAD_DIR, O_RDONLY, 0);
> +       if (ret != -1 && errno != EUCLEAN)
> +               tst_res(TFAIL, "Unexpected lookup result(%d) of %s (%d!=%d)",
> +                       ret, BAD_DIR, errno, EUCLEAN);
> +}
> +
>  static struct test_case {
>         char *name;
>         int error;
> @@ -77,6 +92,13 @@ static struct test_case {
>                 .error = ESHUTDOWN,
>                 .fid = &null_fid,
>         },
> +       {
> +               .name = "Lookup of inode with invalid mode",
> +               .trigger_error = &tcase2_trigger_lookup,
> +               .error_count = 1,
> +               .error = EFSCORRUPTED,
> +               .fid = &bad_file_fid,
> +       },
>  };
>
>  int check_error_event_info_fid(struct fanotify_event_info_fid *fid,
> --
> 2.33.0
>
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c
index 5c5ee3c6fb74..7bcddcaa98cb 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify20.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify20.c
@@ -38,6 +38,10 @@ 
 #define	FILEID_INVALID		0xff
 #endif
 
+#ifndef EFSCORRUPTED
+#define EFSCORRUPTED    EUCLEAN         /* Filesystem is corrupted */
+#endif
+
 #define BUF_SIZE 256
 static char event_buf[BUF_SIZE];
 int fd_notify;
@@ -63,6 +67,17 @@  static void trigger_fs_abort(void)
 		   MS_REMOUNT|MS_RDONLY, "abort");
 }
 
+static void tcase2_trigger_lookup(void)
+{
+	int ret;
+
+	/* SAFE_OPEN cannot be used here because we expect it to fail. */
+	ret = open(MOUNT_PATH"/"BAD_DIR, O_RDONLY, 0);
+	if (ret != -1 && errno != EUCLEAN)
+		tst_res(TFAIL, "Unexpected lookup result(%d) of %s (%d!=%d)",
+			ret, BAD_DIR, errno, EUCLEAN);
+}
+
 static struct test_case {
 	char *name;
 	int error;
@@ -77,6 +92,13 @@  static struct test_case {
 		.error = ESHUTDOWN,
 		.fid = &null_fid,
 	},
+	{
+		.name = "Lookup of inode with invalid mode",
+		.trigger_error = &tcase2_trigger_lookup,
+		.error_count = 1,
+		.error = EFSCORRUPTED,
+		.fid = &bad_file_fid,
+	},
 };
 
 int check_error_event_info_fid(struct fanotify_event_info_fid *fid,