From patchwork Wed Jun 1 03:06:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 9145959 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 252B560777 for ; Wed, 1 Jun 2016 03:08:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 191C525EF7 for ; Wed, 1 Jun 2016 03:08:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DE962693F; Wed, 1 Jun 2016 03:08:31 +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 13E2025EF7 for ; Wed, 1 Jun 2016 03:08:30 +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 1b7wUx-0007kh-TD; Wed, 01 Jun 2016 03:07:11 +0000 Received: from szxga03-in.huawei.com ([119.145.14.66]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b7wUm-0007cs-VF for linux-arm-kernel@lists.infradead.org; Wed, 01 Jun 2016 03:07:02 +0000 Received: from 172.24.1.60 (EHLO szxeml433-hub.china.huawei.com) ([172.24.1.60]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CCM72025; Wed, 01 Jun 2016 11:06:11 +0800 (CST) Received: from localhost (10.177.19.219) by szxeml433-hub.china.huawei.com (10.82.67.210) with Microsoft SMTP Server id 14.3.235.1; Wed, 1 Jun 2016 11:06:04 +0800 From: Yang Yingliang To: Subject: [RFC PATCH 3/4] arm64: vdso: check whether the tp pointer is valid in clock_gettime() Date: Wed, 1 Jun 2016 11:06:01 +0800 Message-ID: <1464750362-14188-4-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.0A020203.574E5125.00BD, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 7f697c9160a2218801454dc6352b6aa6 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160531_200701_480638_030AD4E5 X-CRM114-Status: GOOD ( 10.05 ) 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 Use RANGE_OK to check whether the tp pointer is valid. Returns -EINVAL if the tp pointer is NULL, returns -EFAULT if it's invalid, otherwise return 0. Signed-off-by: Yang Yingliang --- arch/arm64/kernel/vdso/gettimeofday.S | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kernel/vdso/gettimeofday.S b/arch/arm64/kernel/vdso/gettimeofday.S index 43ec321..1e377ac 100644 --- a/arch/arm64/kernel/vdso/gettimeofday.S +++ b/arch/arm64/kernel/vdso/gettimeofday.S @@ -118,6 +118,9 @@ ENDPROC(__kernel_gettimeofday) /* int __kernel_clock_gettime(clockid_t clock_id, struct timespec *tp); */ ENTRY(__kernel_clock_gettime) .cfi_startproc + cbz x1, 7f + RANGE_OK(1, #TSPEC_SZ) + cbz x4, 8f cmp w0, #CLOCK_REALTIME ccmp w0, #CLOCK_MONOTONIC, #0x4, ne b.ne 2f @@ -128,7 +131,7 @@ ENTRY(__kernel_clock_gettime) /* Get kernel timespec. */ adr vdso_data, _vdso_data 1: seqcnt_acquire - cbnz use_syscall, 7f + cbnz use_syscall, 9f bl __do_get_tspec seqcnt_check w9, 1b @@ -148,7 +151,7 @@ ENTRY(__kernel_clock_gettime) 2: cmp w0, #CLOCK_REALTIME_COARSE ccmp w0, #CLOCK_MONOTONIC_COARSE, #0x4, ne - b.ne 8f + b.ne 10f /* xtime_coarse_nsec is already right-shifted */ mov x12, #0 @@ -192,9 +195,15 @@ ENTRY(__kernel_clock_gettime) stp x10, x11, [x1, #TSPEC_TV_SEC] mov x0, xzr ret -7: +7: /* tp is NULL */ + mov x0, #-EINVAL + ret +8: /* tp is invalid */ + mov x0, #-EFAULT + ret +9: mov x30, x2 -8: /* Syscall fallback. */ +10: /* Syscall fallback. */ mov x8, #__NR_clock_gettime svc #0 ret