Skip to contentSkip to conversation

ptp: prevent info leak to userspace

PATCH In review Kyle Zeng 2 participants 3 messages Dec 17, 2025

Subsystems (3)
lore
Share & tools
lore

Kyle Zeng

author
#0 lore raw

PATCH 1/1 ptp: prevent info leak to userspace

Somehow the memset is lost after refactor, which leaks a lot of kernel stack data to userspace directly. This patch clears the reserved data region to prevent the info leak.

---
 drivers/ptp/ptp_chardev.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/ptp/ptp_chardev.c +2 -0
index c61cf9edac48..06f71011fb04 100644
@@ -195,6 +195,8 @@ static long ptp_clock_getcaps(struct ptp_clock *ptp, void __user *arg)
 	if (caps.adjust_phase)
 		caps.max_phase_adj = ptp->info->getmaxphase(ptp->info);
 
+	memset(caps.rsv, 0, sizeof(caps.rsv));
+
 	return copy_to_user(arg, &caps, sizeof(caps)) ? -EFAULT : 0;
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 14 lines · Kyle Zeng

Somehow the memset is lost after refactor, which leaks a lot of kernel stack data to userspace directly. This patch clears the reserved data region to prevent the info leak.

---
 drivers/ptp/ptp_chardev.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/ptp/ptp_chardev.c +0 -0
index c61cf9edac48..06f71011fb04 100644

drivers/ptp/ptp_chardev.c static long ptp_clock_getcaps(struct ptp_clock *ptp, void __user *arg) · line 202

Quoted 8 lines
drivers/ptp/ptp_chardev.c +2 -0
@@ -195,6 +195,8 @@ static long ptp_clock_getcaps(struct ptp_clock *ptp, void __user *arg)
 	if (caps.adjust_phase)
 		caps.max_phase_adj = ptp->info->getmaxphase(ptp->info);
 
+	memset(caps.rsv, 0, sizeof(caps.rsv));
+
 	return copy_to_user(arg, &caps, sizeof(caps)) ? -EFAULT : 0;
 }
 

This is not how C works, the designated initializer clears the field implicitly.

author
#2 lore raw

I apologize for the rookie mistake. Should've known better than this. And thanks for the correction.

Quoted 27 lines · Gal Pressman
Quoted 14 lines · Kyle Zeng

Somehow the memset is lost after refactor, which leaks a lot of kernel stack data to userspace directly. This patch clears the reserved data region to prevent the info leak.

---
 drivers/ptp/ptp_chardev.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/ptp/ptp_chardev.c +0 -0
index c61cf9edac48..06f71011fb04 100644

drivers/ptp/ptp_chardev.c static long ptp_clock_getcaps(struct ptp_clock *ptp, void __user *arg) · line 202

Quoted 8 lines
drivers/ptp/ptp_chardev.c +2 -0
@@ -195,6 +195,8 @@ static long ptp_clock_getcaps(struct ptp_clock *ptp, void __user *arg)
      if (caps.adjust_phase)
              caps.max_phase_adj = ptp->info->getmaxphase(ptp->info);
 
+     memset(caps.rsv, 0, sizeof(caps.rsv));
+
      return copy_to_user(arg, &caps, sizeof(caps)) ? -EFAULT : 0;
 }
 

This is not how C works, the designated initializer clears the field implicitly.