All of lore.kernel.org
 help / color / mirror / Atom feed
From: yangyingliang@huawei.com (Yang Yingliang)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 1/4] arm64: vdso: introdce a macro for checking the address
Date: Wed, 1 Jun 2016 11:05:59 +0800	[thread overview]
Message-ID: <1464750362-14188-2-git-send-email-yangyingliang@huawei.com> (raw)
In-Reply-To: <1464750362-14188-1-git-send-email-yangyingliang@huawei.com>

Add a RANGE_OK macro for validation checking of the
address given by user.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 arch/arm64/kernel/asm-offsets.c       |  3 +++
 arch/arm64/kernel/vdso/gettimeofday.S | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index 574081f..b72c2df 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -98,11 +98,14 @@ int main(void)
   BLANK();
   DEFINE(TVAL_TV_SEC,		offsetof(struct timeval, tv_sec));
   DEFINE(TVAL_TV_USEC,		offsetof(struct timeval, tv_usec));
+  DEFINE(TVAL_SZ,		sizeof(struct timeval));
   DEFINE(TSPEC_TV_SEC,		offsetof(struct timespec, tv_sec));
   DEFINE(TSPEC_TV_NSEC,		offsetof(struct timespec, tv_nsec));
+  DEFINE(TSPEC_SZ,		sizeof(struct timespec));
   BLANK();
   DEFINE(TZ_MINWEST,		offsetof(struct timezone, tz_minuteswest));
   DEFINE(TZ_DSTTIME,		offsetof(struct timezone, tz_dsttime));
+  DEFINE(TZ_SZ,			sizeof(struct timezone));
   BLANK();
 #ifdef CONFIG_KVM_ARM_HOST
   DEFINE(VCPU_CONTEXT,		offsetof(struct kvm_vcpu, arch.ctxt));
diff --git a/arch/arm64/kernel/vdso/gettimeofday.S b/arch/arm64/kernel/vdso/gettimeofday.S
index efa79e8..05ccaca 100644
--- a/arch/arm64/kernel/vdso/gettimeofday.S
+++ b/arch/arm64/kernel/vdso/gettimeofday.S
@@ -21,10 +21,31 @@
 #include <linux/linkage.h>
 #include <asm/asm-offsets.h>
 #include <asm/unistd.h>
+#include <asm/memory.h>
 
 #define NSEC_PER_SEC_LO16	0xca00
 #define NSEC_PER_SEC_HI16	0x3b9a
 
+#define USER_DS		TASK_SIZE_64
+/*
+ * Test whether a block of memory is a valid user space address.
+ * Returns 1 if the range is valid, 0 otherwise.
+ *
+ * This is equivalent to the following test:
+ * (u65)addr + (u65)size <= USER_DS
+ *
+ * This needs 65-bit arithmetic.
+ *
+ * x##n - addr
+ * sz - size
+ * x3 - USER_DS
+ * x4 - return value
+ */
+#define RANGE_OK(n, sz)	mov	x3, #USER_DS;		\
+			adds	x4, x##n, sz;		\
+			ccmp	x4, x3, #0x2, cc;	\
+			cset	x4, ls
+
 vdso_data	.req	x6
 use_syscall	.req	w7
 seqcnt		.req	w8
-- 
2.5.0

  reply	other threads:[~2016-06-01  3:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-01  3:05 [RFC PATCH 0/4] arm64: vdso: check whether the params is invalid address Yang Yingliang
2016-06-01  3:05 ` Yang Yingliang [this message]
2016-06-01  3:06 ` [RFC PATCH 2/4] arm64: vdso: check whether the params of gettimeofday() is valid Yang Yingliang
2016-06-01  3:06 ` [RFC PATCH 3/4] arm64: vdso: check whether the tp pointer is valid in clock_gettime() Yang Yingliang
2016-06-01  3:06 ` [RFC PATCH 4/4] arm64: vdso: check whether the res pointer is valid in clock_getres() Yang Yingliang
2016-06-06 17:12 ` [RFC PATCH 0/4] arm64: vdso: check whether the params is invalid address Will Deacon
2016-06-08  9:18   ` Yang Yingliang
2016-06-08  9:33     ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1464750362-14188-2-git-send-email-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.