diff mbox series

[v2,07/10] syscalls/fanotify20: Create a corrupted file

Message ID 20211026184239.151156-8-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
Allocate a test directory and corrupt it with debugfs.  The corruption
is done by writing an invalid inode mode.  This file can be later
looked up to trigger a corruption error.

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

Comments

Amir Goldstein Oct. 27, 2021, 6:51 a.m. UTC | #1
On Tue, Oct 26, 2021 at 9:44 PM Gabriel Krisman Bertazi
<krisman@collabora.com> wrote:
>
> Allocate a test directory and corrupt it with debugfs.  The corruption
> is done by writing an invalid inode mode.  This file can be later
> looked up to trigger a corruption error.
>
> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>

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

> ---
>  testcases/kernel/syscalls/fanotify/fanotify20.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c
> index 7c4b01720654..298bb303a810 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify20.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify20.c
> @@ -43,9 +43,12 @@ static char event_buf[BUF_SIZE];
>  int fd_notify;
>
>  #define MOUNT_PATH "test_mnt"
> +#define BASE_DIR "internal_dir"
> +#define BAD_DIR BASE_DIR"/bad_dir"
>
>  /* These expected FIDs are common to multiple tests */
>  static struct fanotify_fid_t null_fid;
> +static struct fanotify_fid_t bad_file_fid;
>
>  static void do_debugfs_request(const char *dev, char *request)
>  {
> @@ -182,6 +185,18 @@ static void do_test(unsigned int i)
>         check_event(event_buf, read_len, tcase);
>  }
>
> +static void pre_corrupt_fs(void)
> +{
> +       SAFE_MKDIR(MOUNT_PATH"/"BASE_DIR, 0777);
> +       SAFE_MKDIR(MOUNT_PATH"/"BAD_DIR, 0777);
> +
> +       fanotify_save_fid(MOUNT_PATH"/"BAD_DIR, &bad_file_fid);
> +
> +       SAFE_UMOUNT(MOUNT_PATH);
> +       do_debugfs_request(tst_device->dev, "sif " BAD_DIR " mode 0xff");
> +       SAFE_MOUNT(tst_device->dev, MOUNT_PATH, tst_device->fs_type, 0, NULL);
> +}
> +
>  static void init_null_fid(void)
>  {
>         /* Use fanotify_save_fid to fill the fsid and overwrite the
> @@ -201,6 +216,8 @@ static void setup(void)
>
>         init_null_fid();
>
> +       pre_corrupt_fs();
> +
>         fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF|FAN_REPORT_FID,
>                                        O_RDONLY);
>
> --
> 2.33.0
>
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c
index 7c4b01720654..298bb303a810 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify20.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify20.c
@@ -43,9 +43,12 @@  static char event_buf[BUF_SIZE];
 int fd_notify;
 
 #define MOUNT_PATH "test_mnt"
+#define BASE_DIR "internal_dir"
+#define BAD_DIR BASE_DIR"/bad_dir"
 
 /* These expected FIDs are common to multiple tests */
 static struct fanotify_fid_t null_fid;
+static struct fanotify_fid_t bad_file_fid;
 
 static void do_debugfs_request(const char *dev, char *request)
 {
@@ -182,6 +185,18 @@  static void do_test(unsigned int i)
 	check_event(event_buf, read_len, tcase);
 }
 
+static void pre_corrupt_fs(void)
+{
+	SAFE_MKDIR(MOUNT_PATH"/"BASE_DIR, 0777);
+	SAFE_MKDIR(MOUNT_PATH"/"BAD_DIR, 0777);
+
+	fanotify_save_fid(MOUNT_PATH"/"BAD_DIR, &bad_file_fid);
+
+	SAFE_UMOUNT(MOUNT_PATH);
+	do_debugfs_request(tst_device->dev, "sif " BAD_DIR " mode 0xff");
+	SAFE_MOUNT(tst_device->dev, MOUNT_PATH, tst_device->fs_type, 0, NULL);
+}
+
 static void init_null_fid(void)
 {
 	/* Use fanotify_save_fid to fill the fsid and overwrite the
@@ -201,6 +216,8 @@  static void setup(void)
 
 	init_null_fid();
 
+	pre_corrupt_fs();
+
 	fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF|FAN_REPORT_FID,
 				       O_RDONLY);