From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
Eric Paris <eparis@redhat.com>
Subject: [24/39] inotify: race use after free/double free in inotify inode marks
Date: Mon, 24 May 2010 16:15:36 -0700 [thread overview]
Message-ID: <20100524231815.356917096@clark.site> (raw)
In-Reply-To: <20100524231840.GA17857@kroah.com>
2.6.33-stable review patch. If anyone has any objections, please let us know.
------------------
From: Eric Paris <eparis@redhat.com>
commit e08733446e72b983fed850fc5d8bd21b386feb29 upstream.
There is a race in the inotify add/rm watch code. A task can find and
remove a mark which doesn't have all of it's references. This can
result in a use after free/double free situation.
Task A Task B
------------ -----------
inotify_new_watch()
allocate a mark (refcnt == 1)
add it to the idr
inotify_rm_watch()
inotify_remove_from_idr()
fsnotify_put_mark()
refcnt hits 0, free
take reference because we are on idr
[at this point it is a use after free]
[time goes on]
refcnt may hit 0 again, double free
The fix is to take the reference BEFORE the object can be found in the
idr.
Signed-off-by: Eric Paris <eparis@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
fs/notify/inotify/inotify_user.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -550,21 +550,24 @@ retry:
if (unlikely(!idr_pre_get(&group->inotify_data.idr, GFP_KERNEL)))
goto out_err;
+ /* we are putting the mark on the idr, take a reference */
+ fsnotify_get_mark(&tmp_ientry->fsn_entry);
+
spin_lock(&group->inotify_data.idr_lock);
ret = idr_get_new_above(&group->inotify_data.idr, &tmp_ientry->fsn_entry,
group->inotify_data.last_wd+1,
&tmp_ientry->wd);
spin_unlock(&group->inotify_data.idr_lock);
if (ret) {
+ /* we didn't get on the idr, drop the idr reference */
+ fsnotify_put_mark(&tmp_ientry->fsn_entry);
+
/* idr was out of memory allocate and try again */
if (ret == -EAGAIN)
goto retry;
goto out_err;
}
- /* we put the mark on the idr, take a reference */
- fsnotify_get_mark(&tmp_ientry->fsn_entry);
-
/* we are on the idr, now get on the inode */
ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode);
if (ret) {
next prev parent reply other threads:[~2010-05-24 23:28 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-24 23:18 [00/39] 2.6.33.5-stable review Greg KH
2010-05-24 23:15 ` [01/39] ipv4: udp: fix short packet and bad checksum logging Greg KH
2010-05-24 23:15 ` [02/39] hp_accel: fix race in device removal Greg KH
2010-05-24 23:15 ` [03/39] fbdev: bfin-t350mcqb-fb: fix fbmem allocation with blanking lines Greg KH
2010-05-24 23:15 ` [04/39] hugetlbfs: kill applications that use MAP_NORESERVE with SIGBUS instead of OOM-killer Greg KH
2010-05-24 23:15 ` [05/39] dma-mapping: fix dma_sync_single_range_* Greg KH
2010-05-24 23:15 ` [06/39] ALSA: Revert "ALSA: hda/realtek: quirk for D945GCLF2 mainboard" Greg KH
2010-05-24 23:15 ` [07/39] revert "procfs: provide stack information for threads" and its fixup commits Greg KH
2010-05-24 23:15 ` [08/39] ALSA: hda - fix DG45ID SPDIF output Greg KH
2010-05-24 23:15 ` [09/39] ACPI: sleep: eliminate duplicate entries in acpisleep_dmi_table[] Greg KH
2010-05-24 23:15 ` [10/39] mmc: atmel-mci: fix two parameters swapped Greg KH
2010-05-24 23:15 ` [11/39] mmc: atmel-mci: prevent kernel oops while removing card Greg KH
2010-05-24 23:15 ` [12/39] mmc: atmel-mci: remove data error interrupt after xfer Greg KH
2010-05-24 23:15 ` [13/39] drm/i915: use PIPE_CONTROL instruction on Ironlake and Sandy Bridge Greg KH
2010-05-24 23:15 ` [14/39] drm/i915: fix non-Ironlake 965 class crashes Greg KH
2010-05-24 23:15 ` [15/39] [S390] ptrace: fix return value of do_syscall_trace_enter() Greg KH
2010-05-24 23:15 ` [16/39] [S390] dasd: fix race between tasklet and dasd_sleep_on Greg KH
2010-05-24 23:15 ` [17/39] powerpc/perf_event: Fix oops due to perf_event_do_pending call Greg KH
2010-05-24 23:15 ` [18/39] cifs: guard against hardlinking directories Greg KH
2010-05-24 23:15 ` [19/39] serial: imx.c: fix CTS trigger level lower to avoid lost chars Greg KH
2010-05-24 23:15 ` [20/39] tty: Fix unbalanced BKL handling in error path Greg KH
2010-05-24 23:15 ` [21/39] ALSA: ice1724 - Fix ESI Maya44 capture source control Greg KH
2010-05-24 23:15 ` [22/39] ALSA: virtuoso: fix Xonar D1/DX front panel microphone Greg KH
2010-05-24 23:15 ` [23/39] ALSA: hda: Fix 0 dB for Lenovo models using Conexant CX20549 (Venice) Greg KH
2010-05-24 23:15 ` Greg KH [this message]
2010-05-24 23:15 ` [25/39] inotify: dont leak user struct on inotify release Greg KH
2010-05-24 23:15 ` [26/39] profile: fix stats and data leakage Greg KH
2010-05-24 23:15 ` [27/39] x86, k8: Fix build error when K8_NB is disabled Greg KH
2010-05-24 23:15 ` [28/39] x86, cacheinfo: Turn off L3 cache index disable feature in virtualized environments Greg KH
2010-05-25 1:50 ` Hugh Dickins
2010-05-25 17:14 ` Greg KH
2010-05-25 20:41 ` Hugh Dickins
2010-05-25 20:50 ` Greg KH
2010-05-24 23:15 ` [29/39] x86, amd: Check X86_FEATURE_OSVW bit before accessing OSVW MSRs Greg KH
2010-05-24 23:15 ` [30/39] Btrfs: check for read permission on src file in the clone ioctl Greg KH
2010-05-24 23:15 ` [31/39] ALSA: hda - New Intel HDA controller Greg KH
2010-05-24 23:15 ` [32/39] drm/i915: Disable FBC on 915GM and 945GM Greg KH
2010-05-24 23:15 ` [33/39] iwlwifi: check for aggregation frame and queue Greg KH
2010-05-24 23:15 ` [34/39] iwlwifi: clear all the stop_queue flag after load firmware Greg KH
2010-05-24 23:15 ` [35/39] CacheFiles: Fix error handling in cachefiles_determine_cache_security() Greg KH
2010-05-24 23:15 ` [36/39] mmap_min_addr check CAP_SYS_RAWIO only for write Greg KH
2010-05-24 23:15 ` [37/39] nilfs2: fix sync silent failure Greg KH
2010-05-24 23:15 ` [38/39] Revert "ath9k: fix lockdep warning when unloading module" on stable kernels Greg KH
2010-05-24 23:15 ` [39/39] crypto: authenc - Add EINPROGRESS check 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=20100524231815.356917096@clark.site \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=eparis@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable-review@kernel.org \
--cc=stable@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