From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 D585BC43467 for ; Sun, 18 Oct 2020 19:56:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA2B522263 for ; Sun, 18 Oct 2020 19:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603050981; bh=Gk7Dcdr3qIZh/Hz9V0vphAF3SJqzWma+xLXxVQyVqmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ExGpZ9mNM79peadB9xaP6UCt5OYgFITZ5OPE+GUAc8o5aMhXm0I5FVGTdnmPFqnpM NxjAzgWuJMbF5nIQfNHq38ygZP5NpRC/QOo90H6aOQOvmifDA5sAvDokDYWvszEm0g j6qi0d5oflY4ikbR2gzy2D+VTbtRutVcqyoyzbIU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728406AbgJRTTn (ORCPT ); Sun, 18 Oct 2020 15:19:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:58468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728345AbgJRTTh (ORCPT ); Sun, 18 Oct 2020 15:19:37 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 D6C66222E9; Sun, 18 Oct 2020 19:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603048777; bh=Gk7Dcdr3qIZh/Hz9V0vphAF3SJqzWma+xLXxVQyVqmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FE6Fzhfc89RqqzCacfwsyMKM3gH1jkCNMmc7lTyu6asQ2a3ey8qp7tVhaiBxqfytx rT5XOHyFNkKDtvJOIsPmMWn6ct+GGIDcr4Sl5pvLi6fS22iy0K59588ltpaNkOV78p dAe7biwmLIxWoaLsjqRkERCJ9hsIJyb/q95Iht4k= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Qian Cai , Christoph Hellwig , "Darrick J . Wong" , Sasha Levin Subject: [PATCH AUTOSEL 5.9 075/111] iomap: fix WARN_ON_ONCE() from unprivileged users Date: Sun, 18 Oct 2020 15:17:31 -0400 Message-Id: <20201018191807.4052726-75-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201018191807.4052726-1-sashal@kernel.org> References: <20201018191807.4052726-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 c1aafb2ab9907..9519113ebc352 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -388,6 +388,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; -- 2.25.1