From patchwork Wed Jun 1 03:06:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 9145965 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 01A0E60777 for ; Wed, 1 Jun 2016 03:09:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA13425EF7 for ; Wed, 1 Jun 2016 03:09:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEE6D2693F; Wed, 1 Jun 2016 03:09:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9499B25EF7 for ; Wed, 1 Jun 2016 03:09:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b7wVb-0008H2-CJ; Wed, 01 Jun 2016 03:07:51 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b7wV9-0007fY-5h for linux-arm-kernel@lists.infradead.org; Wed, 01 Jun 2016 03:07:25 +0000 Received: from 172.24.1.136 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.136]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DHZ71581; Wed, 01 Jun 2016 11:06:12 +0800 (CST) Received: from localhost (10.177.19.219) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Wed, 1 Jun 2016 11:06:04 +0800 From: Yang Yingliang To: Subject: [RFC PATCH 2/4] arm64: vdso: check whether the params of gettimeofday() is valid Date: Wed, 1 Jun 2016 11:06:00 +0800 Message-ID: <1464750362-14188-3-git-send-email-yangyingliang@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1464750362-14188-1-git-send-email-yangyingliang@huawei.com> References: <1464750362-14188-1-git-send-email-yangyingliang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.219] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.574E5125.0066, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 395a4d135e77ee562c7bf4b77e5d2662 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160531_200723_981659_69FEF6B8 X-CRM114-Status: GOOD ( 12.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: will.deacon@arm.com, linuxarm@huawei.com, guohanjun@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When the params of gettimeofday() is an invalid addr(E.g. gettimeofday(-1, -1)), it will get segment fault. To avoid this fault, use RANGE_OK to test whether a block of memory is valid. Returns -EFAULT if the range is invalid, 0 otherwise. Signed-off-by: Yang Yingliang --- arch/arm64/kernel/vdso/gettimeofday.S | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/vdso/gettimeofday.S b/arch/arm64/kernel/vdso/gettimeofday.S index 05ccaca..43ec321 100644 --- a/arch/arm64/kernel/vdso/gettimeofday.S +++ b/arch/arm64/kernel/vdso/gettimeofday.S @@ -22,6 +22,7 @@ #include #include #include +#include #define NSEC_PER_SEC_LO16 0xca00 #define NSEC_PER_SEC_HI16 0x3b9a @@ -78,10 +79,12 @@ ENTRY(__kernel_gettimeofday) /* Acquire the sequence counter and get the timespec. */ adr vdso_data, _vdso_data 1: seqcnt_acquire - cbnz use_syscall, 4f + cbnz use_syscall, 5f /* If tv is NULL, skip to the timezone code. */ cbz x0, 2f + RANGE_OK(0, #TVAL_SZ) + cbz x4, 4f bl __do_get_tspec seqcnt_check w9, 1b @@ -93,12 +96,18 @@ ENTRY(__kernel_gettimeofday) 2: /* If tz is NULL, return 0. */ cbz x1, 3f + RANGE_OK(1, #TZ_SZ) + cbz x4, 4f ldp w4, w5, [vdso_data, #VDSO_TZ_MINWEST] stp w4, w5, [x1, #TZ_MINWEST] 3: mov x0, xzr ret x2 4: + /* tz is invalid */ + mov x0, #-EFAULT + ret x2 +5: /* Syscall fallback. */ mov x8, #__NR_gettimeofday svc #0