Skip to contentSkip to conversation

Check for Null return of function of affs_bread in function affs_truncate

PATCH In review Nicholas Krause 5 participants 12 messages Jun 18, 2014 – Jul 13, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Check for Null return of function of affs_bread in function affs_truncate

---
 fs/affs/file.c | 2 ++
 1 file changed, 2 insertions(+)
fs/affs/file.c +2 -0
index a7fe57d..f26482d 100644
@@ -923,6 +923,8 @@ affs_truncate(struct inode *inode)
 
 	while (ext_key) {
 		ext_bh = affs_bread(sb, ext_key);
+		if (!ext_bh)
+			return;
 		size = AFFS_SB(sb)->s_hashsize;
 		if (size > blkcnt - blk)
 			size = blkcnt - blk;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 10 lines · Nicholas Krause
---
 fs/affs/file.c | 2 ++
 1 file changed, 2 insertions(+)
fs/affs/file.c +0 -0
index a7fe57d..f26482d 100644

fs/affs/file.c affs_truncate(struct inode *inode) · line 927

Quoted 5 lines
fs/affs/file.c +2 -0
@@ -923,6 +923,8 @@ affs_truncate(struct inode *inode)
 
 	while (ext_key) {
 		ext_bh = affs_bread(sb, ext_key);
+		if (!ext_bh)
+			return;

The problem is that we don't know if we should return here or break here. If you don't understand the code, then it's best to just leave it alone.

regards,
dan carpenter

Quoted 5 lines
fs/affs/file.c +0 -0
 		size = AFFS_SB(sb)->s_hashsize;
 		if (size > blkcnt - blk)
 			size = blkcnt - blk;
Signature · 1 line
1.9.1
#2 lore raw

Ok that's fine I would return as if it's a NULL the other parts of the function can't continue.
Nick

Quoted 29 lines · Dan Carpenter
Quoted 10 lines · Nicholas Krause
---
 fs/affs/file.c | 2 ++
 1 file changed, 2 insertions(+)
fs/affs/file.c +0 -0
index a7fe57d..f26482d 100644

fs/affs/file.c affs_truncate(struct inode *inode) · line 927

Quoted 5 lines
fs/affs/file.c +2 -0
@@ -923,6 +923,8 @@ affs_truncate(struct inode *inode)
 
      while (ext_key) {
              ext_bh = affs_bread(sb, ext_key);
+             if (!ext_bh)
+                     return;

The problem is that we don't know if we should return here or break here. If you don't understand the code, then it's best to just leave it alone.

regards,
dan carpenter

Quoted 5 lines
fs/affs/file.c +0 -1
              size = AFFS_SB(sb)->s_hashsize;
              if (size > blkcnt - blk)
                      size = blkcnt - blk;
--

1.9.1

#3 lore raw
Quoted 4 lines · Nick Krause

Ok that's fine I would return as if it's a NULL the other parts of the function can't continue.
Nick

Quoted 21 lines
Quoted 20 lines · Dan Carpenter
Quoted 10 lines · Nicholas Krause
---
 fs/affs/file.c | 2 ++
 1 file changed, 2 insertions(+)
fs/affs/file.c +0 -0
index a7fe57d..f26482d 100644

fs/affs/file.c affs_truncate(struct inode *inode) · line 927

Quoted 5 lines
fs/affs/file.c +2 -0
@@ -923,6 +923,8 @@ affs_truncate(struct inode *inode)
 
      while (ext_key) {
              ext_bh = affs_bread(sb, ext_key);
+             if (!ext_bh)
+                     return;

The problem is that we don't know if we should return here or break here. If you don't understand the code, then it's best to just leave it alone.

Dan, what kind of attitude is that?

Nick certainly found an issue where a possible NULL return from affs_bread() can cause havoc.

Do YOU understand that code?

If yes, you better explain, WHY Nicks finding is a false positive instead of just telling him off in a very inpolite way.

If not, you better refrain from telling a reporter that he does not understand the code and should stay away.

You clearly stated that you do not understand it either:

Quoted 2 lines
Quoted 2 lines

The problem is that we don't know if we should return here or break here.

The problem here is that proceeding with a known NULL pointer is wrong to begin with. It does not matter at all whether break or return is the proper thing to do. What matters is that proceeding with a NULL pointer is wrong to begin with, no matter what.

So either explain why this is a non issue and the NULL pointer return cannot happen or shut up and try to find a proper solution for that "return" vs. "break" issue.

Thanks,

tglx

#4 lore raw

Thanks for standing up for me Thomas.
If you have any ideas about what is better
please let me known.
Cheers Nick

Quoted 58 lines · Thomas Gleixner
Quoted 4 lines · Nick Krause

Ok that's fine I would return as if it's a NULL the other parts of the function can't continue.
Nick

Quoted 21 lines
Quoted 20 lines · Dan Carpenter
Quoted 10 lines · Nicholas Krause
---
 fs/affs/file.c | 2 ++
 1 file changed, 2 insertions(+)
fs/affs/file.c +0 -0
index a7fe57d..f26482d 100644

fs/affs/file.c affs_truncate(struct inode *inode) · line 927

Quoted 5 lines
fs/affs/file.c +2 -0
@@ -923,6 +923,8 @@ affs_truncate(struct inode *inode)
 
      while (ext_key) {
              ext_bh = affs_bread(sb, ext_key);
+             if (!ext_bh)
+                     return;

The problem is that we don't know if we should return here or break here. If you don't understand the code, then it's best to just leave it alone.

Dan, what kind of attitude is that?

Nick certainly found an issue where a possible NULL return from affs_bread() can cause havoc.

Do YOU understand that code?

If yes, you better explain, WHY Nicks finding is a false positive instead of just telling him off in a very inpolite way.

If not, you better refrain from telling a reporter that he does not understand the code and should stay away.

You clearly stated that you do not understand it either:

Quoted 2 lines
Quoted 2 lines

The problem is that we don't know if we should return here or break here.

The problem here is that proceeding with a known NULL pointer is wrong to begin with. It does not matter at all whether break or return is the proper thing to do. What matters is that proceeding with a NULL pointer is wrong to begin with, no matter what.

So either explain why this is a non issue and the NULL pointer return cannot happen or shut up and try to find a proper solution for that "return" vs. "break" issue.

Thanks,

tglx

#5 lore raw
Quoted 2 lines · On Fri, 20 Jun 2014 22:25:47 -0400 Nick Krause <[email protected]> wrote:

If you have any ideas about what is better
please let me known.

I think the proposed patch was not a good one - it will cause truncate to silently return, probably leaving the fs in an inconsistent state. Neither the user nor the running application know this happened so they will just keep on modifying the filesystem, possibly mangling it further.

The code as it stands at present is better - if bread() fails we'll get a nice solid oops and the current app will be terminated (at least). As we're in truncate it's quite possible that the entire fs will get wedged up due to now-permanently-held i_mutex, which is even better.

As for the best fix, umm, hard. We're pretty screwed if we cannot read that block at this code site. Perhaps emit loud printks, forcibly turn the fs read-only then return -EIO/-ENOMEM/etc from the truncate. Such a change would require runtime testing, with some form of developer fault injection.

#6 lore raw

Fair enough if somebody is running this file system I would be happy to have someone test my code in order to fix this. Cheers Nick

Quoted 25 lines · Andrew Morton
Quoted 2 lines · On Fri, 20 Jun 2014 22:25:47 -0400 Nick Krause <[email protected]> wrote:

If you have any ideas about what is better
please let me known.

I think the proposed patch was not a good one - it will cause truncate to silently return, probably leaving the fs in an inconsistent state. Neither the user nor the running application know this happened so they will just keep on modifying the filesystem, possibly mangling it further.

The code as it stands at present is better - if bread() fails we'll get a nice solid oops and the current app will be terminated (at least). As we're in truncate it's quite possible that the entire fs will get wedged up due to now-permanently-held i_mutex, which is even better.

As for the best fix, umm, hard. We're pretty screwed if we cannot read that block at this code site. Perhaps emit loud printks, forcibly turn the fs read-only then return -EIO/-ENOMEM/etc from the truncate. Such a change would require runtime testing, with some form of developer fault injection.

#7 lore raw
Quoted 19 lines · On Fri, 20 Jun 2014 22:55:07 -0400 Nick Krause <[email protected]> wrote:
Quoted 17 lines · Andrew Morton
Quoted 2 lines · On Fri, 20 Jun 2014 22:25:47 -0400 Nick Krause <[email protected]> wrote:

If you have any ideas about what is better
please let me known.

I think the proposed patch was not a good one - it will cause truncate to silently return, probably leaving the fs in an inconsistent state. Neither the user nor the running application know this happened so they will just keep on modifying the filesystem, possibly mangling it further.

The code as it stands at present is better - if bread() fails we'll get a nice solid oops and the current app will be terminated (at least). As we're in truncate it's quite possible that the entire fs will get wedged up due to now-permanently-held i_mutex, which is even better.

Quoted 8 lines
Quoted 5 lines

As for the best fix, umm, hard. We're pretty screwed if we cannot read that block at this code site. Perhaps emit loud printks, forcibly turn the fs read-only then return -EIO/-ENOMEM/etc from the truncate. Such a change would require runtime testing, with some form of developer fault injection.

Fair enough if somebody is running this file system I would be happy to have someone test my code in order to fix this.

(top-posting repaired - please don't top-post!)

It's going to be hard to find such a person. As mkfs.affs doesn't appear to exist (?) your best bet would be to find someone who has an Amiga, get them to create a new fs for you (via loopback-on-file) then gzip the underlying file and send it to you. You can then use that fs image file as many times as you want via loopback or straight onto a disk. Make sure the image file is zeroed out first so it compresses well.

Or something like that.

#8 lore raw

I don't think that it's a good idea , in that case I would recommend either leaving this bug open or close it as there doesn't seem to be a good way of testing this.
Cheers Nick

Quoted 41 lines · Andrew Morton
Quoted 19 lines · On Fri, 20 Jun 2014 22:55:07 -0400 Nick Krause <[email protected]> wrote:
Quoted 17 lines · Andrew Morton
Quoted 2 lines · On Fri, 20 Jun 2014 22:25:47 -0400 Nick Krause <[email protected]> wrote:

If you have any ideas about what is better
please let me known.

I think the proposed patch was not a good one - it will cause truncate to silently return, probably leaving the fs in an inconsistent state. Neither the user nor the running application know this happened so they will just keep on modifying the filesystem, possibly mangling it further.

The code as it stands at present is better - if bread() fails we'll get a nice solid oops and the current app will be terminated (at least). As we're in truncate it's quite possible that the entire fs will get wedged up due to now-permanently-held i_mutex, which is even better.

Quoted 8 lines
Quoted 5 lines

As for the best fix, umm, hard. We're pretty screwed if we cannot read that block at this code site. Perhaps emit loud printks, forcibly turn the fs read-only then return -EIO/-ENOMEM/etc from the truncate. Such a change would require runtime testing, with some form of developer fault injection.

Fair enough if somebody is running this file system I would be happy to have someone test my code in order to fix this.

(top-posting repaired - please don't top-post!)

It's going to be hard to find such a person. As mkfs.affs doesn't appear to exist (?) your best bet would be to find someone who has an Amiga, get them to create a new fs for you (via loopback-on-file) then gzip the underlying file and send it to you. You can then use that fs image file as many times as you want via loopback or straight onto a disk. Make sure the image file is zeroed out first so it compresses well.

Or something like that.

maintainer
#9 lore raw
In reply to Thomas Gleixner
Quoted 8 lines · Thomas Gleixner
Quoted 3 lines
Quoted 3 lines

The problem is that we don't know if we should return here or break here. If you don't understand the code, then it's best to just leave it alone.

Dan, what kind of attitude is that?

Nick certainly found an issue where a possible NULL return from affs_bread() can cause havoc.

Yes. No arguments here.

Quoted 4 lines

Do YOU understand that code?

If yes, you better explain, WHY Nicks finding is a false positive instead of just telling him off in a very inpolite way.

It's not a false positive at all.

Quoted 2 lines

If not, you better refrain from telling a reporter that he does not understand the code and should stay away.

Tone aside, he does have a point - namely, that patch in question doesn't contain any analysis of the bug and recovery strategy, turning a bug into something that is much harder to spot on inspection.

If nothing else, such patches should contain a loud printk added on the b0rken codepath, along with a big fat warning in the source.

I'm not saying that "fuck off unless you understand the code" is a sane policy - it's not. But "anything's better than an oops" is also wrong.

Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

The problem is that we don't know if we should return here or break here.

The problem here is that proceeding with a known NULL pointer is wrong to begin with. It does not matter at all whether break or return is the proper thing to do. What matters is that proceeding with a NULL pointer is wrong to begin with, no matter what.

So either explain why this is a non issue and the NULL pointer return cannot happen or shut up and try to find a proper solution for that "return" vs. "break" issue.

return vs. break here is the difference between discarding preallocated blocks and leaking them as well. The thing is, it's either severe OOM or a corrupted image. I'd *probably* go for "affs_error() and return" here, but that's not the only question - we probably ought to make it return an error, instead of having it void. And callers tend to do that affs_free_prealloc(), so much that I'm not sure if we actually want to keep it in affs_truncate() at all.

#10 lore raw
In reply to Thomas Gleixner
Quoted 28 lines · Thomas Gleixner
Quoted 4 lines · Nick Krause

Ok that's fine I would return as if it's a NULL the other parts of the function can't continue.
Nick

Quoted 21 lines
Quoted 20 lines · Dan Carpenter
Quoted 10 lines · Nicholas Krause
---
 fs/affs/file.c | 2 ++
 1 file changed, 2 insertions(+)
fs/affs/file.c +0 -0
index a7fe57d..f26482d 100644

fs/affs/file.c affs_truncate(struct inode *inode) · line 927

Quoted 5 lines
fs/affs/file.c +2 -0
@@ -923,6 +923,8 @@ affs_truncate(struct inode *inode)
 
      while (ext_key) {
              ext_bh = affs_bread(sb, ext_key);
+             if (!ext_bh)
+                     return;

The problem is that we don't know if we should return here or break here. If you don't understand the code, then it's best to just leave it alone.

Quoted 1 line

Dan, what kind of attitude is that?

I'm just catching up on email after being offline for a while.

I apologize that my email came off ruder than intended.

I just meant that as a general rule, sometimes you should leave the static checker warning there if you aren't sure what the correct fix is. Even when it's a real bug, don't just guess at it, you have to be sure. Otherwise you just create a more subtle bug that the static checker can't detect.

regards,
dan carpenter

#11 lore raw
Quoted 35 lines · Dan Carpenter
Quoted 28 lines · Thomas Gleixner
Quoted 4 lines · Nick Krause

Ok that's fine I would return as if it's a NULL the other parts of the function can't continue.
Nick

Quoted 21 lines
Quoted 20 lines · Dan Carpenter
Quoted 10 lines · Nicholas Krause
---
 fs/affs/file.c | 2 ++
 1 file changed, 2 insertions(+)
fs/affs/file.c +0 -0
index a7fe57d..f26482d 100644

fs/affs/file.c affs_truncate(struct inode *inode) · line 927

Quoted 5 lines
fs/affs/file.c +2 -0
@@ -923,6 +923,8 @@ affs_truncate(struct inode *inode)
 
      while (ext_key) {
              ext_bh = affs_bread(sb, ext_key);
+             if (!ext_bh)
+                     return;

The problem is that we don't know if we should return here or break here. If you don't understand the code, then it's best to just leave it alone.

Quoted 1 line

Dan, what kind of attitude is that?

I'm just catching up on email after being offline for a while.

I apologize that my email came off ruder than intended.

Quoted 9 lines

I just meant that as a general rule, sometimes you should leave the static checker warning there if you aren't sure what the correct fix is. Even when it's a real bug, don't just guess at it, you have to be sure. Otherwise you just create a more subtle bug that the static checker can't detect.

regards,
dan carpenter

Hey Dan,
I am pretty sure this is correct as affs_bread does not check for NULL and I am checking
the return of this function. If you feel this patch is wrong and would like me to rewrite it.
Cheers Nick