lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240906034806.1161083-2-ruanjinjie@huawei.com>
Date: Fri, 6 Sep 2024 11:48:05 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <bryan.whitehead@...rochip.com>, <davem@...emloft.net>,
	<edumazet@...gle.com>, <kuba@...nel.org>, <pabeni@...hat.com>,
	<richardcochran@...il.com>, <UNGLinuxDriver@...rochip.com>, <andrew@...n.ch>,
	<netdev@...r.kernel.org>
CC: <ruanjinjie@...wei.com>
Subject: [PATCH -next v2 1/2] ptp: Check timespec64 before call settime64()

As Andrew pointed out, it will make sence that the PTP core
checked timespec64 struct's tv_sec and tv_nsec range before calling
ptp->info->settime64(), so check it ahead.

There are some drivers that use tp->tv_sec and tp->tv_nsec directly to
write registers without validity checks and assume that the PTP core has
been checked, which is dangerous and will benefit from this, such as
hclge_ptp_settime(), igb_ptp_settime_i210(), _rcar_gen4_ptp_settime(),
and some drivers can remove the checks of itself.

Signed-off-by: Jinjie Ruan <ruanjinjie@...wei.com>
Suggested-by: Andrew Lunn <andrew@...n.ch>
---
 drivers/ptp/ptp_clock.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index c56cd0f63909..cf75899a6681 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -100,6 +100,16 @@ static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tp
 		return -EBUSY;
 	}
 
+	if (!tp) {
+		pr_warn("ptp: tp == NULL\n");
+		return -EINVAL;
+	}
+
+	if (!timespec64_valid(tp)) {
+		pr_warn("ptp: tv_sec or tv_usec out of range\n");
+		return -ERANGE;
+	}
+
 	return  ptp->info->settime64(ptp->info, tp);
 }
 
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ