Skip to contentSkip to conversation

mm/writeback: fix dereferencing NULL mapping->host

PATCH Superseded Andrew Yang 2 participants 4 messages Nov 29, 2022 – Nov 30, 2022

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

PATCH 1/1 mm/writeback: fix dereferencing NULL mapping->host

From: "andrew.yang" <[email protected]>

Check before dereferencing mapping->host

---
 include/trace/events/writeback.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/trace/events/writeback.h +1 -1
index 86b2a82da546..56f6e114d3ed 100644
@@ -68,7 +68,7 @@ DECLARE_EVENT_CLASS(writeback_folio_template,
 		strscpy_pad(__entry->name,
 			    bdi_dev_name(mapping ? inode_to_bdi(mapping->host) :
 					 NULL), 32);
-		__entry->ino = mapping ? mapping->host->i_ino : 0;
+		__entry->ino = mapping && mapping->host ? mapping->host->i_ino : 0;
 		__entry->index = folio->index;
 	),
 
Signature · 1 line
2.18.0
maintainer
#1 lore raw
Quoted 14 lines · On Tue, 29 Nov 2022 11:32:59 +0800 Andrew Yang <[email protected]> wrote:

From: "andrew.yang" <[email protected]>

Check before dereferencing mapping->host

---
 include/trace/events/writeback.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/trace/events/writeback.h +0 -0
index 86b2a82da546..56f6e114d3ed 100644

include/trace/events/writeback.h DECLARE_EVENT_CLASS(writeback_folio_template, · line 71

Quoted 5 lines
include/trace/events/writeback.h +1 -1
@@ -68,7 +68,7 @@ DECLARE_EVENT_CLASS(writeback_folio_template,
 		strscpy_pad(__entry->name,
 			    bdi_dev_name(mapping ? inode_to_bdi(mapping->host) :
 					 NULL), 32);
-		__entry->ino = mapping ? mapping->host->i_ino : 0;
+		__entry->ino = mapping && mapping->host ? mapping->host->i_ino : 0;

I hate remembering precedence. Can we add parenthesis around this to be clear?

		__entry->ino = (mapping && mapping->host) ? mapping->host->i_ino : 0;

Thanks,

-- Steve

Quoted 3 lines
include/trace/events/writeback.h +0 -0
 		__entry->index = folio->index;
 	),
 
#2 lore raw

PATCH v2 1/1 mm/writeback: fix dereferencing NULL mapping->host

From: "andrew.yang" <[email protected]>

Check before dereferencing mapping->host

---
v2: add parenthesis

---
 include/trace/events/writeback.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/trace/events/writeback.h +1 -1
index 86b2a82da546..54e353c9f919 100644
@@ -68,7 +68,7 @@ DECLARE_EVENT_CLASS(writeback_folio_template,
 		strscpy_pad(__entry->name,
 			    bdi_dev_name(mapping ? inode_to_bdi(mapping->host) :
 					 NULL), 32);
-		__entry->ino = mapping ? mapping->host->i_ino : 0;
+		__entry->ino = (mapping && mapping->host) ? mapping->host->i_ino : 0;
 		__entry->index = folio->index;
 	),
 
Signature · 1 line
2.18.0
#3 lore raw
Quoted 30 lines · Steven Rostedt
Quoted 21 lines · On Tue, 29 Nov 2022 11:32:59 +0800 Andrew Yang <[email protected]> wrote:

From: "andrew.yang" <[email protected]>

Check before dereferencing mapping->host

---
 include/trace/events/writeback.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/trace/events/writeback.h +0 -0
index 86b2a82da546..56f6e114d3ed 100644
@@ -68,7 +68,7 @@ DECLARE_EVENT_CLASS(writeback_folio_template,
 		strscpy_pad(__entry->name,
 			    bdi_dev_name(mapping ?

inode_to_bdi(mapping->host) :

include/trace/events/writeback.h +1 -1
 					 NULL), 32);
-		__entry->ino = mapping ? mapping->host->i_ino : 0;
+		__entry->ino = mapping && mapping->host ? mapping-
Quoted 1 line
Quoted 1 line

host->i_ino : 0;

I hate remembering precedence. Can we add parenthesis around this to be
clear?

Quoted 13 lines
		__entry->ino = (mapping && mapping->host) ? mapping-
Quoted 1 line

host->i_ino : 0;

Thanks,

-- Steve

Quoted 3 lines
include/trace/events/writeback.h +0 -0
 		__entry->index = folio->index;
 	),

Sure, that's a good suggestion