Skip to contentSkip to conversation

ia64/sn/hwperf: check seq_open return value to avoid NULL deref

PATCH New Rasmus Villemoes 1 participant 1 message Aug 16, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ia64/sn/hwperf: check seq_open return value to avoid NULL deref

This code should check the return value of seq_open(); if it failed, file->private_data is NULL. But in that case we then need to dispose of objbuf to prevent a resource leak.

---
 arch/ia64/sn/kernel/sn2/sn_hwperf.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/ia64/sn/kernel/sn2/sn_hwperf.c +6 -2
index 55febd65911a..9e36f0b7d9ae 100644
@@ -947,8 +947,12 @@ int sn_topology_open(struct inode *inode, struct file *file)
 
 	if ((e = sn_hwperf_enum_objects(&nobj, &objbuf)) = 0) {
 		e = seq_open(file, &sn_topology_seq_ops);
-		seq = file->private_data;
-		seq->private = objbuf;
+		if (e) {
+			vfree(objbuf);
+		} else {
+			seq = file->private_data;
+			seq->private = objbuf;
+		}
 	}
 
 	return e;
Signature · 1 line
2.16.4