Skip to contentSkip to conversation

xfs: Fix error pointer dereference

PATCH Superseded Ethan Tidmore 3 participants 3 messages Feb 19 – Feb 20

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xfs: Fix error pointer dereference

The function try_lookup_noperm() can return an error pointer and is not checked for one.

Add checks for error pointer in xrep_adoption_check_dcache() and xrep_adoption_zap_dcache().

Detected by Smatch:
fs/xfs/scrub/orphanage.c:449 xrep_adoption_check_dcache() error:
'd_child' dereferencing possible ERR_PTR()

fs/xfs/scrub/orphanage.c:485 xrep_adoption_zap_dcache() error:
'd_child' dereferencing possible ERR_PTR()

Fixes 73597e3e42b4 ("xfs: ensure dentry consistency when the orphanage adopts a file")
Cc <[email protected]> # v6.16

---
v3:
- Add dput(d_orphanage) before returning error code in xrep_adoption_check_dcache().
- Revert xrep_adoption_zap_dcache() change back to v1 version.
- Include function names where error pointer checks were added. v2:
- Propagate the error back in xrep_adoption_check_dcache().
- Add Cc to stable.
- Add correct Fixes tag.

 fs/xfs/scrub/orphanage.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/xfs/scrub/orphanage.c +5 -1
index 52a108f6d5f4..682af1bcf131 100644
@@ -442,6 +442,10 @@ xrep_adoption_check_dcache(
 		return 0;
 
 	d_child = try_lookup_noperm(&qname, d_orphanage);
+	if (IS_ERR(d_child)) {
+		dput(d_orphanage);
+		return PTR_ERR(d_child);
+	}
 	if (d_child) {
 		trace_xrep_adoption_check_child(sc->mp, d_child);
 
@@ -479,7 +483,7 @@ xrep_adoption_zap_dcache(
 		return;
 
 	d_child = try_lookup_noperm(&qname, d_orphanage);
-	while (d_child != NULL) {
+	while (!IS_ERR_OR_NULL(d_child)) {
 		trace_xrep_adoption_invalidate_child(sc->mp, d_child);
 
 		ASSERT(d_is_negative(d_child));
Signature · 1 line
2.53.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 35 lines · Ethan Tidmore

The function try_lookup_noperm() can return an error pointer and is not checked for one.

Add checks for error pointer in xrep_adoption_check_dcache() and xrep_adoption_zap_dcache().

Detected by Smatch:
fs/xfs/scrub/orphanage.c:449 xrep_adoption_check_dcache() error:
'd_child' dereferencing possible ERR_PTR()

fs/xfs/scrub/orphanage.c:485 xrep_adoption_zap_dcache() error:
'd_child' dereferencing possible ERR_PTR()

Fixes 73597e3e42b4 ("xfs: ensure dentry consistency when the orphanage adopts a file")
Cc <[email protected]> # v6.16

---
v3:
- Add dput(d_orphanage) before returning error code in xrep_adoption_check_dcache().
- Revert xrep_adoption_zap_dcache() change back to v1 version.
- Include function names where error pointer checks were added. v2:
- Propagate the error back in xrep_adoption_check_dcache().
- Add Cc to stable.
- Add correct Fixes tag.

 fs/xfs/scrub/orphanage.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/xfs/scrub/orphanage.c +0 -0
index 52a108f6d5f4..682af1bcf131 100644

fs/xfs/scrub/orphanage.c xrep_adoption_check_dcache( · line 448

Quoted 7 lines
fs/xfs/scrub/orphanage.c +4 -0
@@ -442,6 +442,10 @@ xrep_adoption_check_dcache(
 		return 0;
 
 	d_child = try_lookup_noperm(&qname, d_orphanage);
+	if (IS_ERR(d_child)) {
+		dput(d_orphanage);
+		return PTR_ERR(d_child);
+	}

Nit: blank link after the closing brace.

Other than me nitpicking this looks ok to me so

Thanks for fixing this!

--D

Quoted 15 lines
fs/xfs/scrub/orphanage.c +1 -1
 	if (d_child) {
 		trace_xrep_adoption_check_child(sc->mp, d_child);
 
@@ -479,7 +483,7 @@ xrep_adoption_zap_dcache(
 		return;
 
 	d_child = try_lookup_noperm(&qname, d_orphanage);
-	while (d_child != NULL) {
+	while (!IS_ERR_OR_NULL(d_child)) {
 		trace_xrep_adoption_invalidate_child(sc->mp, d_child);
 
 		ASSERT(d_is_negative(d_child));
Signature · 1 line
2.53.0
Reviewed-by on v3 1/1
#2 lore raw
In reply to Ethan Tidmore
Quoted 46 lines · Ethan Tidmore

The function try_lookup_noperm() can return an error pointer and is not checked for one.

Add checks for error pointer in xrep_adoption_check_dcache() and xrep_adoption_zap_dcache().

Detected by Smatch:
fs/xfs/scrub/orphanage.c:449 xrep_adoption_check_dcache() error:
'd_child' dereferencing possible ERR_PTR()

fs/xfs/scrub/orphanage.c:485 xrep_adoption_zap_dcache() error:
'd_child' dereferencing possible ERR_PTR()

Fixes 73597e3e42b4 ("xfs: ensure dentry consistency when the orphanage adopts a file")
Cc <[email protected]> # v6.16

---
v3:
- Add dput(d_orphanage) before returning error code in xrep_adoption_check_dcache().
- Revert xrep_adoption_zap_dcache() change back to v1 version.
- Include function names where error pointer checks were added. v2:
- Propagate the error back in xrep_adoption_check_dcache().
- Add Cc to stable.
- Add correct Fixes tag.

 fs/xfs/scrub/orphanage.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/xfs/scrub/orphanage.c +4 -0
index 52a108f6d5f4..682af1bcf131 100644
@@ -442,6 +442,10 @@ xrep_adoption_check_dcache(
 		return 0;
 
 	d_child = try_lookup_noperm(&qname, d_orphanage);
+	if (IS_ERR(d_child)) {
+		dput(d_orphanage);
+		return PTR_ERR(d_child);
+	}
 	if (d_child) {
 		trace_xrep_adoption_check_child(sc->mp, d_child);
 

fs/xfs/scrub/orphanage.c xrep_adoption_zap_dcache( · line 489

Quoted 8 lines
fs/xfs/scrub/orphanage.c +1 -1
@@ -479,7 +483,7 @@ xrep_adoption_zap_dcache(
 		return;
 
 	d_child = try_lookup_noperm(&qname, d_orphanage);
-	while (d_child != NULL) {
+	while (!IS_ERR_OR_NULL(d_child)) {
 		trace_xrep_adoption_invalidate_child(sc->mp, d_child);
 
 		ASSERT(d_is_negative(d_child));

Based on my reviews in the previous version[1], this looks good to me.

[1] https://lore.kernel.org/all/[email protected]/