Skip to contentSkip to conversation

xfsprogs: fix potential memory leak in verify_set_primary_sb()

PATCH Superseded Li Zhong 4 participants 16 messages Sep 22, 2013 – Oct 18, 2013

lore
Share & tools
lore

Li Zhong

author
#0 lore raw

PATCH 1/1 xfsprogs: fix potential memory leak in verify_set_primary_sb()

This patch tries to fix CID 997012, 997013 and 997014 reported by Coverity scan, as suggested by sekharan.

---
 repair/sb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
repair/sb.c +4 -2
index aa550e3..7abf47c 100644
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 	/*
 	 * see if we have enough superblocks to bother with
 	 */
-	if (num_ok < num_sbs / 2)
-		return(XR_INSUFF_SEC_SB);
+	if (num_ok < num_sbs / 2) {
+		retval = XR_INSUFF_SEC_SB;
+		goto out_free_list;
+	}
 
 	current = get_best_geo(list);
 
Signature · 8 lines
1.8.1.4



_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 9 lines · Li Zhong

This patch tries to fix CID 997012, 997013 and 997014 reported by Coverity scan, as suggested by sekharan.

---

repair/sb.c +0 -0
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
  	/*

repair/sb.c verify_set_primary_sb(xfs_sb_t *rsb, · line 764

Quoted 10 lines
repair/sb.c +4 -2
  	 * see if we have enough superblocks to bother with
  	 */
-	if (num_ok < num_sbs / 2)
-		return(XR_INSUFF_SEC_SB);
+	if (num_ok < num_sbs / 2) {
+		retval = XR_INSUFF_SEC_SB;
+		goto out_free_list;
+	}
 
 

Looks good. list, sb and check could have been allocated at this point.

Isn't the list been added to before the conditional in the for loop?:

        list = add_geo(list, &geo, sb_index);

        /*
         * grab N secondaries.  check them off as we get them
         * so we only process each one once
         */
        for (round = 0; round < skip; round++)  {

...

                        if (get_sb(sb, off, size, agno) == XR_EOF)  {
                                retval = 1;
                                goto out;
				^^^^^^^^^ out_free_list?
                        }

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#2 lore raw

PATCH v2 1/1 xfsprogs: fix potential memory leak in verify_set_primary_sb()

This patch tries to fix CID 997012, 997013 and 997014 reported by Coverity scan, as suggested by sekharan.

v2: as Mark pointed out, out in the for loop before also needs list to be freed. Also remove out lable as it is not referenced any more.

---
 repair/sb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
repair/sb.c +5 -4
index aa550e3..d34d7a2 100644
@@ -733,7 +733,7 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 			if (get_sb(sb, off, size, agno) == XR_EOF)  {
 				retval = 1;
-				goto out;
+				goto out_free_list;
 			}
 
 			if (verify_sb(sb, 0) == XR_OK)  {
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 	/*
 	 * see if we have enough superblocks to bother with
 	 */
-	if (num_ok < num_sbs / 2)
-		return(XR_INSUFF_SEC_SB);
+	if (num_ok < num_sbs / 2) {
+		retval = XR_INSUFF_SEC_SB;
+		goto out_free_list;
+	}
 
 	current = get_best_geo(list);
 
@@ -841,7 +843,6 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 out_free_list:
 	free_geo(list);
-out:
 	free(sb);
 	free(checked);
 	return(retval);
Signature · 7 lines
1.8.1.4


_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v2 1/1
#3 lore raw
Quoted 8 lines · Li Zhong

This patch tries to fix CID 997012, 997013 and 997014 reported by Coverity scan, as suggested by sekharan.

v2: as Mark pointed out, out in the for loop before also needs list to be freed. Also remove out lable as it is not referenced any more.

---

Thank-you, that looks great.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#4 lore raw
In reply to Li Zhong
Quoted 5 lines · Li Zhong

This patch tries to fix CID 997012, 997013 and 997014 reported by Coverity scan, as suggested by sekharan.

v2: as Mark pointed out, out in the for loop before also needs list to be freed. Also remove out lable as it is not referenced any more.

Fix itself looks good, thanks! Love to see the scan numbers change for the better. ;)

Nitpicks, though: Patch changelogs usually goes below the "---" so the history of trial and error isn't in the commit log. Not that big a deal, it's just convention as mentioned in the kernel SubmittingPatches doc:

Quoted 11 lines

The "---" marker line serves the essential purpose of marking for patch handling tools where the changelog message ends.

One good use for the additional comments after the "---" marker is for a diffstat, to show what files have changed, and the number of inserted and deleted lines per file. A diffstat is especially useful on bigger patches. Other comments relevant only to the moment or the maintainer, not suitable for the permanent changelog, should also go here. A good example of such comments might be "patch changelogs" which describe what has changed between the v1 and v2 version of the patch.

And since we're on the topic of commit messages lately, this one could be improved too I think.

"CID 997012" won't mean anything to a reader in the future. It'd be better to describe what you're fixing on its own terms. Something like:

===
If verify_set_primary_sb() completes the secondary sb scanning loop with too few valid secondaries found (num_ok < num_sbs / 2), it will immediately return without freeing any of the previously allocated memory (variables sb, checked, and any items on the geo list). This was reported by the Coverity scanner as CID 997012, 997013 and 997014.

Fix this by using the out_free_list: goto target for this error case.

Earlier, if get_sb() fails in the secondary scan loop, it goes to
the out: target which does not free any items on the geo list. Fix
this by using the out_free_list: target as well, and remove the now-unused
out: target.
===

On the one hand, the fix isn't that complicated so it probably speaks for itself. But it was complicated enough to warrant discussion & V2 on the list, so probably worth including that detail in the final changelog.

Also, in looking at this, I wonder if there's another minor buglet.

in phase1.c, we turn the return value from verify_set_primary_sb() into an error string via err_string(rval). This handles the various error returns such as XR_INSUFF_SEC_SB, XR_EOF, etc. But in the 2nd case above (get_sb failure), it simply returns "1" which will be interpreted as XR_BAD_MAGIC ("bad magic number").

get_sb() actually returns several XR_* values, so we should probably capture it and use that return value? That'd be a different patch though.

I guess the comment for verify_set_primary_sb() would be changed then too, now it says:

* returns 1 if bad, 0 if ok

but today we actually return 0, 1, or XR_INSUFF_SEC_SB.

Not that big a deal, but it seems like the error returns, their handling, and associated comments aren't quite consistent.

Thanks,
-Eric

Quoted 33 lines
---
 repair/sb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
repair/sb.c +5 -3
index aa550e3..d34d7a2 100644
@@ -733,7 +733,7 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 			if (get_sb(sb, off, size, agno) == XR_EOF)  {
 				retval = 1;
-				goto out;
+				goto out_free_list;
 			}
 
 			if (verify_sb(sb, 0) == XR_OK)  {
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 	/*
 	 * see if we have enough superblocks to bother with
 	 */
-	if (num_ok < num_sbs / 2)
-		return(XR_INSUFF_SEC_SB);
+	if (num_ok < num_sbs / 2) {
+		retval = XR_INSUFF_SEC_SB;
+		goto out_free_list;
+	}
 
 	current = get_best_geo(list);
 

repair/sb.c verify_set_primary_sb(xfs_sb_t *rsb, · line 848

Quoted 7 lines
repair/sb.c +0 -1
@@ -841,7 +843,6 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 out_free_list:
 	free_geo(list);
-out:
 	free(sb);
 	free(checked);
 	return(retval);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#5 lore raw
Quoted 9 lines · Eric Sandeen
Quoted 5 lines · Li Zhong

This patch tries to fix CID 997012, 997013 and 997014 reported by Coverity scan, as suggested by sekharan.

v2: as Mark pointed out, out in the for loop before also needs list to be freed. Also remove out lable as it is not referenced any more.

Fix itself looks good, thanks! Love to see the scan numbers change for the better. ;)

Thank you for all the education below. :)

Quoted 4 lines

Nitpicks, though: Patch changelogs usually goes below the "---" so the history of trial and error isn't in the commit log. Not that big a deal, it's just convention as mentioned in the kernel SubmittingPatches doc:

I think I'll practice it with a 3rd verion.

Quoted 35 lines
Quoted 4 lines

The "---" marker line serves the essential purpose of marking for patch handling tools where the changelog message ends.

Quoted 8 lines

One good use for the additional comments after the "---" marker is for a diffstat, to show what files have changed, and the number of inserted and deleted lines per file. A diffstat is especially useful on bigger patches. Other comments relevant only to the moment or the maintainer, not suitable for the permanent changelog, should also go here. A good example of such comments might be "patch changelogs" which describe what has changed between the v1 and v2 version of the patch.

And since we're on the topic of commit messages lately, this one could be improved too I think.

"CID 997012" won't mean anything to a reader in the future. It'd be better to describe what you're fixing on its own terms. Something like:

===
If verify_set_primary_sb() completes the secondary sb scanning loop with too few valid secondaries found (num_ok < num_sbs / 2), it will immediately return without freeing any of the previously allocated memory (variables sb, checked, and any items on the geo list). This was reported by the Coverity scanner as CID 997012, 997013 and 997014.

Fix this by using the out_free_list: goto target for this error case.

Earlier, if get_sb() fails in the secondary scan loop, it goes to
the out: target which does not free any items on the geo list. Fix
this by using the out_free_list: target as well, and remove the now-unused
out: target.
===

Quoted 3 lines

On the one hand, the fix isn't that complicated so it probably speaks for itself. But it was complicated enough to warrant discussion & V2 on the list, so probably worth including that detail in the final changelog.

OK, I'll use the above as the changelog.

Quoted 16 lines

Also, in looking at this, I wonder if there's another minor buglet.

in phase1.c, we turn the return value from verify_set_primary_sb() into an error string via err_string(rval). This handles the various error returns such as XR_INSUFF_SEC_SB, XR_EOF, etc. But in the 2nd case above (get_sb failure), it simply returns "1" which will be interpreted as XR_BAD_MAGIC ("bad magic number").

get_sb() actually returns several XR_* values, so we should probably capture it and use that return value? That'd be a different patch though.

I guess the comment for verify_set_primary_sb() would be changed then too, now it says:

Quoted 6 lines

* returns 1 if bad, 0 if ok

but today we actually return 0, 1, or XR_INSUFF_SEC_SB.

Not that big a deal, but it seems like the error returns, their handling, and associated comments aren't quite consistent.

I'll try to make another patch for the above issue. Thanks, Zhong

Quoted 38 lines

Thanks,
-Eric

Quoted 33 lines
---
 repair/sb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
repair/sb.c +5 -3
index aa550e3..d34d7a2 100644
@@ -733,7 +733,7 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 			if (get_sb(sb, off, size, agno) == XR_EOF)  {
 				retval = 1;
-				goto out;
+				goto out_free_list;
 			}
 
 			if (verify_sb(sb, 0) == XR_OK)  {
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 	/*
 	 * see if we have enough superblocks to bother with
 	 */
-	if (num_ok < num_sbs / 2)
-		return(XR_INSUFF_SEC_SB);
+	if (num_ok < num_sbs / 2) {
+		retval = XR_INSUFF_SEC_SB;
+		goto out_free_list;
+	}
 
 	current = get_best_geo(list);
 
@@ -841,7 +843,6 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
Quoted 8 lines

repair/sb.c verify_set_primary_sb(xfs_sb_t *rsb, · line 848

Quoted 7 lines
repair/sb.c +0 -1
 out_free_list:
 	free_geo(list);
-out:
 	free(sb);
 	free(checked);
 	return(retval);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#6 lore raw

PATCH v3 1/2 xfsprogs: fix potential memory leak in verify_set_primary_sb()

In reply to Eric Sandeen

If verify_set_primary_sb() completes the secondary sb scanning loop with too few valid secondaries found (num_ok < num_sbs / 2), it will immediately return without freeing any of the previously allocated memory (variables sb, checked, and any items on the geo list). This was reported by the Coverity scanner as CID 997012, 997013 and 997014.

Fix this by using the out_free_list: goto target for this error case.

Earlier, if get_sb() fails in the secondary scan loop, it goes to
the out: target which does not free any items on the geo list. Fix
this by using the out_free_list: target as well, and remove the now-unused
out: target.

---
v2: as Mark pointed out, out in the for loop before also needs list to
be freed. Also remove out lable as it is not referenced any more.
v3: use a meaningful changlog from Eric, and hide the patch changlogs below "---".

 repair/sb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
repair/sb.c +5 -4
index aa550e3..d34d7a2 100644
@@ -733,7 +733,7 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 			if (get_sb(sb, off, size, agno) == XR_EOF)  {
 				retval = 1;
-				goto out;
+				goto out_free_list;
 			}
 
 			if (verify_sb(sb, 0) == XR_OK)  {
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 	/*
 	 * see if we have enough superblocks to bother with
 	 */
-	if (num_ok < num_sbs / 2)
-		return(XR_INSUFF_SEC_SB);
+	if (num_ok < num_sbs / 2) {
+		retval = XR_INSUFF_SEC_SB;
+		goto out_free_list;
+	}
 
 	current = get_best_geo(list);
 
@@ -841,7 +843,6 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 out_free_list:
 	free_geo(list);
-out:
 	free(sb);
 	free(checked);
 	return(retval);
Signature · 8 lines
1.8.1.4



_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#7 lore raw

PATCH 2/2 xfsprogs: fix return value of verify_set_primary_sb()

If get_sb() fails because of EOF, it will return with retval 1, which will then be interpreted as XR_BAD_MAGIC("bad magic number") in phase1() when warning the user.

This patch fix it by using XR_EOF here, so it would be interpreted correctly. Also change the associated comments about the return value.

---
 repair/sb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
repair/sb.c +2 -2
index d34d7a2..2e35a4c 100644
@@ -665,7 +665,7 @@ get_sb_geometry(fs_geometry_t *geo, xfs_sb_t *sbp)
  * primary and compare the geometries in the secondaries against
  * the geometry indicated by the primary.
  *
- * returns 1 if bad, 0 if ok
+ * returns 0 if ok, else error code (XR_EOF, XR_INSUFF_SEC_SB, etc).
  */
 int
 verify_set_primary_sb(xfs_sb_t		*rsb,
@@ -732,7 +732,7 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 			checked[agno] = 1;
 
 			if (get_sb(sb, off, size, agno) == XR_EOF)  {
-				retval = 1;
+				retval = XR_EOF;
 				goto out_free_list;
 			}
 
Signature · 8 lines
1.8.1.4



_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] xfsprogs: fix return value of verify_set_primary_sb()

Quoted 8 lines · Li Zhong

If get_sb() fails because of EOF, it will return with retval 1, which will then be interpreted as XR_BAD_MAGIC("bad magic number") in phase1() when warning the user.

This patch fix it by using XR_EOF here, so it would be interpreted correctly. Also change the associated comments about the return value.

I think this is OK. I had originally thought we should return whatever XR_* code get_sb() returned, but I wasn't thinking straight; we ignore those other codes, and only stop if we see XR_EOF.

So this is fine as far as it goes; I noticed something else in the process though so I'll send a patch for that. :)

Quoted 19 lines
---
 repair/sb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
repair/sb.c +1 -1
index d34d7a2..2e35a4c 100644
@@ -665,7 +665,7 @@ get_sb_geometry(fs_geometry_t *geo, xfs_sb_t *sbp)
  * primary and compare the geometries in the secondaries against
  * the geometry indicated by the primary.
  *
- * returns 1 if bad, 0 if ok
+ * returns 0 if ok, else error code (XR_EOF, XR_INSUFF_SEC_SB, etc).
  */
 int
 verify_set_primary_sb(xfs_sb_t		*rsb,

repair/sb.c verify_set_primary_sb(xfs_sb_t *rsb, · line 738

Quoted 8 lines
repair/sb.c +1 -1
@@ -732,7 +732,7 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 			checked[agno] = 1;
 
 			if (get_sb(sb, off, size, agno) == XR_EOF)  {
-				retval = 1;
+				retval = XR_EOF;
 				goto out_free_list;
 			}
 

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v3 1/2
#10 lore raw
In reply to Li Zhong
Quoted 13 lines · Li Zhong

If verify_set_primary_sb() completes the secondary sb scanning loop with too few valid secondaries found (num_ok < num_sbs / 2), it will immediately return without freeing any of the previously allocated memory (variables sb, checked, and any items on the geo list). This was reported by the Coverity scanner as CID 997012, 997013 and 997014.

Fix this by using the out_free_list: goto target for this error case.

Earlier, if get_sb() fails in the secondary scan loop, it goes to
the out: target which does not free any items on the geo list. Fix
this by using the out_free_list: target as well, and remove the now-unused
out: target.

Quoted 5 lines

---
v2: as Mark pointed out, out in the for loop before also needs list to
be freed. Also remove out lable as it is not referenced any more.
v3: use a meaningful changlog from Eric, and hide the patch changlogs below "---".

Thanks for that; you can add my:

alongside Mark's.

Quoted 31 lines
 repair/sb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
repair/sb.c +5 -3
index aa550e3..d34d7a2 100644
@@ -733,7 +733,7 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 			if (get_sb(sb, off, size, agno) == XR_EOF)  {
 				retval = 1;
-				goto out;
+				goto out_free_list;
 			}
 
 			if (verify_sb(sb, 0) == XR_OK)  {
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 	/*
 	 * see if we have enough superblocks to bother with
 	 */
-	if (num_ok < num_sbs / 2)
-		return(XR_INSUFF_SEC_SB);
+	if (num_ok < num_sbs / 2) {
+		retval = XR_INSUFF_SEC_SB;
+		goto out_free_list;
+	}
 
 	current = get_best_geo(list);
 

repair/sb.c verify_set_primary_sb(xfs_sb_t *rsb, · line 848

Quoted 7 lines
repair/sb.c +0 -1
@@ -841,7 +843,6 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 out_free_list:
 	free_geo(list);
-out:
 	free(sb);
 	free(checked);
 	return(retval);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author Reviewed-by Mark Tinguely
#11 lore raw
Quoted 20 lines · Eric Sandeen
Quoted 13 lines · Li Zhong

If verify_set_primary_sb() completes the secondary sb scanning loop with too few valid secondaries found (num_ok < num_sbs / 2), it will immediately return without freeing any of the previously allocated memory (variables sb, checked, and any items on the geo list). This was reported by the Coverity scanner as CID 997012, 997013 and 997014.

Fix this by using the out_free_list: goto target for this error case.

Earlier, if get_sb() fails in the secondary scan loop, it goes to
the out: target which does not free any items on the geo list. Fix
this by using the out_free_list: target as well, and remove the now-unused
out: target.

Quoted 5 lines

---
v2: as Mark pointed out, out in the for loop before also needs list to
be freed. Also remove out lable as it is not referenced any more.
v3: use a meaningful changlog from Eric, and hide the patch changlogs below "---".

Quoted 5 lines

Thanks for that; you can add my:

alongside Mark's.

Ah, I missed that. Is it ok to just add it here in this mail?

Quoted 32 lines
Quoted 32 lines
 repair/sb.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
repair/sb.c +5 -3
index aa550e3..d34d7a2 100644
@@ -733,7 +733,7 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
 			if (get_sb(sb, off, size, agno) == XR_EOF)  {
 				retval = 1;
-				goto out;
+				goto out_free_list;
 			}
 
 			if (verify_sb(sb, 0) == XR_OK)  {
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 	/*
 	 * see if we have enough superblocks to bother with
 	 */
-	if (num_ok < num_sbs / 2)
-		return(XR_INSUFF_SEC_SB);
+	if (num_ok < num_sbs / 2) {
+		retval = XR_INSUFF_SEC_SB;
+		goto out_free_list;
+	}
 
 	current = get_best_geo(list);
 
@@ -841,7 +843,6 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
 
Quoted 8 lines

repair/sb.c verify_set_primary_sb(xfs_sb_t *rsb, · line 848

Quoted 7 lines
repair/sb.c +0 -1
 out_free_list:
 	free_geo(list);
-out:
 	free(sb);
 	free(checked);
 	return(retval);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#12 lore raw
Quoted 27 lines · Li Zhong
Quoted 24 lines · Eric Sandeen
Quoted 14 lines · Li Zhong

If verify_set_primary_sb() completes the secondary sb scanning loop with too few valid secondaries found (num_ok < num_sbs / 2), it will immediately return without freeing any of the previously allocated memory (variables sb, checked, and any items on the geo list). This was reported by the Coverity scanner as CID 997012, 997013 and 997014.

Fix this by using the out_free_list: goto target for this error case.

Earlier, if get_sb() fails in the secondary scan loop, it goes to
the out: target which does not free any items on the geo list. Fix
this by using the out_free_list: target as well, and remove the now-unused
out: target.

Quoted 5 lines

---
v2: as Mark pointed out, out in the for loop before also needs list to be freed. Also remove out lable as it is not referenced any more.
v3: use a meaningful changlog from Eric, and hide the patch changlogs below "---".

Thanks for that; you can add my:

Quoted 8 lines
Quoted 3 lines

alongside Mark's.

Ah, I missed that. Is it ok to just add it here in this mail?

Sorry, I meant that for sgi but wasn't clear. Sometimes I talk too much. :)

Eric

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines

repair/sb.c | 9 +++++----

1 file changed, 5 insertions(+), 4 deletions(-)
repair/sb.c +5 -3
index aa550e3..d34d7a2 100644
@@ -733,7 +733,7 @@ verify_set_primary_sb(xfs_sb_t        *rsb,
 
           if (get_sb(sb, off, size, agno) == XR_EOF)  {
               retval = 1;
-                goto out;
+                goto out_free_list;
           }
 
           if (verify_sb(sb, 0) == XR_OK)  {
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t        *rsb,
   /*
    * see if we have enough superblocks to bother with
    */
-    if (num_ok < num_sbs / 2)
-        return(XR_INSUFF_SEC_SB);
+    if (num_ok < num_sbs / 2) {
+        retval = XR_INSUFF_SEC_SB;
+        goto out_free_list;
+    }
 
   current = get_best_geo(list);
 
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
repair/sb.c +0 -0
@@ -841,7 +843,6 @@ verify_set_primary_sb(xfs_sb_t        *rsb,
 

out_free_list:

   free_geo(list);
-out:
   free(sb);
   free(checked);
   return(retval);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#13 lore raw
Quoted 28 lines · Eric Sandeen
Quoted 28 lines · Li Zhong
Quoted 26 lines · Eric Sandeen
Quoted 14 lines · Li Zhong

If verify_set_primary_sb() completes the secondary sb scanning loop with too few valid secondaries found (num_ok < num_sbs / 2), it will immediately return without freeing any of the previously allocated memory (variables sb, checked, and any items on the geo list). This was reported by the Coverity scanner as CID 997012, 997013 and 997014.

Fix this by using the out_free_list: goto target for this error case.

Earlier, if get_sb() fails in the secondary scan loop, it goes to
the out: target which does not free any items on the geo list. Fix
this by using the out_free_list: target as well, and remove the now-unused
out: target.

Quoted 5 lines

---
v2: as Mark pointed out, out in the for loop before also needs list to be freed. Also remove out lable as it is not referenced any more.
v3: use a meaningful changlog from Eric, and hide the patch changlogs below "---".

Thanks for that; you can add my:

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

alongside Mark's.

Ah, I missed that. Is it ok to just add it here in this mail?

Sorry, I meant that for sgi but wasn't clear. Sometimes I talk too much. :)

Oh, I see :)

Thanks, Zhong

Quoted 44 lines

Eric

Quoted 40 lines
Quoted 38 lines
Quoted 38 lines

repair/sb.c | 9 +++++----

1 file changed, 5 insertions(+), 4 deletions(-)
repair/sb.c +5 -3
index aa550e3..d34d7a2 100644
@@ -733,7 +733,7 @@ verify_set_primary_sb(xfs_sb_t        *rsb,
 
           if (get_sb(sb, off, size, agno) == XR_EOF)  {
               retval = 1;
-                goto out;
+                goto out_free_list;
           }
 
           if (verify_sb(sb, 0) == XR_OK)  {
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t        *rsb,
   /*
    * see if we have enough superblocks to bother with
    */
-    if (num_ok < num_sbs / 2)
-        return(XR_INSUFF_SEC_SB);
+    if (num_ok < num_sbs / 2) {
+        retval = XR_INSUFF_SEC_SB;
+        goto out_free_list;
+    }
 
   current = get_best_geo(list);
 
@@ -841,7 +843,6 @@ verify_set_primary_sb(xfs_sb_t        *rsb,
 

out_free_list:

   free_geo(list);
-out:
   free(sb);
   free(checked);
   return(retval);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#15 lore raw
In reply to Mark Tinguely
Quoted 21 lines · Mark Tinguely
Quoted 9 lines · Li Zhong

This patch tries to fix CID 997012, 997013 and 997014 reported by Coverity scan, as suggested by sekharan.

---

repair/sb.c +0 -0
@@ -756,8 +756,10 @@ verify_set_primary_sb(xfs_sb_t		*rsb,
  	/*

repair/sb.c verify_set_primary_sb(xfs_sb_t *rsb, · line 764

Quoted 10 lines
repair/sb.c +4 -2
  	 * see if we have enough superblocks to bother with
  	 */
-	if (num_ok < num_sbs / 2)
-		return(XR_INSUFF_SEC_SB);
+	if (num_ok < num_sbs / 2) {
+		retval = XR_INSUFF_SEC_SB;
+		goto out_free_list;
+	}
 
 
Quoted 3 lines

Looks good. list, sb and check could have been allocated at this point.

Isn't the list been added to before the conditional in the for loop?:

See, I just sent a new version including below change.

Seems it is a Coverity scan bug not discovering this :)

Thanks, Zhong

Quoted 9 lines
         list = add_geo(list, &geo, sb_index);

         /*
          * grab N secondaries.  check them off as we get them
          * so we only process each one once
          */
         for (round = 0; round < skip; round++)  {
Quoted 9 lines

...

                         if (get_sb(sb, off, size, agno) == XR_EOF)  {
                                 retval = 1;
                                 goto out;
				^^^^^^^^^ out_free_list?
                         }

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs