Skip to contentSkip to conversation

Yama: handle 32-bit userspace prctl

PATCH In review Kees Cook 3 participants 4 messages Aug 27, 2012 – Sep 7, 2012

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 Yama: handle 32-bit userspace prctl

When running a 64-bit kernel and receiving prctls from a 32-bit userspace, the "-1" used as an unsigned long will end up being misdetected. The kernel is looking for 0xffffffffffffffff instead of 0xffffffff. Since prctl lacks a distinct compat interface, Yama needs to handle this translation itself. As such, support either value as meaning PR_SET_PTRACER_ANY, to avoid breaking the ABI for 64-bit.

---
 security/yama/yama_lsm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
security/yama/yama_lsm.c +1 -1
index 0cc99a3..dcd6178 100644
@@ -143,7 +143,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
 		if (arg2 == 0) {
 			yama_ptracer_del(NULL, myself);
 			rc = 0;
-		} else if (arg2 == PR_SET_PTRACER_ANY) {
+		} else if (arg2 == PR_SET_PTRACER_ANY || (int)arg2 == -1) {
 			rc = yama_ptracer_add(NULL, myself);
 		} else {
 			struct task_struct *tracer;
Signature · 6 lines
1.7.0.4


-- 
Kees Cook
Chrome OS Security
author
#1 lore raw

Hi James,

Any chance this can get into security-next as well? It'll need to go back to stable, but it's a small enough corner-case that I don't mind it not landing in 3.6 directly. I'm happy if it gets into 3.6.x stable at some point.

Thanks!

-Kees

Quoted 33 lines · Kees Cook

When running a 64-bit kernel and receiving prctls from a 32-bit userspace, the "-1" used as an unsigned long will end up being misdetected. The kernel is looking for 0xffffffffffffffff instead of 0xffffffff. Since prctl lacks a distinct compat interface, Yama needs to handle this translation itself. As such, support either value as meaning PR_SET_PTRACER_ANY, to avoid breaking the ABI for 64-bit.

---
 security/yama/yama_lsm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
security/yama/yama_lsm.c +1 -2
index 0cc99a3..dcd6178 100644
@@ -143,7 +143,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
                if (arg2 == 0) {
                        yama_ptracer_del(NULL, myself);
                        rc = 0;
-               } else if (arg2 == PR_SET_PTRACER_ANY) {
+               } else if (arg2 == PR_SET_PTRACER_ANY || (int)arg2 == -1) {
                        rc = yama_ptracer_add(NULL, myself);
                } else {
                        struct task_struct *tracer;
--

1.7.0.4

--
Kees Cook
Chrome OS Security

Signature · 2 lines
Kees Cook
Chrome OS Security
Acked-by on v1 1/1
#2 lore raw
In reply to Kees Cook
Quoted 19 lines · Kees Cook

When running a 64-bit kernel and receiving prctls from a 32-bit userspace, the "-1" used as an unsigned long will end up being misdetected. The kernel is looking for 0xffffffffffffffff instead of 0xffffffff. Since prctl lacks a distinct compat interface, Yama needs to handle this translation itself. As such, support either value as meaning PR_SET_PTRACER_ANY, to avoid breaking the ABI for 64-bit.

---
 security/yama/yama_lsm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
security/yama/yama_lsm.c +0 -0
index 0cc99a3..dcd6178 100644

security/yama/yama_lsm.c static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3, · line 149

Quoted 8 lines
security/yama/yama_lsm.c +1 -1
@@ -143,7 +143,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
 		if (arg2 == 0) {
 			yama_ptracer_del(NULL, myself);
 			rc = 0;
-		} else if (arg2 == PR_SET_PTRACER_ANY) {
+		} else if (arg2 == PR_SET_PTRACER_ANY || (int)arg2 == -1) {
 			rc = yama_ptracer_add(NULL, myself);
 		} else {
 			struct task_struct *tracer;

yeah this looks good it should at least hit stable

maintainer
#3 lore raw
In reply to Kees Cook
Quoted 9 lines · Kees Cook

When running a 64-bit kernel and receiving prctls from a 32-bit userspace, the "-1" used as an unsigned long will end up being misdetected. The kernel is looking for 0xffffffffffffffff instead of 0xffffffff. Since prctl lacks a distinct compat interface, Yama needs to handle this translation itself. As such, support either value as meaning PR_SET_PTRACER_ANY, to avoid breaking the ABI for 64-bit.

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git next