Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp768850ybc; Sat, 16 Nov 2019 08:21:37 -0800 (PST) X-Google-Smtp-Source: APXvYqyD//l43441V6Th7JkBTsJrWPPQR/AM9VRNgSRF6druQ0AK6V0AXlsHnkkAMULh5tZI0tnt X-Received: by 2002:a17:906:a40e:: with SMTP id l14mr10974379ejz.168.1573921296926; Sat, 16 Nov 2019 08:21:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921296; cv=none; d=google.com; s=arc-20160816; b=AeftTc357l/+Wbp0fXa9Pk8l38RawjitSGhYofUF11df9tDuCyH5nAjHOZPt+qNvTw 8MKA6TIIL0yu65eJ9k+D9Iqv9dSjiluEOpfSgE5ICj81VslPjEa3e4P+9NNU1Flh/S6j gfZslVgxdb6QYtJV5ncS0IOV+GYwdhPRNsYpAbjWWOa0OzglnmqgBkPzJHJ0OzM0uYOQ 1pe8+VmWqmcxsECHANZHDW0wTVw+SIKQQ1EQ6VykHkGUrBDD8ovAGwEdgHQim1U3dLZ/ DFGL2OhMFvt8l7IFsiggmLNOagS2aY6qyirRR/rHZwDxlRWYrvEViq2/3hTRN3Hedmk+ k0qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Aiaq5hyAID4+h0aS3eixLK5s7YIkVUMOV8dDATRGzZE=; b=LL6JbL8s4K0UrAJ1U837fLU2vYRFFTw2amXq69+/R08781PU/tGLmEfDdZiRV6sGm5 gUDf7dISUPOgNaUXbhXFuSUa+SYBMUjc0XMzOk3KhIGH7ar+lquBvsBmc1eIPj8/9EL2 etlFRGe+469PrO0kEzJ6ap9eiXqRFjV4Jp6Rsd0MEhc0cjYU4Van3TLfFPuNzU8f5xZf o0RG148GsM9d24RQxTrTbkpvtZB/WlLkZQBjOaytTVowPmRdEnXCsWiS6XQwJ2PaOWV1 MxmAUHeDOIlyVmgaxZqEvLL62TVTHr9pW8qjKzwX5IrdW6yHpBwxb3DvcplqY/MxwASX H6mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IcfRhq7B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si9046204edc.410.2019.11.16.08.21.12; Sat, 16 Nov 2019 08:21:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IcfRhq7B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728781AbfKPPqj (ORCPT + 99 others); Sat, 16 Nov 2019 10:46:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:52404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728379AbfKPPqL (ORCPT ); Sat, 16 Nov 2019 10:46:11 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 652172077B; Sat, 16 Nov 2019 15:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573919170; bh=mKp2s/blIgMGrwn5l+GuCYtectkjp5AVSv8RFFXlJYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IcfRhq7Bg5PBAkq0A02sTqb1MATzKNkgQXzsHmRxoXkecygxGUxJ2v3/0313ZAUxH 9LSNb7yebYXTfcSqWqYnaSXccbO/7dq+rIgq+bHvtu6f9vvR7I9kQgHrnybBHMijSW Dc/kZ6YzJk3Th5kIvSU0Eb8ODEp0SrjrVqbgrQJU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Changwei Ge , Andrew Morton , Mark Fasheh , Joel Becker , Junxiao Bi , Joseph Qi , Linus Torvalds , Sasha Levin Subject: [PATCH AUTOSEL 4.19 180/237] ocfs2: don't use iocb when EIOCBQUEUED returns Date: Sat, 16 Nov 2019 10:40:15 -0500 Message-Id: <20191116154113.7417-180-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Changwei Ge [ Upstream commit 9e985787750db8aae87f02b67e908f28ac4d6b83 ] When -EIOCBQUEUED returns, it means that aio_complete() will be called from dio_complete(), which is an asynchronous progress against write_iter. Generally, IO is a very slow progress than executing instruction, but we still can't take the risk to access a freed iocb. And we do face a BUG crash issue. Using the crash tool, iocb is obviously freed already. crash> struct -x kiocb ffff881a350f5900 struct kiocb { ki_filp = 0xffff881a350f5a80, ki_pos = 0x0, ki_complete = 0x0, private = 0x0, ki_flags = 0x0 } And the backtrace shows: ocfs2_file_write_iter+0xcaa/0xd00 [ocfs2] aio_run_iocb+0x229/0x2f0 do_io_submit+0x291/0x540 SyS_io_submit+0x10/0x20 system_call_fastpath+0x16/0x75 Link: http://lkml.kernel.org/r/1523361653-14439-1-git-send-email-ge.changwei@h3c.com Signed-off-by: Changwei Ge Reviewed-by: Andrew Morton Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Joseph Qi Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/ocfs2/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index a847fe52c56ee..a3e077fcfeb9b 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -2389,7 +2389,7 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb, written = __generic_file_write_iter(iocb, from); /* buffered aio wouldn't have proper lock coverage today */ - BUG_ON(written == -EIOCBQUEUED && !(iocb->ki_flags & IOCB_DIRECT)); + BUG_ON(written == -EIOCBQUEUED && !direct_io); /* * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io @@ -2509,7 +2509,7 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb, trace_generic_file_read_iter_ret(ret); /* buffered aio wouldn't have proper lock coverage today */ - BUG_ON(ret == -EIOCBQUEUED && !(iocb->ki_flags & IOCB_DIRECT)); + BUG_ON(ret == -EIOCBQUEUED && !direct_io); /* see ocfs2_file_write_iter */ if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) { -- 2.20.1