Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1035464pxb; Fri, 15 Apr 2022 19:06:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznGFKoPBl9pskfs2CIh39um19UAwLADml7mh67z2Bj0JXzT9BCC/Z2w8RbVo6irLspG/HH X-Received: by 2002:a17:902:bc8c:b0:151:8278:d2bf with SMTP id bb12-20020a170902bc8c00b001518278d2bfmr1742098plb.114.1650074815435; Fri, 15 Apr 2022 19:06:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650074815; cv=none; d=google.com; s=arc-20160816; b=ZR6LMLeAtDXyT+qQKJokBo4MqWwuOEqqPttivUE1bslLwJq6P0MbhYfBhXmUkiukw0 W57R+fzC4bcpvKC88fKJFxuNW8ehmEQ/n28R5yt/RZE3KoPI/nBuaPQ7XkDC+y6zLKv4 TlHxcHAq2jUvw9S2YwkC26o1r83VFycwLHvRuMPkJMtYdnBYZzNZjsSdJ4br0hx8zwyf HStTmppW8NubPz38DDRLFxHbQC0CcIL3V29oFHtA1ErjSKeKtDuQ+Ssaihhgqwk0jDgv 1/S7ml1R57tbHiXgTadHG8qz9edLv7mhcjw3XW04Gtlny82ljjloEMu8kQYGFDBLVCBx VS4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OLpxvPtsGIusLE7Ybk0mC46g+NAHrB93+i1qq+/DPTI=; b=mR7CDfiwD7IlaI5MUjv9uGmj+UbW2+Sik/4bZ5MGT9xK/u3qy3pG89ec397ncGh06Z teqd8UffgEWJgKVzE9qkr8NazxBr2IFe8gXl/5m2TeCyrVm59Bs2ueecQwLvnBpuMSmT d6jbXy9qZReD4wi+KxZY0++ZYlFe59U7kRAxKt0OTHS8cazqEDuAQw7D9IJQ2y0njaih 2xTpfp0DLTVdEuhEiVHsmfp8rNVB9yEpV7gL6pfyySfx+FPDeFT//rscAZFQCYI0UqH0 dvHq7zqv8iQHl9DbpshLyR+DMvEr2Kt+eUS8ardeMq6kw4cuL39iopeL3xjbq28FLpYU MFgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yxNlfYKn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id mw17-20020a17090b4d1100b001cd476d0e71si6219534pjb.82.2022.04.15.19.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:06:55 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yxNlfYKn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 31772119879; Fri, 15 Apr 2022 18:25:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231280AbiDNOFX (ORCPT + 99 others); Thu, 14 Apr 2022 10:05:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343891AbiDNNaE (ORCPT ); Thu, 14 Apr 2022 09:30:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1521B0D26; Thu, 14 Apr 2022 06:25:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 11940B82985; Thu, 14 Apr 2022 13:25:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D206C385A5; Thu, 14 Apr 2022 13:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649942729; bh=X9+QBqSy1pQQYXeuH+D28z07BYNcRuMRUFmFK7j86Wc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yxNlfYKn9COCY76g37iVzDMYsdIL1n282AeMQWmVlT2EPdClTqUjRsiFslsotnnXf BU5or+DGWtaOrJWPI58dfI3XqCJtiixAa1EvLHIHhgYUeBdmPE0esQY/AKEL9k5SYx 22pylTJCZEDk7q7fiSeIFGQKAYpEa/PJ+p6Ms0F4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+d59332e2db681cf18f0318a06e994ebbb529a8db@syzkaller.appspotmail.com, Lee Jones , Theodore Tso , Sasha Levin Subject: [PATCH 4.19 200/338] ext4: dont BUG if someone dirty pages without asking ext4 first Date: Thu, 14 Apr 2022 15:11:43 +0200 Message-Id: <20220414110844.587766421@linuxfoundation.org> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220414110838.883074566@linuxfoundation.org> References: <20220414110838.883074566@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Theodore Ts'o [ Upstream commit cc5095747edfb054ca2068d01af20be3fcc3634f ] [un]pin_user_pages_remote is dirtying pages without properly warning the file system in advance. A related race was noted by Jan Kara in 2018[1]; however, more recently instead of it being a very hard-to-hit race, it could be reliably triggered by process_vm_writev(2) which was discovered by Syzbot[2]. This is technically a bug in mm/gup.c, but arguably ext4 is fragile in that if some other kernel subsystem dirty pages without properly notifying the file system using page_mkwrite(), ext4 will BUG, while other file systems will not BUG (although data will still be lost). So instead of crashing with a BUG, issue a warning (since there may be potential data loss) and just mark the page as clean to avoid unprivileged denial of service attacks until the problem can be properly fixed. More discussion and background can be found in the thread starting at [2]. [1] https://lore.kernel.org/linux-mm/20180103100430.GE4911@quack2.suse.cz [2] https://lore.kernel.org/r/Yg0m6IjcNmfaSokM@google.com Reported-by: syzbot+d59332e2db681cf18f0318a06e994ebbb529a8db@syzkaller.appspotmail.com Reported-by: Lee Jones Signed-off-by: Theodore Ts'o Link: https://lore.kernel.org/r/YiDS9wVfq4mM2jGK@mit.edu Signed-off-by: Sasha Levin --- fs/ext4/inode.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 7959aae4857e..96cf0f57ca95 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2148,6 +2148,15 @@ static int ext4_writepage(struct page *page, else len = PAGE_SIZE; + /* Should never happen but for bugs in other kernel subsystems */ + if (!page_has_buffers(page)) { + ext4_warning_inode(inode, + "page %lu does not have buffers attached", page->index); + ClearPageDirty(page); + unlock_page(page); + return 0; + } + page_bufs = page_buffers(page); /* * We cannot do block allocation or other extent handling in this @@ -2697,6 +2706,22 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) wait_on_page_writeback(page); BUG_ON(PageWriteback(page)); + /* + * Should never happen but for buggy code in + * other subsystems that call + * set_page_dirty() without properly warning + * the file system first. See [1] for more + * information. + * + * [1] https://lore.kernel.org/linux-mm/20180103100430.GE4911@quack2.suse.cz + */ + if (!page_has_buffers(page)) { + ext4_warning_inode(mpd->inode, "page %lu does not have buffers attached", page->index); + ClearPageDirty(page); + unlock_page(page); + continue; + } + if (mpd->map.m_len == 0) mpd->first_page = page->index; mpd->next_page = page->index + 1; -- 2.34.1