Skip to contentSkip to conversation

xfs: don't irele after failing to iget in xfs_attri_recover_work

PATCH Applied Darrick J. Wong 3 participants 14 messages Mar 23 – Mar 26 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 xfs: don't irele after failing to iget in xfs_attri_recover_work

From: Darrick J. Wong <[email protected]>

xlog_recovery_iget* never set @ip to a valid pointer if they return zero, so this irele will walk off a dangling pointer. Fix that.

Cc <[email protected]> # v6.10
Fixes ae673f534a3097 ("xfs: record inode generation in xattr update log intent items")
---
 fs/xfs/xfs_attr_item.c |    1 -
 1 file changed, 1 deletion(-)
fs/xfs/xfs_attr_item.c +0 -1
index 354472bf45f145..fe909bc44c3a79 100644
@@ -653,7 +653,6 @@ xfs_attri_recover_work(
 		break;
 	}
 	if (error) {
-		xfs_irele(ip);
 		XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, attrp,
 				sizeof(*attrp));
 		return ERR_PTR(-EFSCORRUPTED);
#1 lore raw

PATCH 2/3 xfs: don't expose stale pointers to callers of xlog_recover_iget

From: Darrick J. Wong <[email protected]>

Fix this function to avoid exposing a stale pointer to the caller when returning an error code after dqattach fails.

Cc <[email protected]> # v5.15
Fixes 4bc619833f738f ("xfs: refactor xfs_iget calls from log intent recovery")
---
 fs/xfs/xfs_log_recover.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
fs/xfs/xfs_log_recover.c +7 -5
index 09e6678ca4878e..0e91a62348eb79 100644
@@ -1745,21 +1745,23 @@ xlog_recover_iget(
 	xfs_ino_t		ino,
 	struct xfs_inode	**ipp)
 {
+	struct xfs_inode	*ip;
 	int			error;
 
-	error = xfs_iget(mp, NULL, ino, 0, 0, ipp);
+	error = xfs_iget(mp, NULL, ino, 0, 0, &ip);
 	if (error)
 		return error;
 
-	error = xfs_qm_dqattach(*ipp);
+	error = xfs_qm_dqattach(ip);
 	if (error) {
-		xfs_irele(*ipp);
+		xfs_irele(ip);
 		return error;
 	}
 
-	if (VFS_I(*ipp)->i_nlink == 0)
-		xfs_iflags_set(*ipp, XFS_IRECOVERY);
+	if (VFS_I(ip)->i_nlink == 0)
+		xfs_iflags_set(ip, XFS_IRECOVERY);
 
+	*ipp = ip;
 	return 0;
 }
 
#2 lore raw

Re: [PATCH 2/3] xfs: don't expose stale pointers to callers of xlog_recover_iget

Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix this function to avoid exposing a stale pointer to the caller when returning an error code after dqattach fails.

I still think this is silly.

Quoted 2 lines
Cc <[email protected]> # v5.15
Fixes 4bc619833f738f ("xfs: refactor xfs_iget calls from log intent recovery")

.. and certainly does not actually fix anything.

#3 lore raw

Re: [PATCH 2/3] xfs: don't expose stale pointers to callers of xlog_recover_iget

Quoted 6 lines · Christoph Hellwig
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix this function to avoid exposing a stale pointer to the caller when returning an error code after dqattach fails.

Quoted 6 lines

I still think this is silly.

Quoted 2 lines
Cc <[email protected]> # v5.15
Fixes 4bc619833f738f ("xfs: refactor xfs_iget calls from log intent recovery")

.. and certainly does not actually fix anything.

<nod> I'll let cem decide if he wants to trade more stack usage for removing theoretical bugs via this patch, then.

--D

#4 lore raw

Re: [PATCH 2/3] xfs: don't expose stale pointers to callers of xlog_recover_iget

Quoted 9 lines · Darrick J. Wong
Quoted 6 lines

I still think this is silly.

Quoted 2 lines
Cc <[email protected]> # v5.15
Fixes 4bc619833f738f ("xfs: refactor xfs_iget calls from log intent recovery")

.. and certainly does not actually fix anything.

<nod> I'll let cem decide if he wants to trade more stack usage for removing theoretical bugs via this patch, then.

I don't think it even removes a theoretical bug. It papers over callers not understanding the calling convention assuming they also have a NULL check which they'd otherwise don't need. That's the kind of cargo cult programming that makes it really hard to reason about the rules.

maintainer
#5 lore raw

Re: [PATCH 2/3] xfs: don't expose stale pointers to callers of xlog_recover_iget

In reply to Darrick J. Wong
Quoted 10 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix this function to avoid exposing a stale pointer to the caller when returning an error code after dqattach fails.

Cc <[email protected]> # v5.15
Fixes 4bc619833f738f ("xfs: refactor xfs_iget calls from log intent recovery")

---

Hi.

Quoted 24 lines
 fs/xfs/xfs_log_recover.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
fs/xfs/xfs_log_recover.c +4 -3
index 09e6678ca4878e..0e91a62348eb79 100644
@@ -1745,21 +1745,23 @@ xlog_recover_iget(
 	xfs_ino_t		ino,
 	struct xfs_inode	**ipp)
 {
+	struct xfs_inode	*ip;
 	int			error;
 
-	error = xfs_iget(mp, NULL, ino, 0, 0, ipp);
+	error = xfs_iget(mp, NULL, ino, 0, 0, &ip);
 	if (error)
 		return error;
 
-	error = xfs_qm_dqattach(*ipp);
+	error = xfs_qm_dqattach(ip);
 	if (error) {
-		xfs_irele(*ipp);
+		xfs_irele(ip);

fs/xfs/xfs_log_recover.c xlog_recover_iget( · line 1765

Quoted 10 lines
fs/xfs/xfs_log_recover.c +3 -2
 		return error;
 	}
 
-	if (VFS_I(*ipp)->i_nlink == 0)
-		xfs_iflags_set(*ipp, XFS_IRECOVERY);
+	if (VFS_I(ip)->i_nlink == 0)
+		xfs_iflags_set(ip, XFS_IRECOVERY);
 
+	*ipp = ip;
 	return 0;

Honestly I tend to agree with Christoph here. I don't really understand what bug, real or theoretical, this is trying to fix, other than somebody not aborting whatever operation is being done if an error is returned.

I don't see any issue with an extra inode pointer being passed on the stack here, but I don't see any benefit for this either.

Did you fall into this somehow? Have you seen this into the wild? I'll pull the other patches meanwhile, but I think this one deserves more discussion.

#6 lore raw

Re: [PATCH 2/3] xfs: don't expose stale pointers to callers of xlog_recover_iget

Quoted 55 lines · Carlos Maiolino
Quoted 10 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Fix this function to avoid exposing a stale pointer to the caller when returning an error code after dqattach fails.

Cc <[email protected]> # v5.15
Fixes 4bc619833f738f ("xfs: refactor xfs_iget calls from log intent recovery")

---

Hi.

Quoted 24 lines
 fs/xfs/xfs_log_recover.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
fs/xfs/xfs_log_recover.c +4 -3
index 09e6678ca4878e..0e91a62348eb79 100644
@@ -1745,21 +1745,23 @@ xlog_recover_iget(
 	xfs_ino_t		ino,
 	struct xfs_inode	**ipp)
 {
+	struct xfs_inode	*ip;
 	int			error;
 
-	error = xfs_iget(mp, NULL, ino, 0, 0, ipp);
+	error = xfs_iget(mp, NULL, ino, 0, 0, &ip);
 	if (error)
 		return error;
 
-	error = xfs_qm_dqattach(*ipp);
+	error = xfs_qm_dqattach(ip);
 	if (error) {
-		xfs_irele(*ipp);
+		xfs_irele(ip);

fs/xfs/xfs_log_recover.c xlog_recover_iget( · line 1765

Quoted 10 lines
fs/xfs/xfs_log_recover.c +3 -2
 		return error;
 	}
 
-	if (VFS_I(*ipp)->i_nlink == 0)
-		xfs_iflags_set(*ipp, XFS_IRECOVERY);
+	if (VFS_I(ip)->i_nlink == 0)
+		xfs_iflags_set(ip, XFS_IRECOVERY);
 
+	*ipp = ip;
 	return 0;

Honestly I tend to agree with Christoph here. I don't really understand what bug, real or theoretical, this is trying to fix, other than somebody not aborting whatever operation is being done if an error is returned.

Quoted 6 lines

I don't see any issue with an extra inode pointer being passed on the stack here, but I don't see any benefit for this either.

Did you fall into this somehow? Have you seen this into the wild? I'll pull the other patches meanwhile, but I think this one deserves more discussion.

Yeah, look who wrote the function and the bad error handling. You could say that the *author* didn't understand his own function's outparam conventions and wants to prevent himself or anyone else from making further mistakes. ;)

--D

#7 lore raw

PATCH 3/3 xfs: remove file_path tracepoint data

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

The xfile/xmbuf shmem file descriptions are no longer as detailed as they were when online fsck was first merged, because moving to static strings in commit 60382993a2e180 ("xfs: get rid of the xchk_xfile_*_descr calls") removed a memory allocation and hence a source of failure.

However this makes encoding the description in the tracepoints sort of a waste of memory. David Laight also points out that file_path doesn't zero the whole buffer which causes exposure of stale trace bytes, and Steven Rostedt wonders why we're not using a dynamic array for the file path.

I don't think this is worth fixing, so let's just rip it out.

Cc <[email protected]> # v6.11
Fixes 19ebc8f84ea12e ("xfs: fix file_path handling in tracepoints")
---
 fs/xfs/scrub/trace.h |   12 ++----------
 fs/xfs/xfs_trace.h   |   11 ++---------
 2 files changed, 4 insertions(+), 19 deletions(-)
fs/xfs/scrub/trace.h +2 -10
index 39ea651cbb7510..286c5f5e054449 100644
@@ -972,20 +972,12 @@ TRACE_EVENT(xfile_create,
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(unsigned long, ino)
-		__array(char, pathname, MAXNAMELEN)
 	),
 	TP_fast_assign(
-		char		*path;
-
 		__entry->ino = file_inode(xf->file)->i_ino;
-		path = file_path(xf->file, __entry->pathname, MAXNAMELEN);
-		if (IS_ERR(path))
-			strncpy(__entry->pathname, "(unknown)",
-					sizeof(__entry->pathname));
 	),
-	TP_printk("xfino 0x%lx path '%s'",
-		  __entry->ino,
-		  __entry->pathname)
+	TP_printk("xfino 0x%lx",
+		  __entry->ino)
 );
 
 TRACE_EVENT(xfile_destroy,
fs/xfs/xfs_trace.h +2 -9
index 813e5a9f57eb7a..91c4c9422c8739 100644
@@ -5091,23 +5091,16 @@ TRACE_EVENT(xmbuf_create,
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(unsigned long, ino)
-		__array(char, pathname, MAXNAMELEN)
 	),
 	TP_fast_assign(
-		char		*path;
 		struct file	*file = btp->bt_file;
 
 		__entry->dev = btp->bt_mount->m_super->s_dev;
 		__entry->ino = file_inode(file)->i_ino;
-		path = file_path(file, __entry->pathname, MAXNAMELEN);
-		if (IS_ERR(path))
-			strncpy(__entry->pathname, "(unknown)",
-					sizeof(__entry->pathname));
 	),
-	TP_printk("dev %d:%d xmino 0x%lx path '%s'",
+	TP_printk("dev %d:%d xmino 0x%lx",
 		  MAJOR(__entry->dev), MINOR(__entry->dev),
-		  __entry->ino,
-		  __entry->pathname)
+		  __entry->ino)
 );
 
 TRACE_EVENT(xmbuf_free,
maintainer Reviewed-by on v1 3/3
#9 lore raw

Re: [PATCH 3/3] xfs: remove file_path tracepoint data

In reply to Darrick J. Wong
Quoted 14 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

The xfile/xmbuf shmem file descriptions are no longer as detailed as they were when online fsck was first merged, because moving to static strings in commit 60382993a2e180 ("xfs: get rid of the xchk_xfile_*_descr calls") removed a memory allocation and hence a source of failure.

However this makes encoding the description in the tracepoints sort of a waste of memory. David Laight also points out that file_path doesn't zero the whole buffer which causes exposure of stale trace bytes, and Steven Rostedt wonders why we're not using a dynamic array for the file path.

Quoted 8 lines

I don't think this is worth fixing, so let's just rip it out.

Cc <[email protected]> # v6.11
Fixes 19ebc8f84ea12e ("xfs: fix file_path handling in tracepoints")
Quoted 63 lines
---
 fs/xfs/scrub/trace.h |   12 ++----------
 fs/xfs/xfs_trace.h   |   11 ++---------
 2 files changed, 4 insertions(+), 19 deletions(-)
fs/xfs/scrub/trace.h +2 -10
index 39ea651cbb7510..286c5f5e054449 100644
@@ -972,20 +972,12 @@ TRACE_EVENT(xfile_create,
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(unsigned long, ino)
-		__array(char, pathname, MAXNAMELEN)
 	),
 	TP_fast_assign(
-		char		*path;
-
 		__entry->ino = file_inode(xf->file)->i_ino;
-		path = file_path(xf->file, __entry->pathname, MAXNAMELEN);
-		if (IS_ERR(path))
-			strncpy(__entry->pathname, "(unknown)",
-					sizeof(__entry->pathname));
 	),
-	TP_printk("xfino 0x%lx path '%s'",
-		  __entry->ino,
-		  __entry->pathname)
+	TP_printk("xfino 0x%lx",
+		  __entry->ino)
 );
 
 TRACE_EVENT(xfile_destroy,
fs/xfs/xfs_trace.h +2 -9
index 813e5a9f57eb7a..91c4c9422c8739 100644
@@ -5091,23 +5091,16 @@ TRACE_EVENT(xmbuf_create,
 	TP_STRUCT__entry(
 		__field(dev_t, dev)
 		__field(unsigned long, ino)
-		__array(char, pathname, MAXNAMELEN)
 	),
 	TP_fast_assign(
-		char		*path;
 		struct file	*file = btp->bt_file;
 
 		__entry->dev = btp->bt_mount->m_super->s_dev;
 		__entry->ino = file_inode(file)->i_ino;
-		path = file_path(file, __entry->pathname, MAXNAMELEN);
-		if (IS_ERR(path))
-			strncpy(__entry->pathname, "(unknown)",
-					sizeof(__entry->pathname));
 	),
-	TP_printk("dev %d:%d xmino 0x%lx path '%s'",
+	TP_printk("dev %d:%d xmino 0x%lx",
 		  MAJOR(__entry->dev), MINOR(__entry->dev),
-		  __entry->ino,
-		  __entry->pathname)
+		  __entry->ino)
 );
 
 TRACE_EVENT(xmbuf_free,
maintainer
#10 lore raw
In reply to Darrick J. Wong
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

xlog_recovery_iget* never set @ip to a valid pointer if they return zero,

* if they return an error * ?
It will always return zero when setting @ip.

I can update it at commit time if you're ok with it.

Quoted 24 lines

so this irele will walk off a dangling pointer. Fix that.

Cc <[email protected]> # v6.10
Fixes ae673f534a3097 ("xfs: record inode generation in xattr update log intent items")
---
 fs/xfs/xfs_attr_item.c |    1 -
 1 file changed, 1 deletion(-)
fs/xfs/xfs_attr_item.c +0 -1
index 354472bf45f145..fe909bc44c3a79 100644
@@ -653,7 +653,6 @@ xfs_attri_recover_work(
 		break;
 	}
 	if (error) {
-		xfs_irele(ip);
 		XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, attrp,
 				sizeof(*attrp));
 		return ERR_PTR(-EFSCORRUPTED);
#11 lore raw
Quoted 10 lines · Carlos Maiolino
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

xlog_recovery_iget* never set @ip to a valid pointer if they return zero,

* if they return an error * ?
It will always return zero when setting @ip.

I can update it at commit time if you're ok with it.

Er, yes, "...if they return an error" is correct.

--D

Quoted 25 lines
Quoted 24 lines

so this irele will walk off a dangling pointer. Fix that.

Cc <[email protected]> # v6.10
Fixes ae673f534a3097 ("xfs: record inode generation in xattr update log intent items")
---
 fs/xfs/xfs_attr_item.c |    1 -
 1 file changed, 1 deletion(-)
fs/xfs/xfs_attr_item.c +0 -1
index 354472bf45f145..fe909bc44c3a79 100644
@@ -653,7 +653,6 @@ xfs_attri_recover_work(
 		break;
 	}
 	if (error) {
-		xfs_irele(ip);
 		XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, attrp,
 				sizeof(*attrp));
 		return ERR_PTR(-EFSCORRUPTED);
maintainer Reviewed-by on v1 1/3
#12 lore raw
In reply to Darrick J. Wong
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

xlog_recovery_iget* never set @ip to a valid pointer if they return zero, so this irele will walk off a dangling pointer. Fix that.

Oh, yeah, and with that fixed...

Quoted 23 lines
Cc <[email protected]> # v6.10
Fixes ae673f534a3097 ("xfs: record inode generation in xattr update log intent items")
---
 fs/xfs/xfs_attr_item.c |    1 -
 1 file changed, 1 deletion(-)
fs/xfs/xfs_attr_item.c +0 -1
index 354472bf45f145..fe909bc44c3a79 100644
@@ -653,7 +653,6 @@ xfs_attri_recover_work(
 		break;
 	}
 	if (error) {
-		xfs_irele(ip);
 		XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, attrp,
 				sizeof(*attrp));
 		return ERR_PTR(-EFSCORRUPTED);
maintainer Applied
#13 lore raw
In reply to Darrick J. Wong
Quoted 4 lines · Darrick J. Wong

xlog_recovery_iget* never set @ip to a valid pointer if they return zero, so this irele will walk off a dangling pointer. Fix that.

Applied to for-next, thanks!

[1/3] xfs: don't irele after failing to iget in xfs_attri_recover_work

      commit: 70685c291ef82269180758130394ecdc4496b52c
[2/3] xfs: don't expose stale pointers to callers of xlog_recover_iget
      (no commit info)
[3/3] xfs: remove file_path tracepoint data
      commit: e31c53a8060e134111ed095783fee0aa0c43b080

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>