* [PATCH] lkdtm: fix ACCESS_USERSPACE test
@ 2015-10-27 20:47 Stephen Smalley
2015-10-27 21:25 ` Kees Cook
2015-10-28 0:12 ` Greg KH
0 siblings, 2 replies; 5+ messages in thread
From: Stephen Smalley @ 2015-10-27 20:47 UTC (permalink / raw)
To: gregkh; +Cc: keescook, linux-kernel, Stephen Smalley
Add a copy_to_user() call to the ACCESS_USERSPACE test
prior to attempting direct dereferencing of the user
address to ensure the page is present. Otherwise,
a fault occurs on arm kernels even prior to the introduction
of CONFIG_CPU_SW_DOMAIN_PAN, and there is no difference in
behavior for CONFIG_CPU_SW_DOMAIN_PAN=n vs CONFIG_CPU_SW_DOMAIN_PAN=y.
Before this change, for any value of CONFIG_CPU_SW_DOMAIN_PAN:
lkdtm: Performing direct entry ACCESS_USERSPACE
lkdtm: attempting bad read at b6fe8000
Unable to handle kernel paging request at virtual address b6fe8000
After this change, for CONFIG_CPU_SW_DOMAIN_PAN=n:
lkdtm: Performing direct entry ACCESS_USERSPACE
lkdtm: attempting bad read at b6efc000
lkdtm: attempting bad write at b6efc000
After this change, for CONFIG_CPU_SW_DOMAIN_PAN=y:
lkdtm: Performing direct entry ACCESS_USERSPACE
lkdtm: attempting bad read at b6f7d000
Unhandled fault: page domain fault (0x01b) at 0xb6f7d000
...
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
---
drivers/misc/lkdtm.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index b5abe34..11fdadc 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -472,7 +472,7 @@ static void lkdtm_do_action(enum ctype which)
break;
}
case CT_ACCESS_USERSPACE: {
- unsigned long user_addr, tmp;
+ unsigned long user_addr, tmp = 0;
unsigned long *ptr;
user_addr = vm_mmap(NULL, 0, PAGE_SIZE,
@@ -483,6 +483,12 @@ static void lkdtm_do_action(enum ctype which)
return;
}
+ if (copy_to_user((void __user *)user_addr, &tmp, sizeof(tmp))) {
+ pr_warn("copy_to_user failed\n");
+ vm_munmap(user_addr, PAGE_SIZE);
+ return;
+ }
+
ptr = (unsigned long *)user_addr;
pr_info("attempting bad read at %p\n", ptr);
--
2.4.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] lkdtm: fix ACCESS_USERSPACE test
2015-10-27 20:47 [PATCH] lkdtm: fix ACCESS_USERSPACE test Stephen Smalley
@ 2015-10-27 21:25 ` Kees Cook
2015-10-28 0:12 ` Greg KH
1 sibling, 0 replies; 5+ messages in thread
From: Kees Cook @ 2015-10-27 21:25 UTC (permalink / raw)
To: Stephen Smalley; +Cc: Greg KH, LKML
On Wed, Oct 28, 2015 at 5:47 AM, Stephen Smalley <sds@tycho.nsa.gov> wrote:
> Add a copy_to_user() call to the ACCESS_USERSPACE test
> prior to attempting direct dereferencing of the user
> address to ensure the page is present. Otherwise,
> a fault occurs on arm kernels even prior to the introduction
> of CONFIG_CPU_SW_DOMAIN_PAN, and there is no difference in
> behavior for CONFIG_CPU_SW_DOMAIN_PAN=n vs CONFIG_CPU_SW_DOMAIN_PAN=y.
>
> Before this change, for any value of CONFIG_CPU_SW_DOMAIN_PAN:
> lkdtm: Performing direct entry ACCESS_USERSPACE
> lkdtm: attempting bad read at b6fe8000
> Unable to handle kernel paging request at virtual address b6fe8000
>
> After this change, for CONFIG_CPU_SW_DOMAIN_PAN=n:
> lkdtm: Performing direct entry ACCESS_USERSPACE
> lkdtm: attempting bad read at b6efc000
> lkdtm: attempting bad write at b6efc000
>
> After this change, for CONFIG_CPU_SW_DOMAIN_PAN=y:
> lkdtm: Performing direct entry ACCESS_USERSPACE
> lkdtm: attempting bad read at b6f7d000
> Unhandled fault: page domain fault (0x01b) at 0xb6f7d000
> ...
>
> Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Great catch! In looking at this test again, I wonder if
ACCESS_USERSPACE should be split so that read and write can be tested
separately...
Acked-by: Kees Cook <keescook@chromium.org>
-Kees
> ---
> drivers/misc/lkdtm.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
> index b5abe34..11fdadc 100644
> --- a/drivers/misc/lkdtm.c
> +++ b/drivers/misc/lkdtm.c
> @@ -472,7 +472,7 @@ static void lkdtm_do_action(enum ctype which)
> break;
> }
> case CT_ACCESS_USERSPACE: {
> - unsigned long user_addr, tmp;
> + unsigned long user_addr, tmp = 0;
> unsigned long *ptr;
>
> user_addr = vm_mmap(NULL, 0, PAGE_SIZE,
> @@ -483,6 +483,12 @@ static void lkdtm_do_action(enum ctype which)
> return;
> }
>
> + if (copy_to_user((void __user *)user_addr, &tmp, sizeof(tmp))) {
> + pr_warn("copy_to_user failed\n");
> + vm_munmap(user_addr, PAGE_SIZE);
> + return;
> + }
> +
> ptr = (unsigned long *)user_addr;
>
> pr_info("attempting bad read at %p\n", ptr);
> --
> 2.4.3
>
--
Kees Cook
Chrome OS Security
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lkdtm: fix ACCESS_USERSPACE test
2015-10-27 20:47 [PATCH] lkdtm: fix ACCESS_USERSPACE test Stephen Smalley
2015-10-27 21:25 ` Kees Cook
@ 2015-10-28 0:12 ` Greg KH
2015-10-29 13:28 ` Stephen Smalley
1 sibling, 1 reply; 5+ messages in thread
From: Greg KH @ 2015-10-28 0:12 UTC (permalink / raw)
To: Stephen Smalley; +Cc: keescook, linux-kernel
On Tue, Oct 27, 2015 at 04:47:53PM -0400, Stephen Smalley wrote:
> Add a copy_to_user() call to the ACCESS_USERSPACE test
> prior to attempting direct dereferencing of the user
> address to ensure the page is present. Otherwise,
> a fault occurs on arm kernels even prior to the introduction
> of CONFIG_CPU_SW_DOMAIN_PAN, and there is no difference in
> behavior for CONFIG_CPU_SW_DOMAIN_PAN=n vs CONFIG_CPU_SW_DOMAIN_PAN=y.
>
> Before this change, for any value of CONFIG_CPU_SW_DOMAIN_PAN:
> lkdtm: Performing direct entry ACCESS_USERSPACE
> lkdtm: attempting bad read at b6fe8000
> Unable to handle kernel paging request at virtual address b6fe8000
>
> After this change, for CONFIG_CPU_SW_DOMAIN_PAN=n:
> lkdtm: Performing direct entry ACCESS_USERSPACE
> lkdtm: attempting bad read at b6efc000
> lkdtm: attempting bad write at b6efc000
>
> After this change, for CONFIG_CPU_SW_DOMAIN_PAN=y:
> lkdtm: Performing direct entry ACCESS_USERSPACE
> lkdtm: attempting bad read at b6f7d000
> Unhandled fault: page domain fault (0x01b) at 0xb6f7d000
> ...
>
> Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
> ---
> drivers/misc/lkdtm.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
Should this also be applied to older kernels (i.e. a stable fix)?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lkdtm: fix ACCESS_USERSPACE test
2015-10-28 0:12 ` Greg KH
@ 2015-10-29 13:28 ` Stephen Smalley
2015-10-30 18:01 ` Kees Cook
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Smalley @ 2015-10-29 13:28 UTC (permalink / raw)
To: Greg KH; +Cc: keescook, linux-kernel
On 10/27/2015 08:12 PM, Greg KH wrote:
> On Tue, Oct 27, 2015 at 04:47:53PM -0400, Stephen Smalley wrote:
>> Add a copy_to_user() call to the ACCESS_USERSPACE test
>> prior to attempting direct dereferencing of the user
>> address to ensure the page is present. Otherwise,
>> a fault occurs on arm kernels even prior to the introduction
>> of CONFIG_CPU_SW_DOMAIN_PAN, and there is no difference in
>> behavior for CONFIG_CPU_SW_DOMAIN_PAN=n vs CONFIG_CPU_SW_DOMAIN_PAN=y.
>>
>> Before this change, for any value of CONFIG_CPU_SW_DOMAIN_PAN:
>> lkdtm: Performing direct entry ACCESS_USERSPACE
>> lkdtm: attempting bad read at b6fe8000
>> Unable to handle kernel paging request at virtual address b6fe8000
>>
>> After this change, for CONFIG_CPU_SW_DOMAIN_PAN=n:
>> lkdtm: Performing direct entry ACCESS_USERSPACE
>> lkdtm: attempting bad read at b6efc000
>> lkdtm: attempting bad write at b6efc000
>>
>> After this change, for CONFIG_CPU_SW_DOMAIN_PAN=y:
>> lkdtm: Performing direct entry ACCESS_USERSPACE
>> lkdtm: attempting bad read at b6f7d000
>> Unhandled fault: page domain fault (0x01b) at 0xb6f7d000
>> ...
>>
>> Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
>> ---
>> drivers/misc/lkdtm.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> Should this also be applied to older kernels (i.e. a stable fix)?
I don't think it qualifies (only a fix for a kernel crash test), but will defer to Kees.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lkdtm: fix ACCESS_USERSPACE test
2015-10-29 13:28 ` Stephen Smalley
@ 2015-10-30 18:01 ` Kees Cook
0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2015-10-30 18:01 UTC (permalink / raw)
To: Stephen Smalley; +Cc: Greg KH, LKML
On Thu, Oct 29, 2015 at 6:28 AM, Stephen Smalley <sds@tycho.nsa.gov> wrote:
> On 10/27/2015 08:12 PM, Greg KH wrote:
>>
>> On Tue, Oct 27, 2015 at 04:47:53PM -0400, Stephen Smalley wrote:
>>>
>>> Add a copy_to_user() call to the ACCESS_USERSPACE test
>>> prior to attempting direct dereferencing of the user
>>> address to ensure the page is present. Otherwise,
>>> a fault occurs on arm kernels even prior to the introduction
>>> of CONFIG_CPU_SW_DOMAIN_PAN, and there is no difference in
>>> behavior for CONFIG_CPU_SW_DOMAIN_PAN=n vs CONFIG_CPU_SW_DOMAIN_PAN=y.
>>>
>>> Before this change, for any value of CONFIG_CPU_SW_DOMAIN_PAN:
>>> lkdtm: Performing direct entry ACCESS_USERSPACE
>>> lkdtm: attempting bad read at b6fe8000
>>> Unable to handle kernel paging request at virtual address b6fe8000
>>>
>>> After this change, for CONFIG_CPU_SW_DOMAIN_PAN=n:
>>> lkdtm: Performing direct entry ACCESS_USERSPACE
>>> lkdtm: attempting bad read at b6efc000
>>> lkdtm: attempting bad write at b6efc000
>>>
>>> After this change, for CONFIG_CPU_SW_DOMAIN_PAN=y:
>>> lkdtm: Performing direct entry ACCESS_USERSPACE
>>> lkdtm: attempting bad read at b6f7d000
>>> Unhandled fault: page domain fault (0x01b) at 0xb6f7d000
>>> ...
>>>
>>> Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
>>> ---
>>> drivers/misc/lkdtm.c | 8 +++++++-
>>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>>
>> Should this also be applied to older kernels (i.e. a stable fix)?
>
>
> I don't think it qualifies (only a fix for a kernel crash test), but will
> defer to Kees.
This emulated PAN support was introduced for v4.3 (a5e090acb), so
there's no meaningful reason to backport the test fix, IMO.
-Kees
--
Kees Cook
Chrome OS Security
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-10-30 18:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-27 20:47 [PATCH] lkdtm: fix ACCESS_USERSPACE test Stephen Smalley
2015-10-27 21:25 ` Kees Cook
2015-10-28 0:12 ` Greg KH
2015-10-29 13:28 ` Stephen Smalley
2015-10-30 18:01 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).