From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk, Jan Kara <jack@suse.cz>
Subject: [20/40] udf: Fix deadlock when converting file from in-ICB one to normal one
Date: Tue, 10 Jan 2012 13:45:33 -0800 [thread overview]
Message-ID: <20120110214619.941624844@clark.kroah.org> (raw)
In-Reply-To: <20120110214630.GA14384@kroah.com>
3.0-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <jack@suse.cz>
commit d2eb8c359309ec45d6bf5b147303ab8e13be86ea upstream.
During BKL removal in 2.6.38, conversion of files from in-ICB format to normal
format got broken. We call ->writepage with i_data_sem held but udf_get_block()
also acquires i_data_sem thus creating A-A deadlock.
We fix the problem by dropping i_data_sem before calling ->writepage() which is
safe since i_mutex still protects us against any changes in the file. Also fix
pagelock - i_data_sem lock inversion in udf_expand_file_adinicb() by dropping
i_data_sem before calling find_or_create_page().
Reported-by: Matthias Matiak <netzpython@mail-on.us>
Tested-by: Matthias Matiak <netzpython@mail-on.us>
Reviewed-by: Namjae Jeon <linkinjeon@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
fs/udf/file.c | 6 +++---
fs/udf/inode.c | 21 ++++++++++++++++++---
2 files changed, 21 insertions(+), 6 deletions(-)
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -125,7 +125,6 @@ static ssize_t udf_file_aio_write(struct
err = udf_expand_file_adinicb(inode);
if (err) {
udf_debug("udf_expand_adinicb: err=%d\n", err);
- up_write(&iinfo->i_data_sem);
return err;
}
} else {
@@ -133,9 +132,10 @@ static ssize_t udf_file_aio_write(struct
iinfo->i_lenAlloc = pos + count;
else
iinfo->i_lenAlloc = inode->i_size;
+ up_write(&iinfo->i_data_sem);
}
- }
- up_write(&iinfo->i_data_sem);
+ } else
+ up_write(&iinfo->i_data_sem);
retval = generic_file_aio_write(iocb, iov, nr_segs, ppos);
if (retval > 0)
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -145,6 +145,12 @@ const struct address_space_operations ud
.bmap = udf_bmap,
};
+/*
+ * Expand file stored in ICB to a normal one-block-file
+ *
+ * This function requires i_data_sem for writing and releases it.
+ * This function requires i_mutex held
+ */
int udf_expand_file_adinicb(struct inode *inode)
{
struct page *page;
@@ -163,9 +169,15 @@ int udf_expand_file_adinicb(struct inode
iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
/* from now on we have normal address_space methods */
inode->i_data.a_ops = &udf_aops;
+ up_write(&iinfo->i_data_sem);
mark_inode_dirty(inode);
return 0;
}
+ /*
+ * Release i_data_sem so that we can lock a page - page lock ranks
+ * above i_data_sem. i_mutex still protects us against file changes.
+ */
+ up_write(&iinfo->i_data_sem);
page = find_or_create_page(inode->i_mapping, 0, GFP_NOFS);
if (!page)
@@ -181,6 +193,7 @@ int udf_expand_file_adinicb(struct inode
SetPageUptodate(page);
kunmap(page);
}
+ down_write(&iinfo->i_data_sem);
memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr, 0x00,
iinfo->i_lenAlloc);
iinfo->i_lenAlloc = 0;
@@ -190,17 +203,20 @@ int udf_expand_file_adinicb(struct inode
iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
/* from now on we have normal address_space methods */
inode->i_data.a_ops = &udf_aops;
+ up_write(&iinfo->i_data_sem);
err = inode->i_data.a_ops->writepage(page, &udf_wbc);
if (err) {
/* Restore everything back so that we don't lose data... */
lock_page(page);
kaddr = kmap(page);
+ down_write(&iinfo->i_data_sem);
memcpy(iinfo->i_ext.i_data + iinfo->i_lenEAttr, kaddr,
inode->i_size);
kunmap(page);
unlock_page(page);
iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
inode->i_data.a_ops = &udf_adinicb_aops;
+ up_write(&iinfo->i_data_sem);
}
page_cache_release(page);
mark_inode_dirty(inode);
@@ -1105,10 +1121,9 @@ int udf_setsize(struct inode *inode, lof
if (bsize <
(udf_file_entry_alloc_offset(inode) + newsize)) {
err = udf_expand_file_adinicb(inode);
- if (err) {
- up_write(&iinfo->i_data_sem);
+ if (err)
return err;
- }
+ down_write(&iinfo->i_data_sem);
} else
iinfo->i_lenAlloc = newsize;
}
next prev parent reply other threads:[~2012-01-10 22:57 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-10 21:46 [00/40] 3.0.17-stable review Greg KH
2012-01-10 21:45 ` [01/40] MAINTAINERS: stable: Update address Greg KH
2012-01-10 21:45 ` [02/40] Documentation: Update stable address Greg KH
2012-01-10 21:45 ` [03/40] firmware: Fix an oops on reading fw_priv->fw in sysfs loading file Greg KH
2012-01-10 21:45 ` [04/40] rt2800usb: Move ID out of unknown Greg KH
2012-01-10 21:45 ` [05/40] offb: Fix setting of the pseudo-palette for >8bpp Greg KH
2012-01-10 21:45 ` [06/40] offb: Fix bug in calculating requested vram size Greg KH
2012-01-10 21:45 ` [07/40] wl12xx: Validate FEM index from ini file and FW Greg KH
2012-01-10 21:45 ` [08/40] wl12xx: Check buffer bound when processing nvs data Greg KH
2012-01-10 21:45 ` [09/40] powerpc/time: Handle wrapping of decrementer Greg KH
2012-01-10 21:45 ` [10/40] powerpc: Fix unpaired probe_hcall_entry and probe_hcall_exit Greg KH
2012-01-10 21:45 ` [11/40] asix: new device id Greg KH
2012-01-10 21:45 ` [12/40] IB/qib: Fix a possible data corruption when receiving packets Greg KH
2012-01-10 21:45 ` [13/40] perf: Fix parsing of __print_flags() in TP_printk() Greg KH
2012-01-10 21:45 ` [14/40] reiserfs: Fix quota mount option parsing Greg KH
2012-01-10 21:45 ` [15/40] reiserfs: Force inode evictions before umount to avoid crash Greg KH
2012-01-10 21:45 ` [16/40] ext3: Dont warn from writepage when readonly inode is spotted after error Greg KH
2012-01-10 21:45 ` [17/40] USB: update documentation for usbmon Greg KH
2012-01-10 21:45 ` [18/40] atmel_serial: fix spinlock lockup in RS485 code Greg KH
2012-01-10 21:45 ` [19/40] cgroup: fix to allow mounting a hierarchy by name Greg KH
2012-01-10 21:45 ` Greg KH [this message]
2012-01-10 21:45 ` [21/40] drivers/usb/class/cdc-acm.c: clear dangling pointer Greg KH
2012-01-10 21:45 ` [22/40] USB: isight: fix kernel bug when loading firmware Greg KH
2012-01-10 21:45 ` [23/40] usb: usb-storage doesnt support dynamic id currently, the patch disables the feature to fix an oops Greg KH
2012-01-10 21:45 ` [24/40] USB: add quirk for another camera Greg KH
2012-01-10 21:45 ` [25/40] usb: musb: fix pm_runtime mismatch Greg KH
2012-01-10 21:45 ` [26/40] USB: omninet: fix write_room Greg KH
2012-01-10 21:45 ` [27/40] USB: Add USB-ID for Multiplex RC serial adapter to cp210x.c Greg KH
2012-01-10 21:45 ` [28/40] usb: fix number of mapped SG DMA entries Greg KH
2012-01-10 21:45 ` [29/40] xhci: Properly handle COMP_2ND_BW_ERR Greg KH
2012-01-10 21:45 ` [30/40] USB: option: add id for 3G dongle Model VT1000 of Viettel Greg KH
2012-01-10 21:45 ` [31/40] usb: option: add ZD Incorporated HSPA modem Greg KH
2012-01-10 21:45 ` [32/40] usb: ch9: fix up MaxStreams helper Greg KH
2012-01-10 21:45 ` [33/40] OHCI: final fix for NVIDIA problems (I hope) Greg KH
2012-01-10 21:45 ` [34/40] igmp: Avoid zero delay when receiving odd mixture of IGMP queries Greg KH
2012-01-10 21:45 ` [35/40] asix: fix infinite loop in rx_fixup() Greg KH
2012-01-10 21:45 ` [36/40] bonding: fix error handling if slave is busy (v2) Greg KH
2012-01-10 21:45 ` [37/40] PM / Sleep: Fix race between CPU hotplug and freezer Greg KH
2012-01-10 21:45 ` [38/40] SCSI: mpt2sas: Added missing mpt2sas_base_detach call from scsih_remove context Greg KH
2012-01-10 21:45 ` [39/40] usb: cdc-acm: Fix acm_tty_hangup() vs. acm_tty_close() race Greg KH
2012-01-10 21:45 ` [40/40] xfs: fix acl count validation in xfs_acl_from_disk() Greg KH
2012-01-11 22:21 ` [00/40] 3.0.17-stable review Nick Bowler
2012-01-12 23:01 ` Greg KH
2012-01-12 23:15 ` David Miller
2012-01-17 17:47 ` Greg KH
2012-01-26 18:35 ` Greg KH
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=20120110214619.941624844@clark.kroah.org \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®