From patchwork Tue Oct 27 13:55:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 307142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1BC1C388F9 for ; Tue, 27 Oct 2020 17:25:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D1BC22281 for ; Tue, 27 Oct 2020 17:25:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603819547; bh=pczS5DlWXVa6fiIHMoBSKiiTtWrg4VUKcYl1CkNJuok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=OrXZ+X78yZiO1hqhg2W+j+Ta3VyReQNxw1LINS/R0gpaZoxdqfkkDwYZQTgWigiM+ EmZxGhlQ5EULGtKhNwJCKKtQ+Vg717xu1bQZLWGevhfumUOFQA9fPIuvQqJnoR40Ty INLc5xh6Vr1zd65CJc/iwDrKw3l/ALbPl6JL5LBM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1780091AbgJ0Oxw (ORCPT ); Tue, 27 Oct 2020 10:53:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:45626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763964AbgJ0Opo (ORCPT ); Tue, 27 Oct 2020 10:45:44 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 70FEB206E5; Tue, 27 Oct 2020 14:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809944; bh=pczS5DlWXVa6fiIHMoBSKiiTtWrg4VUKcYl1CkNJuok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AzOFhNprI73cIuIoLj7ApcS/jKMJA8cwWSqQ4xU6cmRsCL9kseesA24/XNLSyspeg k2MsEFQH129f5vYi8vCX5k9j60jHa8PTao/h5MwzYaLMCylszYFmE5X3RxrWbz2u59 pvlVYPtZf7cqaTrKkkmJHeK2X8a3KyG0Wo67vH+Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Christoph Hellwig , "Darrick J. Wong" , Sasha Levin Subject: [PATCH 5.4 374/408] iomap: fix WARN_ON_ONCE() from unprivileged users Date: Tue, 27 Oct 2020 14:55:12 +0100 Message-Id: <20201027135512.352207543@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Qian Cai [ Upstream commit a805c111650cdba6ee880f528abdd03c1af82089 ] It is trivial to trigger a WARN_ON_ONCE(1) in iomap_dio_actor() by unprivileged users which would taint the kernel, or worse - panic if panic_on_warn or panic_on_taint is set. Hence, just convert it to pr_warn_ratelimited() to let users know their workloads are racing. Thank Dave Chinner for the initial analysis of the racing reproducers. Signed-off-by: Qian Cai Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Sasha Levin --- fs/iomap/direct-io.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 7b5f76efef02d..8c98fd92bf665 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -377,6 +377,16 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length, return iomap_dio_bio_actor(inode, pos, length, dio, iomap); case IOMAP_INLINE: return iomap_dio_inline_actor(inode, pos, length, dio, iomap); + case IOMAP_DELALLOC: + /* + * DIO is not serialised against mmap() access at all, and so + * if the page_mkwrite occurs between the writeback and the + * iomap_apply() call in the DIO path, then it will see the + * DELALLOC block that the page-mkwrite allocated. + */ + pr_warn_ratelimited("Direct I/O collision with buffered writes! File: %pD4 Comm: %.20s\n", + dio->iocb->ki_filp, current->comm); + return -EIO; default: WARN_ON_ONCE(1); return -EIO;