Skip to content

Commit 3b84adf

Browse files
RSmirnov512jankara
authored andcommitted
udf: udftime: prevent overflow in udf_disk_stamp_to_time()
An overflow can occur in a situation where src.centiseconds takes the value of 255. This situation is unlikely, but there is no validation check anywere in the code. Found by Linux Verification Center (linuxtesting.org) with Svace. Suggested-by: Jan Kara <[email protected]> Signed-off-by: Roman Smirnov <[email protected]> Reviewed-by: Sergey Shtylyov <[email protected]> Signed-off-by: Jan Kara <[email protected]> Message-Id: <[email protected]>
1 parent 3e90417 commit 3b84adf

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

fs/udf/udftime.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ udf_disk_stamp_to_time(struct timespec64 *dest, struct timestamp src)
4646
dest->tv_sec = mktime64(year, src.month, src.day, src.hour, src.minute,
4747
src.second);
4848
dest->tv_sec -= offset * 60;
49-
dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
50-
src.hundredsOfMicroseconds * 100 + src.microseconds);
49+
5150
/*
5251
* Sanitize nanosecond field since reportedly some filesystems are
5352
* recorded with bogus sub-second values.
5453
*/
55-
dest->tv_nsec %= NSEC_PER_SEC;
54+
if (src.centiseconds < 100 && src.hundredsOfMicroseconds < 100 &&
55+
src.microseconds < 100) {
56+
dest->tv_nsec = 1000 * (src.centiseconds * 10000 +
57+
src.hundredsOfMicroseconds * 100 + src.microseconds);
58+
} else {
59+
dest->tv_nsec = 0;
60+
}
5661
}
5762

5863
void

0 commit comments

Comments
 (0)