Skip to contentSkip to conversation

eventfs: Directly return NULL to avoid null point dereferenced

PATCH In review [email protected] 2 participants 4 messages May 11, 2024 – May 13, 2024

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

PATCH 1/1 eventfs: Directly return NULL to avoid null point dereferenced

From: Hao Ge <[email protected]>

When the condition ei->is_free holds,we return NULL directly to avoid update_events_attr to use NULL point about ei.

Fixes 8186fff7ab64 ("tracefs/eventfs: Use root and instance inodes as default ownership")
---
 fs/tracefs/event_inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/tracefs/event_inode.c +1 -2
index a878cea70f4c..da2827c6acc2 100644
@@ -346,8 +346,7 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry)
 		 * doesn't matter.
 		 */
 		if (ei->is_freed) {
-			ei = NULL;
-			break;
+			return NULL;
 		}
 		// Walk upwards until you find the events inode
 	} while (!ei->is_events);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines

When the condition ei->is_free holds,we return NULL directly to avoid update_events_attr to use NULL point about ei.

* Please avoid typos in the summary phrase and the commit message.

* Would you like to use an imperative wording for an improved change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.9-rc7#n94

…

fs/tracefs/event_inode.c static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) · line 350

Quoted 9 lines

+++ b/fs/tracefs/event_inode.c

fs/tracefs/event_inode.c +1 -2
@@ -346,8 +346,7 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry)
 		 * doesn't matter.
 		 */
 		if (ei->is_freed) {
-			ei = NULL;
-			break;
+			return NULL;
 		}

…

How do you think about to omit curly brackets here?

Regards,
Markus

author
#2 lore raw

Hi Markus

Thanks for your review.

Quoted 9 lines · Markus Elfring
Quoted 2 lines

When the condition ei->is_free holds,we return NULL directly to avoid update_events_attr to use NULL point about ei.

* Please avoid typos in the summary phrase and the commit message.

* Would you like to use an imperative wording for an improved change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.9-rc7#n94

…

OK, I'll study it,

Quoted 11 lines
Quoted 9 lines

+++ b/fs/tracefs/event_inode.c

fs/tracefs/event_inode.c +1 -2
@@ -346,8 +346,7 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry)
  		 * doesn't matter.
  		 */
  		if (ei->is_freed) {
-			ei = NULL;
-			break;
+			return NULL;
  		}

…

Quoted 1 line

How do you think about to omit curly brackets here?

You are right, I will make changes to it in future versions

Quoted 3 lines

Regards,
Markus

Best Regards

Hao

#3 lore raw

PATCH v2 1/1 eventfs: Fix a possible null pointer dereference in eventfs_find_events

From: Hao Ge <[email protected]>

In function eventfs_find_events,there is a potential null pointer that may be caused by calling update_events_attr which will perform some operations on the members of the ei struct when ei is NULL.

Hence,When ei->is_freed is set,return NULL directly.

Fixes 8186fff7ab64 ("tracefs/eventfs: Use root and instance inodes as default ownership")

---
v2:
- adjust title and commit message
- omit curly brackets

---
 fs/tracefs/event_inode.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/tracefs/event_inode.c +3 -4
index a878cea70f4c..0256afdd4acf 100644
@@ -345,10 +345,9 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry)
 		 * If the ei is being freed, the ownership of the children
 		 * doesn't matter.
 		 */
-		if (ei->is_freed) {
-			ei = NULL;
-			break;
-		}
+		if (ei->is_freed)
+			return NULL;
+
 		// Walk upwards until you find the events inode
 	} while (!ei->is_events);
 
Signature · 1 line
2.25.1