From nobody Fri Nov 29 12:43:27 2024 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C4B919C54B for ; Thu, 19 Sep 2024 09:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726738774; cv=none; b=WEbEOvrC9xvF1EK0DtpOyPuPhT7vvxPdLizKmD/NXWTe2zRbjqGBHM/+69it1XA5vAYSH8XKI3sQ/dvQlQPlxVI7WdmRLvOJvetjs7BNedXYoSSN0onYMpWf/XmmkdLD7ydthm+HCqiPMUwapPwP7NDZ+hEYgOuF47xkZBd+d8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726738774; c=relaxed/simple; bh=7KWMRCfLshJan+v1YjbxtnHR81BOQimjwuapGh0YCt8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YCNWVker3B1Sjb6Cc3L8dEhieBx8lv9zXMEedrPUVTvEjBA6IdrwxocyTCXf1+w3V45GTQIzNSSdPVpq50MgxsM1CkAL/oiPUOyjf3PCD6jyWaC5kAgN+Py6WZBhYhJwWgxeQBaqCcng1gTQ+bmX4SfVh46L59spHihB4JmRIYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ntKKPYh8; arc=none smtp.client-ip=91.218.175.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ntKKPYh8" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1726738747; 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=0el6xdbuEtFnFMlbAu4zA1Zhc8E2Sw9sLTTq195ArnA=; b=ntKKPYh8Dfp6S1p7ekwz33ZuRQL9q9BgcfGUcv0OAIk1JWOe/qVKX0yDBENkQ5dBLUT/rp bKA7cwCnJ5UfenP2hOmca2/i8PfvzocksSESFVmI2/iyRAi85dHff/gXBZQQXQFINSd6+x uq42KEJjtvC8loCvlt6DUOKiztt6ixc= From: "Luis Henriques (SUSE)" To: Theodore Ts'o , Andreas Dilger , Jan Kara , Harshad Shirwadkar Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, "Luis Henriques (SUSE)" Subject: [PATCH 1/2] ext4: use handle to mark fc as ineligible in __track_dentry_update() Date: Thu, 19 Sep 2024 10:38:47 +0100 Message-ID: <20240919093848.2330-2-luis.henriques@linux.dev> In-Reply-To: <20240919093848.2330-1-luis.henriques@linux.dev> References: <20240919093848.2330-1-luis.henriques@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Calling ext4_fc_mark_ineligible() with a NULL handle is racy and may result in a fast-commit being done before the filesystem is effectively marked as ineligible. This patch fixes the calls to this function in __track_dentry_update() by adding an extra parameter to the callback used in ext4_fc_track_template(). Suggested-by: Jan Kara Signed-off-by: Luis Henriques (SUSE) Reviewed-by: Jan Kara --- fs/ext4/fast_commit.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 3926a05eceee..c330efd771d1 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -372,7 +372,7 @@ void ext4_fc_mark_ineligible(struct super_block *sb, in= t reason, handle_t *handl */ static int ext4_fc_track_template( handle_t *handle, struct inode *inode, - int (*__fc_track_fn)(struct inode *, void *, bool), + int (*__fc_track_fn)(handle_t *handle, struct inode *, void *, bool), void *args, int enqueue) { bool update =3D false; @@ -389,7 +389,7 @@ static int ext4_fc_track_template( ext4_fc_reset_inode(inode); ei->i_sync_tid =3D tid; } - ret =3D __fc_track_fn(inode, args, update); + ret =3D __fc_track_fn(handle, inode, args, update); mutex_unlock(&ei->i_fc_lock); =20 if (!enqueue) @@ -413,7 +413,8 @@ struct __track_dentry_update_args { }; =20 /* __track_fn for directory entry updates. Called with ei->i_fc_lock. */ -static int __track_dentry_update(struct inode *inode, void *arg, bool upda= te) +static int __track_dentry_update(handle_t *handle, struct inode *inode, + void *arg, bool update) { struct ext4_fc_dentry_update *node; struct ext4_inode_info *ei =3D EXT4_I(inode); @@ -428,14 +429,14 @@ static int __track_dentry_update(struct inode *inode,= void *arg, bool update) =20 if (IS_ENCRYPTED(dir)) { ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_ENCRYPTED_FILENAME, - NULL); + handle); mutex_lock(&ei->i_fc_lock); return -EOPNOTSUPP; } =20 node =3D kmem_cache_alloc(ext4_fc_dentry_cachep, GFP_NOFS); if (!node) { - ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL); + ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle); mutex_lock(&ei->i_fc_lock); return -ENOMEM; } @@ -447,7 +448,7 @@ static int __track_dentry_update(struct inode *inode, v= oid *arg, bool update) node->fcd_name.name =3D kmalloc(dentry->d_name.len, GFP_NOFS); if (!node->fcd_name.name) { kmem_cache_free(ext4_fc_dentry_cachep, node); - ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL); + ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle); mutex_lock(&ei->i_fc_lock); return -ENOMEM; } @@ -569,7 +570,8 @@ void ext4_fc_track_create(handle_t *handle, struct dent= ry *dentry) } =20 /* __track_fn for inode tracking */ -static int __track_inode(struct inode *inode, void *arg, bool update) +static int __track_inode(handle_t *handle, struct inode *inode, void *arg, + bool update) { if (update) return -EEXIST; @@ -607,7 +609,8 @@ struct __track_range_args { }; =20 /* __track_fn for tracking data updates */ -static int __track_range(struct inode *inode, void *arg, bool update) +static int __track_range(handle_t *handle, struct inode *inode, void *arg, + bool update) { struct ext4_inode_info *ei =3D EXT4_I(inode); ext4_lblk_t oldstart; From nobody Fri Nov 29 12:43:27 2024 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2307E19ABAF for ; Thu, 19 Sep 2024 09:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726738790; cv=none; b=qlnBah6Rp4GFgeD2A+IsBSETqrnkm0s2runDxxrpqj23FNd/eUL3wK16viRofajZhgryeM49J9CjajW4CQtlv7T+YzQC/1zG6t97T3Z1TN3+bQqfeB5xk8AMb/VauC2bioJ7vHkQMXllAYigCpebcNxt5vWRs/0whVBm6p55qfA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726738790; c=relaxed/simple; bh=quLF4r0BPg/Lg56Pq4mAL3T/2KzHzxOAJO26kJYaM1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iC+cfKFt3Xt2SBswcIgtFsj8V4hSGmf5APSGbjkTrWYSddBikKp/GeTKj8nNvXvfo4hePd2DaCDJq+J35ZgJsgDHUTYd66b8EfadU+p8BjCWRTO0+9BBDc6EonvK0NhbxsniV2Q6Il0ENtppqhQH8iXweqMV4DXD9Eargiv63MQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=v0KQpTRn; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="v0KQpTRn" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1726738762; 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=kgS97rYBis0paBZDtTgvMBnKTKUqe4gMl/tKEtgKQec=; b=v0KQpTRn2bRSXJivoqD9JMO2Q9lUFHzTQyCzC5w+u87Jh2qV5aM3Esc6c5/9GoPGdEt4cg LlYjyQ1IAm8iYoN6rl+cYuCgvJeomPWZk4J5uUx2aCoXo4RhEAQsoaMj/sR/1Ws/mFWUW6 +18yvQZYF2vb47Q7yhNBARS7WN8chLk= From: "Luis Henriques (SUSE)" To: Theodore Ts'o , Andreas Dilger , Jan Kara , Harshad Shirwadkar Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, "Luis Henriques (SUSE)" Subject: [PATCH 2/2] ext4: mark fc as ineligible using an handle in ext4_xattr_set() Date: Thu, 19 Sep 2024 10:38:48 +0100 Message-ID: <20240919093848.2330-3-luis.henriques@linux.dev> In-Reply-To: <20240919093848.2330-1-luis.henriques@linux.dev> References: <20240919093848.2330-1-luis.henriques@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Calling ext4_fc_mark_ineligible() with a NULL handle is racy and may result in a fast-commit being done before the filesystem is effectively marked as ineligible. This patch reduces the risk of this happening in function ext4_xattr_set() by using an handle if one is available. Suggested-by: Jan Kara Signed-off-by: Luis Henriques (SUSE) --- fs/ext4/xattr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 46ce2f21fef9..dbe4d11cd332 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -2554,11 +2554,15 @@ ext4_xattr_set(struct inode *inode, int name_index,= const char *name, handle =3D ext4_journal_start(inode, EXT4_HT_XATTR, credits); if (IS_ERR(handle)) { error =3D PTR_ERR(handle); + ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_XATTR, + NULL); } else { int error2; =20 error =3D ext4_xattr_set_handle(handle, inode, name_index, name, value, value_len, flags); + ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_XATTR, + handle); error2 =3D ext4_journal_stop(handle); if (error =3D=3D -ENOSPC && ext4_should_retry_alloc(sb, &retries)) @@ -2566,7 +2570,6 @@ ext4_xattr_set(struct inode *inode, int name_index, c= onst char *name, if (error =3D=3D 0) error =3D error2; } - ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_XATTR, NULL); =20 return error; }