* [PATCH] time/namespace: Validate nanosecond field in proc_timens_set_offset()
@ 2026-07-04 9:34 Malaya Kumar Rout
2026-07-07 21:32 ` [tip: timers/core] " tip-bot2 for Malaya Kumar Rout
0 siblings, 1 reply; 2+ messages in thread
From: Malaya Kumar Rout @ 2026-07-04 9:34 UTC (permalink / raw)
To: linux-kernel, tglx
Cc: mrout, skhan, me, Malaya Kumar Rout, Anna-Maria Behnsen,
Frederic Weisbecker, Dmitry Safonov, Andrei Vagin
The function validates tv_sec to be within [-KTIME_SEC_MAX, KTIME_SEC_MAX]
but never validates that tv_nsec is within the valid range of
[0, NSEC_PER_SEC-1] before using it in timespec64_add().
timespec64_add() expects both timespec64 structures to have normalized
values with tv_nsec in the range [0, 999999999]. If off->val.tv_nsec
contains invalid values (negative or >= NSEC_PER_SEC), it could lead to
incorrect calculations or unexpected behavior.
Add validation to ensure tv_nsec is within the valid range before
performing the addition.
Fixes: 04a8682a71be ("fs/proc: Introduce /proc/pid/timens_offsets")
Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
---
kernel/time/namespace.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
index 5fa0af66cf3f..d1b5de88f8ff 100644
--- a/kernel/time/namespace.c
+++ b/kernel/time/namespace.c
@@ -297,6 +297,9 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
off->val.tv_sec < -KTIME_SEC_MAX)
return -ERANGE;
+ if (off->val.tv_nsec < 0 || off->val.tv_nsec >= NSEC_PER_SEC)
+ return -EINVAL;
+
tp = timespec64_add(tp, off->val);
/*
* KTIME_SEC_MAX is divided by 2 to be sure that KTIME_MAX is
--
2.54.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* [tip: timers/core] time/namespace: Validate nanosecond field in proc_timens_set_offset()
2026-07-04 9:34 [PATCH] time/namespace: Validate nanosecond field in proc_timens_set_offset() Malaya Kumar Rout
@ 2026-07-07 21:32 ` tip-bot2 for Malaya Kumar Rout
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Malaya Kumar Rout @ 2026-07-07 21:32 UTC (permalink / raw)
To: linux-tip-commits; +Cc: Malaya Kumar Rout, Thomas Gleixner, x86, linux-kernel
The following commit has been merged into the timers/core branch of tip:
Commit-ID: 06aba58e58492d2b8eae059274caed29025ea96e
Gitweb: https://git.kernel.org/tip/06aba58e58492d2b8eae059274caed29025ea96e
Author: Malaya Kumar Rout <malayarout91@gmail.com>
AuthorDate: Sat, 04 Jul 2026 15:04:28 +05:30
Committer: Thomas Gleixner <tglx@kernel.org>
CommitterDate: Tue, 07 Jul 2026 23:26:58 +02:00
time/namespace: Validate nanosecond field in proc_timens_set_offset()
The function validates tv_sec to be within [-KTIME_SEC_MAX, KTIME_SEC_MAX]
but never validates that tv_nsec is within the valid range of
[0, NSEC_PER_SEC-1] before using it in timespec64_add().
timespec64_add() expects both timespec64 structures to have normalized
values with tv_nsec in the range [0, 999999999]. If off->val.tv_nsec
contains invalid values (negative or >= NSEC_PER_SEC), it could lead to
incorrect calculations or unexpected behavior.
Add validation to ensure tv_nsec is within the valid range before
performing the addition.
Fixes: 04a8682a71be ("fs/proc: Introduce /proc/pid/timens_offsets")
Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260704093429.89350-1-malayarout91@gmail.com
---
kernel/time/namespace.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
index 5fa0af6..3aff27b 100644
--- a/kernel/time/namespace.c
+++ b/kernel/time/namespace.c
@@ -293,10 +293,12 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p,
return -EINVAL;
}
- if (off->val.tv_sec > KTIME_SEC_MAX ||
- off->val.tv_sec < -KTIME_SEC_MAX)
+ if (off->val.tv_sec > KTIME_SEC_MAX || off->val.tv_sec < -KTIME_SEC_MAX)
return -ERANGE;
+ if (off->val.tv_nsec < 0 || off->val.tv_nsec >= NSEC_PER_SEC)
+ return -EINVAL;
+
tp = timespec64_add(tp, off->val);
/*
* KTIME_SEC_MAX is divided by 2 to be sure that KTIME_MAX is
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-07 21:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-04 9:34 [PATCH] time/namespace: Validate nanosecond field in proc_timens_set_offset() Malaya Kumar Rout
2026-07-07 21:32 ` [tip: timers/core] " tip-bot2 for Malaya Kumar Rout
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox