From f44a0a3c6329900774a12b44ffa4f2caa86c018e Mon Sep 17 00:00:00 2001 From: Kaho Ng Date: Thu, 30 Jun 2016 05:30:28 +0800 Subject: [PATCH] ext4: add filetype checking to ext4_mknod --- src/ext4.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ext4.c b/src/ext4.c index 0f2f07a..7f10e11 100644 --- a/src/ext4.c +++ b/src/ext4.c @@ -2448,9 +2448,23 @@ int ext4_mknod(const char *path, int filetype, uint32_t dev) if (mp->fs.read_only) return EROFS; + /* + * The filetype shouldn't be normal file, directory or + * unknown. + */ if (filetype == EXT4_DE_UNKNOWN || filetype == EXT4_DE_REG_FILE || - filetype == EXT4_DE_DIR) + filetype == EXT4_DE_DIR || + filetype == EXT4_DE_SYMLINK) + return EINVAL; + + /* + * Nor should it be any bogus value. + */ + if (filetype != EXT4_DE_CHRDEV && + filetype != EXT4_DE_BLKDEV && + filetype != EXT4_DE_FIFO && + filetype != EXT4_DE_SOCK) return EINVAL; EXT4_MP_LOCK(mp);