All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Alexey Khoroshilov <khoroshilov@ispras.ru>
Cc: Christoph Hellwig <hch@tuxera.com>,
	Anton Salikhmetov <alexo@tuxera.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	roman@ardistech.com, linux-kernel@vger.kernel.org,
	ldv-project@ispras.ru
Subject: Re: [PATCH 1/2] hfsplus: add error checking for hfs_find_init()
Date: Thu, 30 Jun 2011 07:42:42 -0400	[thread overview]
Message-ID: <20110630114242.GA9597@infradead.org> (raw)
In-Reply-To: <1308863702-30859-1-git-send-email-khoroshilov@ispras.ru>

On Fri, Jun 24, 2011 at 01:15:01AM +0400, Alexey Khoroshilov wrote:
> hfs_find_init() may fail with ENOMEM, but there are places, where
> the returned value is not checked. The consequences can be very
> unpleasant, e.g. kfree uninitialized pointer and
> inappropriate mutex unlocking.
> 
> The patch adds checks for errors in hfs_find_init().
> 
> Found by Linux Driver Verification project (linuxtesting.org).

What kind of testing did you do in detail?

> -	hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
> +	err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
> +	if (err)
> +		goto err_init;
>  
>  	hfsplus_cat_build_key(sb, fd.search_key, cnid, NULL);
>  	entry_size = hfsplus_fill_cat_thread(sb, &entry,
> @@ -255,6 +257,7 @@ err1:
>  		hfs_brec_remove(&fd);
>  err2:
>  	hfs_find_exit(&fd);
> +err_init:

Please just return the error directly unless there's something to
unwind, both here and in other places.

> @@ -124,9 +124,10 @@ static void hfsplus_ext_write_extent_locked(struct inode *inode)
>  	if (HFSPLUS_I(inode)->extent_state & HFSPLUS_EXT_DIRTY) {
>  		struct hfs_find_data fd;
>  
> -		hfs_find_init(HFSPLUS_SB(inode->i_sb)->ext_tree, &fd);
> -		__hfsplus_ext_write_extent(inode, &fd);
> -		hfs_find_exit(&fd);
> +		if (!hfs_find_init(HFSPLUS_SB(inode->i_sb)->ext_tree, &fd)) {
> +			__hfsplus_ext_write_extent(inode, &fd);
> +			hfs_find_exit(&fd);
> +		}
>  	}
>  }

This one need to be propagated back through the callers.

> @@ -523,7 +528,11 @@ void hfsplus_file_truncate(struct inode *inode)
>  		goto out;
>  
>  	mutex_lock(&hip->extents_lock);
> -	hfs_find_init(HFSPLUS_SB(sb)->ext_tree, &fd);
> +	res = hfs_find_init(HFSPLUS_SB(sb)->ext_tree, &fd);
> +	if (res) {
> +		mutex_unlock(&hip->extents_lock);
> +		return;
> +	}

At least add an XXX comment about the lack of error handling here.
Once hfsplus gets converted to the new truncate sequence we'll be
able to handle to return it.


  parent reply	other threads:[~2011-06-30 11:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-23 21:15 [PATCH 1/2] hfsplus: add error checking for hfs_find_init() Alexey Khoroshilov
2011-06-23 21:15 ` [PATCH 2/2] hfsplus: Fix double iput of the same inode in hfsplus_fill_super() Alexey Khoroshilov
2011-06-30 11:42   ` Christoph Hellwig
2011-06-30 11:42 ` Christoph Hellwig [this message]
2011-07-05 22:29   ` [PATCH v2 0/2] hfsplus: add error checking for hfs_find_init() Alexey Khoroshilov
2011-07-05 22:29     ` [PATCH v2 1/2] " Alexey Khoroshilov
2011-07-05 22:30     ` [PATCH v2 2/2] hfsplus: Add error propagation for hfsplus_ext_write_extent_locked Alexey Khoroshilov
2011-07-07 16:33     ` [PATCH v2 0/2] hfsplus: add error checking for hfs_find_init() Christoph Hellwig

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=20110630114242.GA9597@infradead.org \
    --to=hch@infradead.org \
    --cc=alexo@tuxera.com \
    --cc=hch@tuxera.com \
    --cc=khoroshilov@ispras.ru \
    --cc=ldv-project@ispras.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roman@ardistech.com \
    --cc=viro@zeniv.linux.org.uk \
    /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.