diff --git a/fs/proc/base.c b/fs/proc/base.c
index 6484c0f..09b65d3 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -864,17 +864,22 @@ static const struct file_operations proc_single_file_operations = {
 };
 
 
-struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
+struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode, u64 *ptracer_exec_id)
 {
 	struct task_struct *task = get_proc_task(inode);
 	struct mm_struct *mm = ERR_PTR(-ESRCH);
 
+	if (ptracer_exec_id)
+		*ptracer_exec_id = 0;
+
 	if (task) {
 		mm = mm_access(task, mode | PTRACE_MODE_FSCREDS);
 		if (!IS_ERR_OR_NULL(mm) && gr_acl_handle_procpidmem(task)) {
 			mmput(mm);
 			mm = ERR_PTR(-EPERM);
 		}
+		if (ptracer_exec_id)
+			current_is_ptracer(task, ptracer_exec_id);
 		put_task_struct(task);
 
 		if (!IS_ERR_OR_NULL(mm)) {
@@ -890,7 +895,7 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
 
 static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
 {
-	struct mm_struct *mm = proc_mem_open(inode, mode);
+	struct mm_struct *mm = proc_mem_open(inode, mode, NULL);
 
 	if (IS_ERR(mm))
 		return PTR_ERR(mm);
@@ -923,15 +928,24 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
 	char *page;
 
 #ifdef CONFIG_GRKERNSEC
-	if (write)
+	struct task_struct *task = get_proc_task(file_inode(file));
+	bool is_by_ptracer = false;
+
+	if (task) {
+		is_by_ptracer = current_is_ptracer(task, NULL);
+		put_task_struct(task);
+	}
+
+	if (write && !is_by_ptracer)
 		return -EPERM;
-#endif
+
 #ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
-	if (file->f_version != current->exec_id) {
+	if (file->f_version != current->exec_id && !is_by_ptracer) {
 		gr_log_badprocpid("mem");
 		return 0;
 	}
 #endif
+#endif
 
 	if (!mm)
 		return 0;
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 9f2d3b2..6f98bdd 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -292,9 +292,12 @@ struct proc_maps_private {
 #ifdef CONFIG_NUMA
 	struct mempolicy *task_mempolicy;
 #endif
-};
+#ifdef CONFIG_GRKERNSEC
+	u64 ptracer_exec_id;
+#endif
+} __randomize_layout;
 
-struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode);
+struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode, u64 *ptracer_exec_id);
 
 extern const struct file_operations proc_pid_maps_operations;
 extern const struct file_operations proc_tid_maps_operations;
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 52c3ee0..f6ab73e 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -254,7 +254,7 @@ static int proc_maps_open(struct inode *inode, struct file *file,
 		return -ENOMEM;
 
 	priv->inode = inode;
-	priv->mm = proc_mem_open(inode, PTRACE_MODE_READ);
+	priv->mm = proc_mem_open(inode, PTRACE_MODE_READ, &priv->ptracer_exec_id);
 	if (IS_ERR(priv->mm)) {
 		int err = PTR_ERR(priv->mm);
 
@@ -309,7 +309,7 @@ static int is_stack(struct proc_maps_private *priv,
 }
 
 static void
-show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
+show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid, bool restrict)
 {
 	struct mm_struct *mm = vma->vm_mm;
 	struct file *file = vma->vm_file;
@@ -328,13 +328,8 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
 		pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
 	}
 
-#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
-	start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
-	end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
-#else
-	start = vma->vm_start;
-	end = vma->vm_end;
-#endif
+	start = restrict ? 0UL : vma->vm_start;
+	end = restrict ? 0UL : vma->vm_end;
 
 	seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
 	seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
@@ -344,11 +339,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
 			flags & VM_WRITE ? 'w' : '-',
 			flags & VM_EXEC ? 'x' : '-',
 			flags & VM_MAYSHARE ? 's' : 'p',
-#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
-			PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
-#else
-			pgoff,
-#endif
+			restrict ? 0UL : pgoff,
 			MAJOR(dev), MINOR(dev), ino);
 
 	/*
@@ -394,13 +385,20 @@ done:
 
 static int show_map(struct seq_file *m, void *v, int is_pid)
 {
+	bool restrict = false;
+
 #ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
-	if (current->exec_id != m->exec_id) {
+	struct vm_area_struct *vma = (struct vm_area_struct *)v;
+	struct proc_maps_private *priv = m->private;
+	restrict = current->exec_id != priv->ptracer_exec_id;
+	if (current->exec_id != m->exec_id && restrict) {
 		gr_log_badprocpid("maps");
 		return 0;
 	}
+	if (restrict)
+		restrict = PAX_RAND_FLAGS(vma->vm_mm);
 #endif
-	show_map_vma(m, v, is_pid);
+	show_map_vma(m, v, is_pid, restrict);
 	m_cache_vma(m, v);
 	return 0;
 }
@@ -751,6 +749,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
 		.mm = vma->vm_mm,
 		.private = &mss,
 	};
+	bool restrict = false;
 
 #ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
 	if (current->exec_id != m->exec_id) {
@@ -785,12 +784,14 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
 #endif
 
 #ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
-	if (!PAX_RAND_FLAGS(vma->vm_mm))
+	if (PAX_RAND_FLAGS(vma->vm_mm))
+		restrict = true;
+	else
 #endif
 		/* mmap_sem is held in m_start */
 		walk_page_vma(vma, &smaps_walk);
 
-	show_map_vma(m, vma, is_pid);
+	show_map_vma(m, vma, is_pid, restrict);
 
 	seq_printf(m,
 		   "Size:           %8lu kB\n"
@@ -810,11 +811,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
 		   "KernelPageSize: %8lu kB\n"
 		   "MMUPageSize:    %8lu kB\n"
 		   "Locked:         %8lu kB\n",
-#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
-		   PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
-#else
-		   (vma->vm_end - vma->vm_start) >> 10,
-#endif
+		   restrict ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
 		   mss.resident >> 10,
 		   (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
 		   mss.shared_clean  >> 10,
@@ -1462,7 +1459,7 @@ static int pagemap_open(struct inode *inode, struct file *file)
 {
 	struct mm_struct *mm;
 
-	mm = proc_mem_open(inode, PTRACE_MODE_READ);
+	mm = proc_mem_open(inode, PTRACE_MODE_READ, NULL);
 	if (IS_ERR(mm))
 		return PTR_ERR(mm);
 	file->private_data = mm;
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index ce736cd..ea03024 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -287,7 +287,7 @@ static int maps_open(struct inode *inode, struct file *file,
 		return -ENOMEM;
 
 	priv->inode = inode;
-	priv->mm = proc_mem_open(inode, PTRACE_MODE_READ);
+	priv->mm = proc_mem_open(inode, PTRACE_MODE_READ, &priv->ptracer_exec_id);
 	if (IS_ERR(priv->mm)) {
 		int err = PTR_ERR(priv->mm);
 
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 2d7faf1..3ab8d31 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2416,6 +2416,27 @@ static inline void populate_stack(void *stack)
 }
 #endif
 
+#ifdef CONFIG_GRKERNSEC
+static inline bool current_is_ptracer(struct task_struct *task, u64 *exec_id)
+{
+	bool ret = false;
+        if (!task->ptrace)
+		return ret;
+
+	rcu_read_lock();
+	read_lock(&tasklist_lock);
+	if (task->parent && task->parent == current) {
+		ret = true;
+		if (exec_id)
+			*exec_id = task->parent->exec_id;
+	}
+	read_unlock(&tasklist_lock);
+	rcu_read_unlock();
+
+	return ret;
+}
+#endif
+
 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
 static inline void sched_clock_tick(void)
 {
