All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/3] ext4: propagate error if creation of directory entry fails
Date: Thu, 18 Aug 2016 16:45:58 +0200	[thread overview]
Message-ID: <20160818164558.64b3840c@amdc2363> (raw)
In-Reply-To: <75ade8f4c4da44ffab424ff310a6c045@rwthex-w2-b.rwth-ad.de>

Hi Stefan,

> In case the dir entry creation failed, ext4fs_write would later
> overwrite a random inode, as inodeno was never initialized.
> 
> Signed-off-by: Stefan Br?ns <stefan.bruens@rwth-aachen.de>
> ---
>  fs/ext4/ext4_common.c | 12 ++++++------
>  fs/ext4/ext4_common.h |  2 +-
>  fs/ext4/ext4_write.c  |  4 +++-
>  3 files changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
> index 3ecd9a8..b8c37cf 100644
> --- a/fs/ext4/ext4_common.c
> +++ b/fs/ext4/ext4_common.c
> @@ -344,7 +344,7 @@ static int check_void_in_dentry(struct
> ext2_dirent *dir, char *filename) return 0;
>  }
>  
> -void ext4fs_update_parent_dentry(char *filename, int *p_ino, int
> file_type) +int ext4fs_update_parent_dentry(char *filename, int
> file_type) {
>  	unsigned int *zero_buffer = NULL;
>  	char *root_first_block_buffer = NULL;
> @@ -358,7 +358,7 @@ void ext4fs_update_parent_dentry(char *filename,
> int *p_ino, int file_type) unsigned int last_entry_dirlen;
>  	int sizeof_void_space = 0;
>  	int templength = 0;
> -	int inodeno;
> +	int inodeno = -1;
>  	int status;
>  	struct ext_filesystem *fs = get_fs();
>  	/* directory entry */
> @@ -371,13 +371,13 @@ void ext4fs_update_parent_dentry(char
> *filename, int *p_ino, int file_type) zero_buffer = zalloc(fs->blksz);
>  	if (!zero_buffer) {
>  		printf("No Memory\n");
> -		return;
> +		return -1;
>  	}
>  	root_first_block_buffer = zalloc(fs->blksz);
>  	if (!root_first_block_buffer) {
>  		free(zero_buffer);
>  		printf("No Memory\n");
> -		return;
> +		return -1;
>  	}
>  restart:
>  
> @@ -496,8 +496,6 @@ restart:
>  	temp_dir = temp_dir + sizeof(struct ext2_dirent);
>  	memcpy(temp_dir, filename, strlen(filename));
>  
> -	*p_ino = inodeno;
> -
>  	/* update or write  the 1st block of root inode */
>  	if (ext4fs_put_metadata(root_first_block_buffer,
>  				first_block_no_of_root))
> @@ -506,6 +504,8 @@ restart:
>  fail:
>  	free(zero_buffer);
>  	free(root_first_block_buffer);
> +
> +	return inodeno;
>  }
>  
>  static int search_dir(struct ext2_inode *parent_inode, char *dirname)
> diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h
> index 370a717..cc9d0c5 100644
> --- a/fs/ext4/ext4_common.h
> +++ b/fs/ext4/ext4_common.h
> @@ -61,7 +61,7 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir,
> char *name, uint32_t ext4fs_div_roundup(uint32_t size, uint32_t n);
>  uint16_t ext4fs_checksum_update(unsigned int i);
>  int ext4fs_get_parent_inode_num(const char *dirname, char *dname,
> int flags); -void ext4fs_update_parent_dentry(char *filename, int
> *p_ino, int file_type); +int ext4fs_update_parent_dentry(char
> *filename, int file_type); uint32_t ext4fs_get_new_blk_no(void);
>  int ext4fs_get_new_inode_no(void);
>  void ext4fs_reset_block_bmap(long int blockno, unsigned char *buffer,
> diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
> index f5811aa..4235b95 100644
> --- a/fs/ext4/ext4_write.c
> +++ b/fs/ext4/ext4_write.c
> @@ -890,7 +890,9 @@ int ext4fs_write(const char *fname, unsigned char
> *buffer, goto fail;
>  	}
>  
> -	ext4fs_update_parent_dentry(filename, &inodeno,
> FILETYPE_REG);
> +	inodeno = ext4fs_update_parent_dentry(filename,
> FILETYPE_REG);
> +	if (inodeno == -1)
> +		goto fail;
>  	/* prepare file inode */
>  	inode_buffer = zalloc(fs->inodesz);
>  	if (!inode_buffer)

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

  reply	other threads:[~2016-08-18 14:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20160814144143.24301-1-stefan.bruens@rwth-aachen.de>
2016-08-14 14:41 ` [U-Boot] [PATCH 1/3 v2] ext4: fix possible crash on directory traversal, ignore deleted entries Stefan Brüns
2016-08-18 14:44   ` Lukasz Majewski
2016-08-14 14:41 ` [U-Boot] [PATCH 2/3] ext4: propagate error if creation of directory entry fails Stefan Brüns
2016-08-18 14:45   ` Lukasz Majewski [this message]
2016-08-14 14:41 ` [U-Boot] [PATCH 3/3] ext4: Do not crash when trying to grow a directory using extents Stefan Brüns
2016-08-18 14:48   ` Lukasz Majewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160818164558.64b3840c@amdc2363 \
    --to=l.majewski@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.