linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH 4.4 33/37] fix io_destroy()/aio_complete() race
Date: Tue,  5 Jun 2018 19:01:38 +0200	[thread overview]
Message-ID: <20180605170110.835706577@linuxfoundation.org> (raw)
In-Reply-To: <20180605170108.884872354@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Al Viro <viro@zeniv.linux.org.uk>

commit 4faa99965e027cc057c5145ce45fa772caa04e8d upstream.

If io_destroy() gets to cancelling everything that can be cancelled and
gets to kiocb_cancel() calling the function driver has left in ->ki_cancel,
it becomes vulnerable to a race with IO completion.  At that point req
is already taken off the list and aio_complete() does *NOT* spin until
we (in free_ioctx_users()) releases ->ctx_lock.  As the result, it proceeds
to kiocb_free(), freing req just it gets passed to ->ki_cancel().

Fix is simple - remove from the list after the call of kiocb_cancel().  All
instances of ->ki_cancel() already have to cope with the being called with
iocb still on list - that's what happens in io_cancel(2).

Cc: stable@kernel.org
Fixes: 0460fef2a921 "aio: use cancellation list lazily"
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/aio.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/fs/aio.c
+++ b/fs/aio.c
@@ -628,9 +628,8 @@ static void free_ioctx_users(struct perc
 	while (!list_empty(&ctx->active_reqs)) {
 		req = list_first_entry(&ctx->active_reqs,
 				       struct aio_kiocb, ki_list);
-
-		list_del_init(&req->ki_list);
 		kiocb_cancel(req);
+		list_del_init(&req->ki_list);
 	}
 
 	spin_unlock_irq(&ctx->ctx_lock);

  parent reply	other threads:[~2018-06-05 17:10 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 17:01 [PATCH 4.4 00/37] 4.4.136-stable review Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 01/37] arm64: lse: Add early clobbers to some input/output asm operands Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 02/37] powerpc/64s: Clear PCR on boot Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 03/37] USB: serial: cp210x: use tcflag_t to fix incompatible pointer type Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 04/37] sh: New gcc support Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 05/37] xfs: detect agfl count corruption and reset agfl Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 06/37] Revert "ima: limit file hash setting by user to fix and log modes" Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 07/37] Input: elan_i2c_smbus - fix corrupted stack Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 08/37] tracing: Fix crash when freeing instances with event triggers Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 09/37] selinux: KASAN: slab-out-of-bounds in xattr_getsecurity Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 10/37] cfg80211: further limit wiphy names to 64 bytes Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 11/37] rtlwifi: rtl8192cu: Remove variable self-assignment in rf.c Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 12/37] ASoC: Intel: sst: remove redundant variable dma_dev_name Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 13/37] irda: fix overly long udelay() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 14/37] tcp: avoid integer overflows in tcp_rcv_space_adjust() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 15/37] i2c: rcar: make sure clocks are on when doing clock calculation Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 16/37] i2c: rcar: rework hw init Greg Kroah-Hartman
2018-06-18 18:46   ` Ben Hutchings
2018-06-25 10:05     ` Fabrizio Castro
2018-06-05 17:01 ` [PATCH 4.4 17/37] i2c: rcar: remove unused IOERROR state Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 18/37] i2c: rcar: remove spinlock Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 19/37] i2c: rcar: refactor setup of a msg Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 20/37] i2c: rcar: init new messages in irq Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 21/37] i2c: rcar: dont issue stop when HW does it automatically Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 22/37] i2c: rcar: check master irqs before slave irqs Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 23/37] i2c: rcar: revoke START request early Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 24/37] dmaengine: usb-dmac: fix endless loop in usb_dmac_chan_terminate_all() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 25/37] iio:kfifo_buf: check for uint overflow Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 26/37] MIPS: ptrace: Fix PTRACE_PEEKUSR requests for 64-bit FGRs Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 27/37] MIPS: prctl: Disallow FRE without FR with PR_SET_FP_MODE requests Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 28/37] scsi: scsi_transport_srp: Fix shost to rport translation Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 29/37] stm class: Use vmalloc for the master map Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 30/37] hwtracing: stm: fix build error on some arches Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 32/37] Kbuild: change CC_OPTIMIZE_FOR_SIZE definition Greg Kroah-Hartman
2018-06-05 17:01 ` Greg Kroah-Hartman [this message]
2018-06-05 17:01 ` [PATCH 4.4 34/37] mm: fix the NULL mapping case in __isolate_lru_page() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 35/37] sparc64: Add __multi3 for gcc 7.x and later Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 36/37] sparc64: Dont clibber fixed registers in __multi4 Greg Kroah-Hartman
2018-06-05 21:59 ` [PATCH 4.4 00/37] 4.4.136-stable review Shuah Khan
2018-06-06  0:30 ` Nathan Chancellor
2018-06-06  8:19   ` Greg Kroah-Hartman
2018-06-06 11:18 ` Naresh Kamboju
2018-06-06 12:15   ` Greg Kroah-Hartman
2018-06-06 13:28 ` Guenter Roeck
2018-06-06 13:31   ` Greg Kroah-Hartman
2018-06-06 15:01     ` Guenter Roeck
2018-06-06 15:35       ` Greg Kroah-Hartman

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=20180605170110.835706577@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).