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=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 35696C433EF for ; Mon, 20 Sep 2021 16:55:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A82961391 for ; Mon, 20 Sep 2021 16:55:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244437AbhITQ5F (ORCPT ); Mon, 20 Sep 2021 12:57:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:44384 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244458AbhITQxw (ORCPT ); Mon, 20 Sep 2021 12:53:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 395A26137C; Mon, 20 Sep 2021 16:50:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156619; bh=4NzNkLn05QZJcL5Yb64RzliCzb+IlNgrs2fsUuwb0aM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v8Kxpx5ibj25kFur7j8I8qhzWbNlNx5TSvUSDX/j4q2YISUusxMrRB1E5QWdnfKkz 05rtQWTSeaCQh5n2vrlGSzCd+dKhXWCHR/0491Y8cKjYXRXsjRYGdTt4MvQXWo34t6 4ZwPR/QCG4ywE/VpI6AmS9Q33HoPN/1fsyPhK3Bw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, syzbot+13146364637c7363a7de@syzkaller.appspotmail.com, Theodore Tso Subject: [PATCH 4.9 001/175] ext4: fix race writing to an inline_data file while its xattrs are changing Date: Mon, 20 Sep 2021 18:40:50 +0200 Message-Id: <20210920163918.118625761@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163918.068823680@linuxfoundation.org> References: <20210920163918.068823680@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Theodore Ts'o commit a54c4613dac1500b40e4ab55199f7c51f028e848 upstream. The location of the system.data extended attribute can change whenever xattr_sem is not taken. So we need to recalculate the i_inline_off field since it mgiht have changed between ext4_write_begin() and ext4_write_end(). This means that caching i_inline_off is probably not helpful, so in the long run we should probably get rid of it and shrink the in-memory ext4 inode slightly, but let's fix the race the simple way for now. Cc: stable@kernel.org Fixes: f19d5870cbf72 ("ext4: add normal write support for inline data") Reported-by: syzbot+13146364637c7363a7de@syzkaller.appspotmail.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inline.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -747,6 +747,12 @@ int ext4_write_inline_data_end(struct in ext4_write_lock_xattr(inode, &no_expand); BUG_ON(!ext4_has_inline_data(inode)); + /* + * ei->i_inline_off may have changed since ext4_write_begin() + * called ext4_try_to_write_inline_data() + */ + (void) ext4_find_inline_data_nolock(inode); + kaddr = kmap_atomic(page); ext4_write_inline_data(inode, &iloc, kaddr, pos, len); kunmap_atomic(kaddr);