From patchwork Mon Sep 20 19:41:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kelsey Skunberg X-Patchwork-Id: 1530324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=o65mehar; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HCw0f4W3Bz9sX3; Tue, 21 Sep 2021 05:41:22 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mSPAA-0003KU-QP; Mon, 20 Sep 2021 19:41:14 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mSPA9-0003KO-Q7 for kernel-team@lists.ubuntu.com; Mon, 20 Sep 2021 19:41:13 +0000 Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id A6BEC3F048 for ; Mon, 20 Sep 2021 19:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632166873; bh=FMDdRHlRAQdttZ/yGKKNIpUIiAMApyrtsq7y3NnIiZE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o65meharHcWlrS6Bwz4G4+sSswcV2CQq5w9MrKeVYSyI+AAh+R2WQnSjUC0owTnxD nEahu8UJ+v7cU9uZ1pwEht9g8hW+pfTtFhigf8pt9xNBoTG0nMHeAF/s3vPHvvF/MK Py8UsRCjgyJAhymSl6SYFg75Gae4kU/uIARyOrTI1rx5F+2nZESGu17IxgYb80ldbb GauSXvjc4pPtjixtjfvtFuXJvU+VcuACght4Q8BdtI7BDZVBK0yXkM76fFPQEYS+iz VGLBSd++pP9yqy4fPRVg+6yS0RuabKqeUWE3Ubyti6bTgOJBr7B0YH/3CQYE1xnVvu px4jUeYgFKzHg== Received: by mail-oo1-f70.google.com with SMTP id f2-20020a4a2202000000b0028c8a8074deso44741524ooa.20 for ; Mon, 20 Sep 2021 12:41:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FMDdRHlRAQdttZ/yGKKNIpUIiAMApyrtsq7y3NnIiZE=; b=nB4HieXFqZyjpnCzsBsMDvTY+hwEsjh9sfc1KsXh0K/riyYmdFC51OHiXco+IHiTDY 9aUO6RL2ATWlJqiWA2KFcuotAyJYlDNRRytlyx8tUoDCLy9Z6lpa3YEyjyL4eA1JMRjz vapZjc41mFEm9H9QznZJB9GUR0NQuEnaCOTmyzQwDR7Fv4ozfEu4xgLb9KhzafVW85l+ CY6TpzUKARZxAoGVGPXyn8870I1mRoH25soDGMZtzH32wIOdvpWsBS5cp9HbjDJ35jEl fIvIDz7n6OSfx/cxkgUv3AiMK6eI5gIOcrJ8e2NvxQIuguvQlie9uNtBHMMSa632jGV1 CneA== X-Gm-Message-State: AOAM532G5LoEXkitv1gBPtl+7WJkRj3/9mRcAZAvQMn6P/bNndt1Fsfc AF//Ovcd1wXRQ+EJy8n/ZsVt+dUHRl4mxleUk26amHWWwqq3oWXlhmyA0+tHLV9jNf9cdvq3gsu azaX9A2S0PJz6DptyLj0OwDn7B9ronQ770ZpKZ1hrBg== X-Received: by 2002:a4a:c90a:: with SMTP id v10mr2292366ooq.83.1632166872556; Mon, 20 Sep 2021 12:41:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4OIMuIGwS6KMfgDIY3Ch/NpuvmThwBbBpyUmNYrXYAAjliM23CpVotoWvs2Fnok1g6/0Tig== X-Received: by 2002:a4a:c90a:: with SMTP id v10mr2292357ooq.83.1632166872376; Mon, 20 Sep 2021 12:41:12 -0700 (PDT) Received: from localhost.localdomain ([2605:b40:1403:2c00:e5e4:d27d:555a:ac1a]) by smtp.gmail.com with ESMTPSA id h17sm949658ooc.18.2021.09.20.12.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 12:41:12 -0700 (PDT) From: Kelsey Skunberg To: kelsey.skunberg@canonical.com, kernel-team@lists.ubuntu.com Subject: [SRU B/F/H/I/OEM-5.10/HWE-5.8 1/1] ext4: fix race writing to an inline_data file while its xattrs are changing Date: Mon, 20 Sep 2021 13:41:09 -0600 Message-Id: <20210920194109.18976-4-kelsey.skunberg@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210920194109.18976-1-kelsey.skunberg@canonical.com> References: <20210920194109.18976-1-kelsey.skunberg@canonical.com> MIME-Version: 1.0 X-Mailer: git-send-email 2.30.2 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Thadeu Lima de Souza Cascardo From: Theodore Ts'o 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 (cherry picked from commit a54c4613dac1500b40e4ab55199f7c51f028e848) CVE-2021-40490 Signed-off-by: Thadeu Lima de Souza Cascardo --- fs/ext4/inline.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 6c95196a6f80..952c3e1715d4 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -750,6 +750,12 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, 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);