From patchwork Mon Jul 29 16:19:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13745286 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30CECC3DA61 for ; Mon, 29 Jul 2024 16:20:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB7186B0095; Mon, 29 Jul 2024 12:20:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF04D6B0096; Mon, 29 Jul 2024 12:20:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 943B96B0098; Mon, 29 Jul 2024 12:20:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 75B216B0095 for ; Mon, 29 Jul 2024 12:20:42 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C857CA0368 for ; Mon, 29 Jul 2024 16:20:41 +0000 (UTC) X-FDA: 82393303482.09.EED4D72 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 182E6180018 for ; Mon, 29 Jul 2024 16:20:39 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=apOhyN5w; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722270036; a=rsa-sha256; cv=none; b=iYULvI6p5f2AzHs5wayHqCCUUtmB3vmZqGx1g6uOrB3NuCA/Bo9JGFcKiio43pAvcVMc4i K3iPXw5y+A+MYG5X3/xZv9KNckPuH2acsnAl1GlKQ9vAqjCNrmfAIt+9NIdENma0gt0D1u Kz5jV+yd6IPdcj74seHVCNATMuhNTwM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=apOhyN5w; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722270036; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wvz9YBrTPFQ9wVYP2d1umk84aV9uv83ek2O7Ma2LSP4=; b=nQA4J8XaWpe/cNYfal4EyufI1b6JdLfWyH9FWTHJbN0RCObOG7KkMUe8ugVw6sqZGBsyGR xjBMsjqLC9X35wjSQpw7fO1Q7tZsnAxhG+MokOkGr91doE4TvMf4Fs8EXMuoHnUY3iFn78 tet87bRzUxrNgqIRa/B/Qcjm41C7eI8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722270039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wvz9YBrTPFQ9wVYP2d1umk84aV9uv83ek2O7Ma2LSP4=; b=apOhyN5wOUocUWIDRw+HtKXDR27ljo92oDGeA7vMr+ChP8CIU5l+Sr6Bmtrk9yxGjVvfdk UyNqc2PfR03+kqwnxHNYaNkmR6haOHL/RE8Ohm7xusReQbL+OXDZSMNaFf2Q+12Mq/Rb/r YxcCu+pCyrlEVJ7gBn0WXbKUCNymE0w= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-57-U7bPQnvjMCGinNQMEYrDUw-1; Mon, 29 Jul 2024 12:20:35 -0400 X-MC-Unique: U7bPQnvjMCGinNQMEYrDUw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 64EFB1955D4B; Mon, 29 Jul 2024 16:20:30 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.216]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B49B03000193; Mon, 29 Jul 2024 16:20:23 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French , Matthew Wilcox Cc: David Howells , Jeff Layton , Gao Xiang , Dominique Martinet , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Christian Brauner , Gao Xiang Subject: [PATCH 02/24] cachefiles: Fix non-taking of sb_writers around set/removexattr Date: Mon, 29 Jul 2024 17:19:31 +0100 Message-ID: <20240729162002.3436763-3-dhowells@redhat.com> In-Reply-To: <20240729162002.3436763-1-dhowells@redhat.com> References: <20240729162002.3436763-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspam-User: X-Rspamd-Queue-Id: 182E6180018 X-Rspamd-Server: rspam01 X-Stat-Signature: bkbk4qqzs4r986xu7k5didx6u9y6o6ty X-HE-Tag: 1722270039-691707 X-HE-Meta: U2FsdGVkX18uMxWc+TGBBFYLfo9SZQiUhK5ymgTFV4vIPkF4H0E5uBBk6Om4CxBGtqtLcK3AEC9/YCbtlbvE0KpIFsQmo34azH+ceI6hSe0oB3TnQhEXrRsqgx6SXt7E+XW913s9cAnD4w8KOt1ckLm7/uX6MpZTORSzmpe9ZWbW5xrUZzJfVzPcKX2Y3dgJlBdVD3mYGfMxOBP5jsLkxbzCLqBmTAMWq+w6T56hW5i1DwQdwJxtjSxZ4vb9EpmxTtFWWoVUUHI1TaIU8v3DInTvcOAYqmPVhPDAAziOvcJUP89GvrFvIqhtaee/yQ+JhKBgv5Y+xum7eBZIXFuKXcU/6JDngMFgeddkIvxzF/T1byjCZpmqKIYV40sV4DBPIRJm/N9P4pBsxXOrfXvYWSd0AA7Hvo8wWuBlctxYwlpWgBx9h6kMph4a9UbYdKitOnZVNF2CLV0Z5X+NkgurHRKT5CoemBLPiJLNqqj4HEysx/UqxyLWv5MiaU311X0s5YmKB7mr+LOml0iZe8nIBTBbN1vUTHWIOtAcgEc+1rud8RahDk28HeY2Q5u88aaLVJdO8w7hKHV2lNP7VFjiliGDI8NW37y44Rb4wLCxot8CdaH7msnPHicnxzzn1FMuvlwFV5rQjh+cZzXS0vTcHocceWItGOjBC3rd8MVeQdlbdTNG/2Uezbj1lsdlYofUNdmLcTnVDyR0JyAIBF+1HDtyl3k2DCCfH3EhU7AyqzcQ1XI83j9rv4WS9aUpPFlI0LE3xOAsxT7Ljy3oSk+nfG4ezj64xsVHNAAs/MvmFCm0UV6PYcT0rIOxqp1R475lmZrtdEiGFDdouECoIbb3i2VDqh2LMqPviyZancw1Gizn9BeMhG7Okx33lcg/8YBLu7jwMvGqyOSm9bILivEhRprI7CG8g9bFPSzu5Morme0tgxVa1s5IFmP6kg+ePYsj9U9Gb8GlIHZw9JFADkY 3h0hknsN +NEjzfPaq6bzIG7glv5X2AODr4K4r6U2pPk0agBSb1A21iUhCFAj1QzZzFt02cCKn1j2I0tJx7eve0R8ZuQLRhSGU3AYCopHRIYzMNREcQD7uRoSxzrCON0XfmOgUkmplb7xZB6vnZXHFbN/w69rwk0rab3XnYQTzr7amsZeVpKqi6vBoizEfUT4lgrcp8jMtV+nSx4C2ZydZMFiU+pB4MQhAPDYfwnbRm/mu96N/2KNo00nCZVn2FCnHMhpQrxYEvXX+Src34BHCJMhIAZTLqUc6T2wBkmjEeuYURkogFtln8aqRqpMkMGtgyL17vL+ejnWkXK/ZI/7D/A1bF0AAZbJmoP/AR5fs9r7h7b+UTHnzQBprO8YTKA9TXnn8dam0UzoE2dJg2BlrhnzZk2K6xKzVFFMbqQq/Ss0k24gMs32IUHVIkv8FXXvKwgcPGiioe86uICjeRxbnuITRzID8skz4GQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Unlike other vfs_xxxx() calls, vfs_setxattr() and vfs_removexattr() don't take the sb_writers lock, so the caller should do it for them. Fix cachefiles to do this. Fixes: 9ae326a69004 ("CacheFiles: A cache that backs onto a mounted filesystem") Signed-off-by: David Howells cc: Christian Brauner cc: Gao Xiang cc: netfs@lists.linux.dev cc: linux-erofs@lists.ozlabs.org cc: linux-fsdevel@vger.kernel.org --- fs/cachefiles/xattr.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c index 4dd8a993c60a..7c6f260a3be5 100644 --- a/fs/cachefiles/xattr.c +++ b/fs/cachefiles/xattr.c @@ -64,9 +64,15 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object) memcpy(buf->data, fscache_get_aux(object->cookie), len); ret = cachefiles_inject_write_error(); - if (ret == 0) - ret = vfs_setxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache, - buf, sizeof(struct cachefiles_xattr) + len, 0); + if (ret == 0) { + ret = mnt_want_write_file(file); + if (ret == 0) { + ret = vfs_setxattr(&nop_mnt_idmap, dentry, + cachefiles_xattr_cache, buf, + sizeof(struct cachefiles_xattr) + len, 0); + mnt_drop_write_file(file); + } + } if (ret < 0) { trace_cachefiles_vfs_error(object, file_inode(file), ret, cachefiles_trace_setxattr_error); @@ -151,8 +157,14 @@ int cachefiles_remove_object_xattr(struct cachefiles_cache *cache, int ret; ret = cachefiles_inject_remove_error(); - if (ret == 0) - ret = vfs_removexattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache); + if (ret == 0) { + ret = mnt_want_write(cache->mnt); + if (ret == 0) { + ret = vfs_removexattr(&nop_mnt_idmap, dentry, + cachefiles_xattr_cache); + mnt_drop_write(cache->mnt); + } + } if (ret < 0) { trace_cachefiles_vfs_error(object, d_inode(dentry), ret, cachefiles_trace_remxattr_error); @@ -208,9 +220,15 @@ bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume) memcpy(buf->data, p, volume->vcookie->coherency_len); ret = cachefiles_inject_write_error(); - if (ret == 0) - ret = vfs_setxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache, - buf, len, 0); + if (ret == 0) { + ret = mnt_want_write(volume->cache->mnt); + if (ret == 0) { + ret = vfs_setxattr(&nop_mnt_idmap, dentry, + cachefiles_xattr_cache, + buf, len, 0); + mnt_drop_write(volume->cache->mnt); + } + } if (ret < 0) { trace_cachefiles_vfs_error(NULL, d_inode(dentry), ret, cachefiles_trace_setxattr_error);