summaryrefslogtreecommitdiffstats
path: root/drivers/rtc/lib.c
diff options
context:
space:
mode:
authorXuefeng Wang <wxf.wang@hisilicon.com>2019-02-15 11:13:59 +0800
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2019-04-06 15:05:31 +0200
commit73f28f714a8fd0ecb692a225bb7a5979d902ecb5 (patch)
tree5e33a8d62239ecb8e659ec03fd94a9186c0522c5 /drivers/rtc/lib.c
parentc48cadf5bf4becefcd0751b97995d2350aa9bb57 (diff)
downloadlinux-73f28f714a8fd0ecb692a225bb7a5979d902ecb5.tar.bz2
rtc: lib: check whether tm->tm_year in int32 range
When setting rtc alarm (RTC_WKALM_SET), the tm_year is not checked if it is in suiteable range. Use INT_MAX - 1900 to check it. UBSAN: Undefined behaviour in drivers/rtc/rtc-lib.c:119:30 signed integer overflow: 2147483647 + 1900 cannot be represented in type 'int' CPU: 1 PID: 20994 Comm: syz-executor0 Not tainted 4.19.18-514.55.6.9.x86_64 + #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xca/0x13e lib/dump_stack.c:113 ubsan_epilogue+0xe/0x81 lib/ubsan.c:159 handle_overflow+0x193/0x1e2 lib/ubsan.c:190 rtc_tm_to_time64+0x267/0x280 drivers/rtc/rtc-lib.c:119 rtc_tm_to_ktime+0x16/0x70 drivers/rtc/rtc-lib.c:129 rtc_set_alarm+0x1a9/0x2d0 drivers/rtc/interface.c:466 rtc_dev_ioctl+0x6db/0x810 drivers/rtc/rtc-dev.c:380 vfs_ioctl fs/ioctl.c:46 [inline] do_vfs_ioctl+0x1a5/0x10b0 fs/ioctl.c:690 ksys_ioctl+0x89/0xa0 fs/ioctl.c:705 __do_sys_ioctl fs/ioctl.c:712 [inline] __se_sys_ioctl fs/ioctl.c:710 [inline] __x64_sys_ioctl+0x74/0xb0 fs/ioctl.c:710 do_syscall_64+0xc8/0x580 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x462589 Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f5348896c58 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 000000000072bf00 RCX: 0000000000462589 RDX: 0000000020000000 RSI: 000000004028700f RDI: 0000000000000003 RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f53488976bc R13: 00000000004bf67e R14: 00000000006f96e0 R15: 00000000ffffffff ========================================================================== Signed-off-by: Xuefeng Wang <wxf.wang@hisilicon.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc/lib.c')
-rw-r--r--drivers/rtc/lib.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/rtc/lib.c b/drivers/rtc/lib.c
index e36c233455ee..23284580df97 100644
--- a/drivers/rtc/lib.c
+++ b/drivers/rtc/lib.c
@@ -94,6 +94,7 @@ EXPORT_SYMBOL(rtc_time64_to_tm);
int rtc_valid_tm(struct rtc_time *tm)
{
if (tm->tm_year < 70 ||
+ tm->tm_year > (INT_MAX - 1900) ||
((unsigned int)tm->tm_mon) >= 12 ||
tm->tm_mday < 1 ||
tm->tm_mday > rtc_month_days(tm->tm_mon,