ptrace: kill BKL in ptrace syscall
PATCH 1/1 ptrace: kill BKL in ptrace syscall
From: Arnd Bergmann <[email protected]>
The comment suggests that this usage is stale. There is no bkl in the exec path so if there is a race lurking there, the bkl in ptrace is not going to help in this regard.
Overview of the possibility of "accidental" races this bkl might protect:
- ptrace_traceme() is protected against task removal and concurrent read/write on current->ptrace as it locks write tasklist_lock.
- arch_ptrace_attach() is serialized by ptrace_traceme() against concurrent PTRACE_TRACEME or PTRACE_ATTACH
- ptrace_attach() is protected the same way ptrace_traceme() and in turn serializes arch_ptrace_attach()
- ptrace_check_attach() does its own well described serializing too.
There is no obvious race here.
--- kernel/ptrace.c | 10 ---------- 1 files changed, 0 insertions(+), 10 deletions(-)
kernel/ptrace.c +0 -10
@@ -666,10 +666,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)struct task_struct *child;long ret; -/* -* This lock_kernel fixes a subtle race with suid exec -*/ -lock_kernel ();if (request ==PTRACE_TRACEME ) { ret =ptrace_traceme ();if (!ret)
@@ -703,7 +699,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data) out_put_task_struct:put_task_struct (child); out: -unlock_kernel ();return ret; }
@@ -813,10 +808,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,struct task_struct *child;long ret; -/* -* This lock_kernel fixes a subtle race with suid exec -*/ -lock_kernel ();if (request ==PTRACE_TRACEME ) { ret =ptrace_traceme (); goto out;
@@ -846,7 +837,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, out_put_task_struct:put_task_struct (child); out: -unlock_kernel (); return ret; }#endif /* CONFIG_COMPAT */
Signature · 1 line
1.6.2.3
Quoted 15 lines · Frederic Weisbecker
From: Arnd Bergmann <[email protected]>
The comment suggests that this usage is stale. There is no bkl in the exec path so if there is a race lurking there, the bkl in ptrace is not going to help in this regard.
Overview of the possibility of "accidental" races this bkl might protect:
-
ptrace_traceme()is protected against task removal and concurrent read/write oncurrent->ptraceas it locks writetasklist_lock.-
arch_ptrace_attach()is serialized byptrace_traceme()against concurrentPTRACE_TRACEMEorPTRACE_ATTACH
Quoted 6 lines
-
ptrace_attach()is protected the same wayptrace_traceme()and in turn serializesarch_ptrace_attach()-
ptrace_check_attach()does its own well described serializing too.There is no obvious race here.
And the call to arch_ptrace() doesn't need any pushdown I think, since this is serialized by nature as there is only one "ptracer" for a task.
Quoted 53 lines
Signed-off-by Arnd Bergmann <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>Cc Andrew Morton <[email protected]>--- kernel/ptrace.c | 10 ---------- 1 files changed, 0 insertions(+), 10 deletions(-)kernel/ptrace.c +0
-10@@ -666,10 +666,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)struct task_struct *child;long ret; -/* -* This lock_kernel fixes a subtle race with suid exec -*/ -lock_kernel ();if (request ==PTRACE_TRACEME ) { ret =ptrace_traceme ();if (!ret)@@ -703,7 +699,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data) out_put_task_struct:put_task_struct (child); out: -unlock_kernel ();return ret; }@@ -813,10 +808,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,struct task_struct *child;long ret; -/* -* This lock_kernel fixes a subtle race with suid exec -*/ -lock_kernel ();if (request ==PTRACE_TRACEME ) { ret =ptrace_traceme (); goto out;@@ -846,7 +837,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, out_put_task_struct:put_task_struct (child); out: -unlock_kernel (); return ret; }#endif /* CONFIG_COMPAT */ Signature · 1 line
1.6.2.3
Quoted 6 lines · Frederic Weisbecker
From: Arnd Bergmann <[email protected]>
The comment suggests that this usage is stale. There is no bkl in the exec path so if there is a race lurking there, the bkl in ptrace is not going to help in this regard.
I never understood this comment too, and I do not see any potentional races bkl could prevent.
Quoted 9 lines
Overview of the possibility of "accidental" races this bkl might protect:
-
ptrace_traceme()is protected against task removal and concurrent read/write oncurrent->ptraceas it locks writetasklist_lock.-
arch_ptrace_attach()is serialized byptrace_traceme()against concurrentPTRACE_TRACEMEorPTRACE_ATTACH
Quoted 6 lines
-
ptrace_attach()is protected the same wayptrace_traceme()and in turn serializesarch_ptrace_attach()-
ptrace_check_attach()does its own well described serializing too.There is no obvious race here.
Yes, nothing inside sys_ptrace() pathes relies on bkl, and all recent changes were done assuming that lock_kernel() doesn't exist.
I think the patch is correct.
Quoted 52 lines
Signed-off-by Arnd Bergmann <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>Cc Andrew Morton <[email protected]>--- kernel/ptrace.c | 10 ---------- 1 files changed, 0 insertions(+), 10 deletions(-)kernel/ptrace.c +0
-11@@ -666,10 +666,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)struct task_struct *child;long ret; -/* -* This lock_kernel fixes a subtle race with suid exec -*/ -lock_kernel ();if (request ==PTRACE_TRACEME ) { ret =ptrace_traceme ();if (!ret)@@ -703,7 +699,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data) out_put_task_struct:put_task_struct (child); out: -unlock_kernel ();return ret; }@@ -813,10 +808,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,struct task_struct *child;long ret; -/* -* This lock_kernel fixes a subtle race with suid exec -*/ -lock_kernel ();if (request ==PTRACE_TRACEME ) { ret =ptrace_traceme (); goto out;@@ -846,7 +837,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, out_put_task_struct:put_task_struct (child); out: -unlock_kernel (); return ret; }#endif /* CONFIG_COMPAT */ --1.6.2.3
Quoted 78 lines · Oleg Nesterov
Quoted 6 lines · Frederic Weisbecker
From: Arnd Bergmann <[email protected]>
The comment suggests that this usage is stale. There is no bkl in the exec path so if there is a race lurking there, the bkl in ptrace is not going to help in this regard.
I never understood this comment too, and I do not see any potentional races bkl could prevent.
Quoted 9 lines
Overview of the possibility of "accidental" races this bkl might protect:
-
ptrace_traceme()is protected against task removal and concurrent read/write oncurrent->ptraceas it locks writetasklist_lock.-
arch_ptrace_attach()is serialized byptrace_traceme()against concurrentPTRACE_TRACEMEorPTRACE_ATTACHQuoted 6 lines
-
ptrace_attach()is protected the same wayptrace_traceme()and in turn serializesarch_ptrace_attach()-
ptrace_check_attach()does its own well described serializing too.There is no obvious race here.
Yes, nothing inside
sys_ptrace()pathes relies on bkl, and all recent changes were done assuming thatlock_kernel()doesn't exist.I think the patch is correct.
Acked-by Oleg Nesterov <[email protected]>Quoted 44 lines
Signed-off-by Arnd Bergmann <[email protected]>Signed-off-by Frederic Weisbecker <[email protected]>Cc Andrew Morton <[email protected]>---
kernel/ptrace.c | 10 ----------1 files changed, 0 insertions(+), 10 deletions(-)kernel/ptrace.c +0
-4@@ -666,10 +666,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data) struct task_struct *child; long ret; - /* - * This lock_kernel fixes a subtle race with suid exec - */ - lock_kernel(); if (request == PTRACE_TRACEME) { ret = ptrace_traceme(); if (!ret)@@ -703,7 +699,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
out_put_task_struct:
put_task_struct(child);
out:
-unlock_kernel();
return ret;
}kernel/ptrace.c +0
-4@@ -813,10 +808,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, struct task_struct *child; long ret; - /* - * This lock_kernel fixes a subtle race with suid exec - */ - lock_kernel(); if (request == PTRACE_TRACEME) { ret = ptrace_traceme(); goto out;@@ -846,7 +837,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
out_put_task_struct:
put_task_struct(child);
Quoted 8 lines
Quoted 8 lines
out:
-unlock_kernel();
return ret;
}
#endif /*CONFIG_COMPAT*/
--
1.6.2.3
So, just to be clear about this particular patch, who is queuing it up to send to Linus? Would that be you Oleg, as a ptrace maintainer?
Thanks
Oleg Nesterov
maintainerQuoted 3 lines · John Kacur
So, just to be clear about this particular patch, who is queuing it up to send to Linus? Would that be you Oleg, as a ptrace maintainer?
Cough. I must admit, apart from "urgent" bugfixes the only way I know is to send the patch to Andrew.
So I'd suggest to send this patch to akpm. Of course, if you wish I can forward it, but doesn't matter.
Oleg.
Quoted 5 lines · Oleg Nesterov
Quoted 3 lines · John Kacur
So, just to be clear about this particular patch, who is queuing it up to send to Linus? Would that be you Oleg, as a ptrace maintainer?
Quoted 8 lines
Cough. I must admit, apart from "urgent" bugfixes the only way I know is to send the patch to Andrew.
So I'd suggest to send this patch to akpm. Of course, if you wish I can forward it, but doesn't matter.
Oleg.
I know that in the past, Thomas was keeping a BKL tree in tip, but not sure if he is still doing so. It seems that Arnd's tree is at least partially experimental,
so I wonder if we need to maintain another BKL tree somewhere of fixes that have no
obvious maintainer, but are ready to send to Linus for inclusion?
For fixes that have obvious maintainers though, I would just rather go through the normal route.
John
Quoted 15 lines · John Kacur
Quoted 5 lines · Oleg Nesterov
Quoted 3 lines · John Kacur
So, just to be clear about this particular patch, who is queuing it up to send to Linus? Would that be you Oleg, as a ptrace maintainer?
Quoted 8 lines
Cough. I must admit, apart from "urgent" bugfixes the only way I know is to send the patch to Andrew.
So I'd suggest to send this patch to akpm. Of course, if you wish I can forward it, but doesn't matter.
Oleg.
Quoted 6 lines
I know that in the past, Thomas was keeping a BKL tree in tip, but not sure if he is still doing so. It seems that Arnd's tree is at least partially experimental,
so I wonder if we need to maintain another BKL tree somewhere of fixes that have no
obvious maintainer, but are ready to send to Linus for inclusion?
I have cc'ed Andrew for this patch, partly for that purpose, so that he can take it if he wants to.
But in the worst case these patches are never lost. We don't want to lose them. For those that can't go in someone else .35 targeted tree for any reason, I can queue them up in mine in a dedicated branch that I'll propose to Linus.
Quoted 3 lines
For fixes that have obvious maintainers though, I would just rather go through the normal route.
Exactly, as far as there is an active maintainer in the area concerned by a random kill-bkl patch, I much prefer this patch goes to this maintainer. It gives a much better passport for this patch, and it avoids possible future conflicts in this area of code, less work for Stephen :)
Oleg Nesterov
maintainerQuoted 18 lines · Frederic Weisbecker
Quoted 8 lines · John Kacur
Quoted 7 lines · Oleg Nesterov
Cough. I must admit, apart from "urgent" bugfixes the only way I know is to send the patch to Andrew.
So I'd suggest to send this patch to akpm. Of course, if you wish I can forward it, but doesn't matter.
Quoted 6 lines
I know that in the past, Thomas was keeping a BKL tree in tip, but not sure if he is still doing so. It seems that Arnd's tree is at least partially experimental,
so I wonder if we need to maintain another BKL tree somewhere of fixes that have no
obvious maintainer, but are ready to send to Linus for inclusion?
Quoted 2 lines
I have cc'ed Andrew for this patch, partly for that purpose, so that he can take it if he wants to.
Ah, good, I didn't notice.
If he doesn't pick this patch now, I'll forward it to him later again ;)
Quoted 3 lines
But in the worst case these patches are never lost. We don't want to lose them. For those that can't go in someone else .35 targeted tree for any reason, I can queue them up in mine in a dedicated branch that I'll propose to Linus.
Frederic, whatever is more convenient to you.
Oleg.
Quoted 24 lines · Oleg Nesterov
Quoted 18 lines · Frederic Weisbecker
Quoted 8 lines · John Kacur
Quoted 7 lines · Oleg Nesterov
Cough. I must admit, apart from "urgent" bugfixes the only way I know is to send the patch to Andrew.
So I'd suggest to send this patch to akpm. Of course, if you wish I can forward it, but doesn't matter.
Quoted 6 lines
I know that in the past, Thomas was keeping a BKL tree in tip, but not sure if he is still doing so. It seems that Arnd's tree is at least partially experimental,
so I wonder if we need to maintain another BKL tree somewhere of fixes that have no
obvious maintainer, but are ready to send to Linus for inclusion?Quoted 2 lines
I have cc'ed Andrew for this patch, partly for that purpose, so that he can take it if he wants to.
Ah, good, I didn't notice.
Quoted 7 lines
If he doesn't pick this patch now, I'll forward it to him later again ;)
Quoted 3 lines
But in the worst case these patches are never lost. We don't want to lose them. For those that can't go in someone else .35 targeted tree for any reason, I can queue them up in mine in a dedicated branch that I'll propose to Linus.
Frederic, whatever is more convenient to you.
I just keep it somewhere and if it's not queued in one week or so, I'll put it in my tree :-)
Thanks.
Quoted 26 lines · Oleg Nesterov
Quoted 18 lines · Frederic Weisbecker
Quoted 8 lines · John Kacur
Quoted 7 lines · Oleg Nesterov
Cough. I must admit, apart from "urgent" bugfixes the only way I know is to send the patch to Andrew.
So I'd suggest to send this patch to akpm. Of course, if you wish I can forward it, but doesn't matter.
Quoted 6 lines
I know that in the past, Thomas was keeping a BKL tree in tip, but not sure if he is still doing so. It seems that Arnd's tree is at least partially experimental,
so I wonder if we need to maintain another BKL tree somewhere of fixes that have no
obvious maintainer, but are ready to send to Linus for inclusion?Quoted 2 lines
I have cc'ed Andrew for this patch, partly for that purpose, so that he can take it if he wants to.
Ah, good, I didn't notice.
If he doesn't pick this patch now, I'll forward it to him later again ;)
Quoted 8 lines
Quoted 3 lines
But in the worst case these patches are never lost. We don't want to lose them. For those that can't go in someone else .35 targeted tree for any reason, I can queue them up in mine in a dedicated branch that I'll propose to Linus.
Frederic, whatever is more convenient to you.
Oleg.
I have applied it to:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
bkl/core
Thanks.
Quoted 33 lines · On Thu, 1 Apr 2010 20:48:58 +0200 Frederic Weisbecker <[email protected]>…
Quoted 32 lines · Oleg Nesterov
Quoted 18 lines · Frederic Weisbecker
Quoted 8 lines · John Kacur
Quoted 7 lines · Oleg Nesterov
Cough. I must admit, apart from "urgent" bugfixes the only way I know is to send the patch to Andrew.
So I'd suggest to send this patch to akpm. Of course, if you wish I can forward it, but doesn't matter.
Quoted 6 lines
I know that in the past, Thomas was keeping a BKL tree in tip, but not sure if he is still doing so. It seems that Arnd's tree is at least partially experimental,
so I wonder if we need to maintain another BKL tree somewhere of fixes that have no
obvious maintainer, but are ready to send to Linus for inclusion?Quoted 2 lines
I have cc'ed Andrew for this patch, partly for that purpose, so that he can take it if he wants to.
Ah, good, I didn't notice.
If he doesn't pick this patch now, I'll forward it to him later again ;)
Quoted 3 lines
But in the worst case these patches are never lost. We don't want to lose them. For those that can't go in someone else .35 targeted tree for any reason, I can queue them up in mine in a dedicated branch that I'll propose to Linus.
Frederic, whatever is more convenient to you.
Quoted 9 lines
Quoted 2 lines
Oleg.
I have applied it to:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
bkl/core
It hasn't turned up in linux-next yet?
Quoted 40 lines · Andrew Morton
Quoted 37 lines · On Thu, 1 Apr 2010 20:48:58 +0200 Frederic Weisbecker <[email protected]>…
Quoted 34 lines · Oleg Nesterov
Quoted 18 lines · Frederic Weisbecker
Quoted 8 lines · John Kacur
Quoted 7 lines · Oleg Nesterov
Cough. I must admit, apart from "urgent" bugfixes the only way I know is to send the patch to Andrew.
So I'd suggest to send this patch to akpm. Of course, if you wish I can forward it, but doesn't matter.
Quoted 6 lines
I know that in the past, Thomas was keeping a BKL tree in tip, but not sure if he is still doing so. It seems that Arnd's tree is at least partially experimental,
so I wonder if we need to maintain another BKL tree somewhere of fixes that have no
obvious maintainer, but are ready to send to Linus for inclusion?Quoted 2 lines
I have cc'ed Andrew for this patch, partly for that purpose, so that he can take it if he wants to.
Ah, good, I didn't notice.
If he doesn't pick this patch now, I'll forward it to him later again ;)
Quoted 3 lines
But in the worst case these patches are never lost. We don't want to lose them. For those that can't go in someone else .35 targeted tree for any reason, I can queue them up in mine in a dedicated branch that I'll propose to Linus.
Frederic, whatever is more convenient to you.
Oleg.
Quoted 7 lines
Quoted 5 lines
I have applied it to:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
bkl/coreIt hasn't turned up in linux-next yet?
I've asked Stephen two days ago:
http://lkml.org/lkml/2010/4/10/42
I guess this is going to show up in -next soon.
Hi Andrew,
Quoted 9 lines · On Mon, 12 Apr 2010 13:29:10 -0700 Andrew Morton <[email protected]>…
Quoted 5 lines · On Thu, 1 Apr 2010 20:48:58 +0200 Frederic Weisbecker <[email protected]>…
I have applied it to:
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
bkl/coreIt hasn't turned up in linux-next yet?
It will be there from today (assuming no problems).
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Roland McGrath
Acked-byThanks,
Roland