Skip to contentSkip to conversation

Fixed null-ptr-deref Read in drop_buffers

PATCH In review Saru2003 2 participants 2 messages Nov 8, 2024 VFS

lore
Share & tools
lore

Saru2003

author
#0 lore raw

PATCH 1/1 Fixed null-ptr-deref Read in drop_buffers

---
 fs/buffer.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/buffer.c +9 -0
index 1fc9a50def0b..e32420d8b9e3 100644
@@ -2888,14 +2888,23 @@ drop_buffers(struct folio *folio, struct buffer_head **buffers_to_free)
 	struct buffer_head *head = folio_buffers(folio);
 	struct buffer_head *bh;
 
+	if (!head) {
+		goto failed;
+	}
+
 	bh = head;
 	do {
+		if (!bh)
+			goto failed;
 		if (buffer_busy(bh))
 			goto failed;
 		bh = bh->b_this_page;
 	} while (bh != head);
 
 	do {
+		if (!bh)
+			goto failed;
+
 		struct buffer_head *next = bh->b_this_page;
 
 		if (bh->b_assoc_map)
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 10 lines · On Fri, Nov 08, 2024 at 08:07:17AM +0530, Saru2003 wrote:
---
 fs/buffer.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/buffer.c +0 -0
index 1fc9a50def0b..e32420d8b9e3 100644

fs/buffer.c drop_buffers(struct folio *folio, struct buffer_head **buffers_to_free) · line 2893

Quoted 6 lines
fs/buffer.c +3 -0
@@ -2888,14 +2888,23 @@ drop_buffers(struct folio *folio, struct buffer_head **buffers_to_free)
 	struct buffer_head *head = folio_buffers(folio);
 	struct buffer_head *bh;
 
+	if (!head) {
+		goto failed;
+	}

Which caller can hit that?

fs/buffer.c drop_buffers(struct folio *folio, struct buffer_head **buffers_to_free) · line 2898

Quoted 4 lines
fs/buffer.c +2 -0
 	bh = head;
 	do {
+		if (!bh)
+			goto failed;

Huh? How the hell can _that_ happen? "Somehow got called for a folio without associated buffer_heads" is one thing, but this would require an obvious memory corruption; a NULL forward pointer in the middle of a cyclic list.

fs/buffer.c drop_buffers(struct folio *folio, struct buffer_head **buffers_to_free) · line 2906

Quoted 8 lines
fs/buffer.c +2 -0
 		if (buffer_busy(bh))
 			goto failed;
 		bh = bh->b_this_page;
 	} while (bh != head);
 
 	do {
+		if (!bh)
+			goto failed;

NAK. In the best case you are papering over unrelated memory corruption.

Please, explain what's going on. Random checks for pointers being NULL are not magical unicorn piss to be sprinkled all over the place...

And "fixed null-pointer-deref" does *not* work as an explanation - not with otherwise empty commit message.