Skip to contentSkip to conversation

self introduction

kernel-hardening Colin Vidal 8 participants 25 messages Oct 9, 2016 – Oct 18, 2016

lore
Share & tools
lore
#0 lore raw

Hi all,

My name is Colin Vidal. I am currently a PhD student in computer science. My researches  consist on building a dedicated specific language on top of JavaScript in order to handle asynchronous events in a synchronous style. Hence, with a direct relation between the control flow and the instruction flow.

Beside my researches, I am taking up the Eudyptula Challenge (task 15 submitted). It helps me to have a global view of the kernel (organization, tree, some features), but it is not enough to get involved in serious development. Therefore, I am looking for task I can accomplish to be involved into real kernel development!

I still don't have yet a narrow idea about where I can begin. I like though the idea of kernel self protection. For instance, I find the VM- mapped stack to be really interesting, but I think it is an overkill as a beginning, and a lot of work have already been done on it. On the architecture point-of-view, I have a preference of x86 since I only have this hardware for now, but I can work on ARM and others with QEMU too.

Thanks,

Colin

#1 lore raw

Hi Colin,

If you're interested, the HARDENED_ATOMIC team is looking for people to help porting the feature to other architectures. ARM is a reasonable candidate for someone new to the project. I have begun this effort myself, but if you'd like to collaborate I'd be grateful.

It essentially involves porting the original arch-specific features from PAX_REFCOUNT into Elena Reshetova's official HARDENED_ATOMIC tree, which can be found at https://github.com/esreshetova/linux-stable

Please contact me if you have any questions; I'd be glad to help!

Thanks,
David

Quoted 27 lines · Colin Vidal

Hi all,

My name is Colin Vidal. I am currently a PhD student in computer science. My researches consist on building a dedicated specific language on top of JavaScript in order to handle asynchronous events in a synchronous style. Hence, with a direct relation between the control flow and the instruction flow.

Beside my researches, I am taking up the Eudyptula Challenge (task 15 submitted). It helps me to have a global view of the kernel (organization, tree, some features), but it is not enough to get involved in serious development. Therefore, I am looking for task I can accomplish to be involved into real kernel development!

I still don't have yet a narrow idea about where I can begin. I like though the idea of kernel self protection. For instance, I find the VM- mapped stack to be really interesting, but I think it is an overkill as a beginning, and a lot of work have already been done on it. On the architecture point-of-view, I have a preference of x86 since I only have this hardware for now, but I can work on ARM and others with QEMU too.

Thanks,

Colin

#2 lore raw

Hi David,

Quoted 5 lines

If you're interested, the HARDENED_ATOMIC team is looking for people to help porting the feature to other architectures.  ARM is a reasonable candidate for someone new to the project.  I have begun this effort myself, but if you'd like to collaborate I'd be grateful.

Sounds good!

Quoted 4 lines

It essentially involves porting the original arch-specific features from PAX_REFCOUNT into Elena Reshetova's official HARDENED_ATOMIC tree, which can be found at
https://github.com/esreshetova/linux-stable

The link seems broken (https://github.com/esreshetova too). I found
https://github.com/dwindsor/hardened-atomic but it is empty. Did I miss something/Github filter?

Quoted 1 line

Please contact me if you have any questions; I'd be glad to help!

I actually have question. :-) As far as I understand, PAX_REFCOUNT [1] is mainly a x86-only port from PaX project in order to avoid overflow on atomic_t variable (and avoid use-after-free exploits). I am a little bit confused about the Elena patch-set HARDENED_ATOMIC [2]. It is a more mature/recent version of the port, isn't it ?

Thanks!

Colin

[1] https://lwn.net/Articles/668724/
[2] https://lwn.net/Articles/702640/

#3 lore raw
Quoted 10 lines · Colin Vidal

Hi David,

Quoted 5 lines

If you're interested, the HARDENED_ATOMIC team is looking for people to help porting the feature to other architectures.  ARM is a reasonable candidate for someone new to the project.  I have begun this effort myself, but if you'd like to collaborate I'd be grateful.

Sounds good!

Quoted 8 lines
Quoted 4 lines

It essentially involves porting the original arch-specific features from PAX_REFCOUNT into Elena Reshetova's official HARDENED_ATOMIC tree, which can be found at
https://github.com/esreshetova/linux-stable

The link seems broken (https://github.com/esreshetova too). I found
https://github.com/dwindsor/hardened-atomic but it is empty. Did I miss something/Github filter?

Typo in the link, I think?
https://github.com/ereshetova/linux-stable

Quoted 4 lines
Quoted 1 line

Please contact me if you have any questions; I'd be glad to help!

I actually have question. :-) As far as I understand, PAX_REFCOUNT [1] is mainly a x86-only

No, PAX_REFCOUNT also supports a bunch of other architectures. As far as I can tell from a quick look: ARM, MIPS, PowerPC and SPARC.

Quoted 1 line

port from PaX project

It is part of the PaX patch.

Quoted 2 lines

in order to avoid overflow
on atomic_t variable (and avoid use-after-free exploits)

Yes - overflow (beyond INT_MAX) and underflow (beyond INT_MIN).

. I am a

Quoted 2 lines

little bit confused about the Elena patch-set HARDENED_ATOMIC [2]. It is a more mature/recent version of the port, isn't it ?

HARDENED_ATOMIC is a patch based on PAX_REFCOUNT that is developed with the intent to merge it into the upstream kernel.

#4 lore raw
Quoted 15 lines · Colin Vidal

Hi David,

Quoted 5 lines

If you're interested, the HARDENED_ATOMIC team is looking for people to help porting the feature to other architectures.  ARM is a reasonable candidate for someone new to the project.  I have begun this effort myself, but if you'd like to collaborate I'd be grateful.

Sounds good!

Quoted 4 lines

It essentially involves porting the original arch-specific features from PAX_REFCOUNT into Elena Reshetova's official HARDENED_ATOMIC tree, which can be found at
https://github.com/esreshetova/linux-stable

Quoted 6 lines

The link seems broken (https://github.com/esreshetova too). I found
https://github.com/dwindsor/hardened-atomic but it is empty. Did I miss something/Github filter?

Typo in the link, I think?
https://github.com/ereshetova/linux-stable

This branch to be precise:
https://github.com/ereshetova/linux-stable/tree/hardened_atomic_on_next

This is where the latest code for linux-next is hosted now and where we work with David and Hans.

Quoted 6 lines
Quoted 1 line

Please contact me if you have any questions; I'd be glad to help!

I actually have question. :-) As far as I understand, PAX_REFCOUNT [1] is mainly a x86-only

No, PAX_REFCOUNT also supports a bunch of other architectures. As far as I can tell from a quick look: ARM, MIPS, PowerPC and SPARC.

Yes, just in our patch series we only made implementation for x86. But if you look into Grsecurity/PaX patches, it has support for others implemented.

#5 lore raw
Quoted 13 lines

This branch to be precise:
https://github.com/ereshetova/linux-stable/tree/hardened_atomic_on_next

This is where the latest code for linux-next is hosted now and where we work with David and Hans.

Quoted 8 lines

Quoted 2 lines


Please contact me if you have any questions; I'd be glad to help!


I actually have question. :-) As far as I understand, PAX_REFCOUNT
[1] is mainly a x86-only

Quoted 6 lines
Quoted 2 lines

No, PAX_REFCOUNT also supports a bunch of other architectures. As far as I can tell from a quick look: ARM, MIPS, PowerPC and SPARC.


Yes, just in our patch series we only made implementation for x86. But if you look into Grsecurity/PaX patches, it has support for others implemented.

OK, got it! Thanks for this clarification.

So, I will try to start to port PAX_REFCOUNT arm-specific features to hardened_atomic_on_next, and keep you in touch. Is there a deadline? (4.10 / 5.0 merge window?)

Just to be sure, the patch [1] and documentation [2] of PaX are still up-to-date, or there is another references I missed?

Thanks

Colin

[1] https://pax.grsecurity.net/pax-linux-3.6-201210022100.patch
[2] https://forums.grsecurity.net/viewtopic.php?f=7&t=4173

#6 lore raw
Quoted 8 lines

Yes, just in our patch series we only made implementation for x86. But if you look into Grsecurity/PaX patches, it has support for others implemented.

OK, got it! Thanks for this clarification.

So, I will try to start to port PAX_REFCOUNT arm-specific features to hardened_atomic_on_next, and keep you in touch. Is there a deadline? (4.10 / 5.0 merge window?)

I don't think we have any particular deadline in mind: getting it in the upstream and making it behaving correctly is more of a priority.

Quoted 1 line

Just to be sure, the patch [1] and documentation [2] of PaX are still up-to-date, or there is another references I missed?

I don't think there are any other significant references. Where we functionaly deviate from PaX/Grsecurity, we documented it in commit messages (so far only on percpu refcount thing) .

Best Regards,
Elena.

#7 lore raw
In reply to Colin Vidal
Quoted 20 lines · Colin Vidal
Quoted 13 lines

This branch to be precise:
https://github.com/ereshetova/linux-stable/tree/hardened_atomic_on_next

This is where the latest code for linux-next is hosted now and where we work with David and Hans.

Quoted 8 lines
Quoted 3 lines

Please contact me if you have any questions; I'd be glad to help!

I actually have question. :-) As far as I understand, PAX_REFCOUNT
[1] is mainly a x86-only

Quoted 6 lines
Quoted 2 lines

No, PAX_REFCOUNT also supports a bunch of other architectures. As far as I can tell from a quick look: ARM, MIPS, PowerPC and SPARC.

Yes, just in our patch series we only made implementation for x86. But if you look into Grsecurity/PaX patches, it has support for others implemented.

Quoted 5 lines

OK, got it! Thanks for this clarification.

So, I will try to start to port PAX_REFCOUNT arm-specific features to hardened_atomic_on_next, and keep you in touch. Is there a deadline? (4.10 / 5.0 merge window?)

You may want to compare notes with Takahiro (CCed) who may have started to look at arm64 (and maybe arm too).

As for a deadline, as Elena says, we have no specific target. ("As soon as possible.") The only thing around timing that I like to see is persistent progress: if a patch series goes up for review, getting people to take a look at it, ask questions, make comments, and then hopefully within a week or so, the next version comes up. Momentum is easier to maintain than to build. ;)

Quoted 8 lines

Just to be sure, the patch [1] and documentation [2] of PaX are still up-to-date, or there is another references I missed?

Thanks

Colin

[1] https://pax.grsecurity.net/pax-linux-3.6-201210022100.patch

This is a quite old version of PaX. (Note the date.) If you want to examine PaX separately from Grsecurity (noting differences can be enlightening), check here:

https://www.grsecurity.net/~paxguy1/?C=M;O=D

Quoted 1 line

[2] https://forums.grsecurity.net/viewtopic.php?f=7&t=4173

Yes, outside of reading the code itself, I believe this to be the most comprehensive piece of documentation about PAX_REFCOUNT.

-Kees

Signature · 2 lines
Kees Cook
Nexus Security
#8 lore raw

Hi all,

My name is Jiayy (@chengjia4574 <https://twitter.com/chengjia4574>). I am currently a security researcher in
android and linux kernel. My researches consist on hunting vulnerabilities in kernel code (most of them within drivers) and doing exploits using those vulns.
I had found more than 40 vulnerabilities
<http://www.linkedin.com/in/chen-gengjia-a4411855?trk=nav_responsive_tab_profile>
which were confirmed by Android Security Team
in the past year. I also figured out some way to attack mitigation solutions of kernel
(such as Bypass PXN <http://en.mosec.org/#speech_bg>).

Those works help me get familiar with the kernel(device tree, memory management,
network , some features especially those associated with security such as pxn, selinux, seccomp) and ARM instruction. However, it is not enough to get
involved in real security development in kernel. Therefore, I am looking for task
I can accomplish to be involved into real kernel development! Recently I found
this project (kernel self protection) and I thought it is so interesting.

I don't know whether I can involve and where I can begin, I am looking forward to
your response.

Thanks,

Jiayy

2016-10-11 5:05 GMT+08:00 Kees Cook <[email protected]>:

Quoted 63 lines · Colin Vidal
Quoted 20 lines
Quoted 13 lines

This branch to be precise:
https://github.com/ereshetova/linux-stable/tree/hardened_atomic_on_next

This is where the latest code for linux-next is hosted now and where we work with David and Hans.

Quoted 8 lines
Quoted 3 lines

Please contact me if you have any questions; I'd be glad to help!

I actually have question. :-) As far as I understand, PAX_REFCOUNT
[1] is mainly a x86-only

Quoted 6 lines
Quoted 2 lines

No, PAX_REFCOUNT also supports a bunch of other architectures. As far as I can tell from a quick look: ARM, MIPS, PowerPC and SPARC.

Yes, just in our patch series we only made implementation for x86. But if you look into Grsecurity/PaX patches, it has support for others implemented.

Quoted 5 lines

OK, got it! Thanks for this clarification.

So, I will try to start to port PAX_REFCOUNT arm-specific features to hardened_atomic_on_next, and keep you in touch. Is there a deadline? (4.10 / 5.0 merge window?)

You may want to compare notes with Takahiro (CCed) who may have started to look at arm64 (and maybe arm too).

As for a deadline, as Elena says, we have no specific target. ("As soon as possible.") The only thing around timing that I like to see is persistent progress: if a patch series goes up for review, getting people to take a look at it, ask questions, make comments, and then hopefully within a week or so, the next version comes up. Momentum is easier to maintain than to build. ;)

Quoted 8 lines

Just to be sure, the patch [1] and documentation [2] of PaX are still up-to-date, or there is another references I missed?

Thanks

Colin

[1] https://pax.grsecurity.net/pax-linux-3.6-201210022100.patch

This is a quite old version of PaX. (Note the date.) If you want to examine PaX separately from Grsecurity (noting differences can be enlightening), check here:

https://www.grsecurity.net/~paxguy1/?C=M;O=D

Quoted 1 line

[2] https://forums.grsecurity.net/viewtopic.php?f=7&t=4173

Yes, outside of reading the code itself, I believe this to be the most comprehensive piece of documentation about PAX_REFCOUNT.

-Kees

--
Kees Cook
Nexus Security

#9 lore raw
Quoted 1 line · Gengjia Chen

Hi all,

Hi, welcome!

Quoted 9 lines

My name is Jiayy (@chengjia4574). I am currently a security researcher in android and linux kernel. My researches consist on hunting vulnerabilities in kernel code (most of them within drivers) and doing exploits using those vulns.
I had found more than 40 vulnerabilities which were confirmed by Android Security Team
in the past year. I also figured out some way to attack mitigation solutions of kernel
(such as Bypass PXN).

In your research have you seen a common kind of bug that results in the vulnerabilities you find? Is there anything that would have significantly made exploitation more difficult in the things you worked on?

Quoted 10 lines

Those works help me get familiar with the kernel(device tree, memory management,
network , some features especially those associated with security such as pxn, selinux, seccomp) and ARM instruction. However, it is not enough to get involved in real security development in kernel. Therefore, I am looking for task
I can accomplish to be involved into real kernel development! Recently I found
this project (kernel self protection) and I thought it is so interesting.

Quoted 3 lines

I don't know whether I can involve and where I can begin, I am looking forward to
your response.

Are you interested mostly in ARM-specific things? Are you interested in kernel-assisted userspace defenses too?

-Kees

Signature · 2 lines
Kees Cook
Nexus Security
#10 lore raw
Quoted 2 lines

In your research have you seen a common kind of bug that results in the vulnerabilities you find?

No,
Most of those issues are caused by the lack of checking of user input length
in copy_xx_user functions or afterwards in memcpy functions, however, looking into the details,
they vary among different functions in different files.

Quoted 3 lines

Is there anything that would have
significantly made exploitation more difficult in the things you worked on?

Yes!

I mostly exploit buffer overflow vulns by overwrite function pointers (such as
pointers in file_operations) of a global object or a heap object to redirect execution (and if PXN is enable, we simply use rop gadgets). Therefore mitigation solutions of Function_pointer_overwrite
<https://kernsec.org/wiki/index.php/Exploit_Methods/Function_pointer_overwrite>
would
make such kind of exploitation much more diffcult.
But I don't know if you have let all the pointers "const".

Becsides, ret2dir is a common way to exploit UAF vulns so I think solutions like XPFO is a way to make those kind of exploitation more diffcult.

Right now KALSR is still disable in most android devices, so it is easy to get kernel symbol address,
however if KALSR is enable, it may make exploitation more diffcult.

Quoted 1 line

Are you interested mostly in ARM-specific things?

I am famillar with ARM-specific things mostly, but I can also accept x86/x64 tasks.

Quoted 1 line

Are you interested in kernel-assisted userspace defenses too?

What dose that mean ? something like seccomp ?

2016-10-13 6:31 GMT+08:00 Kees Cook <[email protected]>:

Quoted 49 lines
Quoted 1 line · Gengjia Chen

Hi all,

Hi, welcome!

Quoted 2 lines

My name is Jiayy (@chengjia4574). I am currently a security researcher in android and linux kernel. My researches consist on hunting

vulnerabilities

Quoted 1 line

in kernel code (most of them within drivers) and doing exploits using

those

Quoted 4 lines

vulns.
I had found more than 40 vulnerabilities which were confirmed by Android Security Team
in the past year. I also figured out some way to attack mitigation

solutions

Quoted 2 lines

of kernel
(such as Bypass PXN).

In your research have you seen a common kind of bug that results in the vulnerabilities you find? Is there anything that would have significantly made exploitation more difficult in the things you worked on?

Quoted 4 lines

Those works help me get familiar with the kernel(device tree, memory management,
network , some features especially those associated with security such as pxn, selinux, seccomp) and ARM instruction. However, it is not enough to

get

Quoted 1 line

involved in real security development in kernel. Therefore, I am looking

for

Quoted 8 lines

task
I can accomplish to be involved into real kernel development! Recently I found
this project (kernel self protection) and I thought it is so interesting.

I don't know whether I can involve and where I can begin, I am looking forward to
your response.

Are you interested mostly in ARM-specific things? Are you interested in kernel-assisted userspace defenses too?

-Kees

--
Kees Cook
Nexus Security

#11 lore raw
Quoted 9 lines · Gengjia Chen
Quoted 2 lines

In your research have you seen a common kind of bug that results in the vulnerabilities you find?

No,
Most of those issues are caused by the lack of checking of user input length
in copy_xx_user functions or afterwards in memcpy functions, however, looking into the details,
they vary among different functions in different files.

Cool, I hope the recent hardened usercopy stuff will improve that situation, though there is plenty left to do.

Quoted 6 lines
Quoted 3 lines

Is there anything that would have
significantly made exploitation more difficult in the things you worked on?

Yes!

Quoted 7 lines

I mostly exploit buffer overflow vulns by overwrite function pointers (such as
pointers in file_operations) of a global object or a heap object to redirect execution (and if PXN is enable, we simply use rop gadgets). Therefore mitigation solutions of Function_pointer_overwrite would make such kind of exploitation much more diffcult.
But I don't know if you have let all the pointers "const".

Creating a mechanism like PaX's pax_open_kernel()/pax_close_kernel() combined with the constify plugin would vastly improve the function tables that could be const in the kernel. Perhaps that's something you could look at: porting the pax_open_kernel()/pax_close_kernel() infrastructure on ARM to upstream?

Quoted 3 lines

Becsides, ret2dir is a common way to exploit UAF vulns so I think solutions like XPFO is a way to make those kind of exploitation more diffcult.

That's also good to hear. XPFO is making some progress; I'm looking forward to it's next patch version (though IIUC, we'll need arch-specific support for it on ARM -- the current patches are x86 only).

Quoted 3 lines

Right now KALSR is still disable in most android devices, so it is easy to get kernel symbol address,
however if KALSR is enable, it may make exploitation more diffcult.

Eliminating the various address exposures for KASLR is going to be a long process, I suspect. If you find any that look easily fixable, let's get them in. :)

Quoted 8 lines
Quoted 1 line

Are you interested mostly in ARM-specific things?

I am famillar with ARM-specific things mostly, but I can also accept x86/x64 tasks.

Quoted 1 line

Are you interested in kernel-assisted userspace defenses too?

What dose that mean ? something like seccomp ?

Sure, though I meant things like the brute-force detection, or W^X memory enforcement for mmap/mprotect, etc. The defenses that the kernel provides, but are for userspace hardening rather than kernel hardening.

-Kees

Signature · 2 lines
Kees Cook
Nexus Security
#12 lore raw
Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

In your research have you seen a common kind of bug that results in the vulnerabilities you find?

No,
Most of those issues are caused by the lack of checking of user input length
in copy_xx_user functions or afterwards in memcpy functions, however, looking into the details,
they vary among different functions in different files.

Quoted 10 lines

Cool, I hope the recent hardened usercopy stuff will improve that situation, though there is plenty left to do.

Quoted 7 lines
Quoted 3 lines

Is there anything that would have
significantly made exploitation more difficult in the things you worked on?

Yes!

I mostly exploit buffer overflow vulns by overwrite function pointers

(such

Quoted 7 lines
Quoted 6 lines

as
pointers in file_operations) of a global object or a heap object to redirect execution (and if PXN is enable, we simply use rop gadgets). Therefore mitigation solutions of Function_pointer_overwrite would make such kind of exploitation much more diffcult.
But I don't know if you have let all the pointers "const".

Quoted 6 lines

Creating a mechanism like PaX's pax_open_kernel()/pax_close_kernel() combined with the constify plugin would vastly improve the function tables that could be const in the kernel. Perhaps that's something you could look at: porting the pax_open_kernel()/pax_close_kernel() infrastructure on ARM to upstream?

I found that pax_open_kernel()/pax_close_kernel() infrastructure had been ported on ARM in patch grsecurity-3.1-4.7.8-201610161720.patch, as follow:

file: arch/arm/include/asm/pgtable.h

#ifdef CONFIG_PAX_KERNEXEC
static inline unsigned long pax_open_kernel(void) {

#ifdef CONFIG_ARM_LPAE
        /* TODO */
#else
        preempt_disable();
        BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
        modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
#endif
        return 0;
}

static inline unsigned long pax_close_kernel(void) {

#ifdef CONFIG_ARM_LPAE
        /* TODO */
#else
        BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
        /* DOMAIN_MANAGER = "client" under KERNEXEC */
        modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
        preempt_enable_no_resched();
#endif
        return 0;
}

#else
static inline unsigned long pax_open_kernel(void) { return 0; } static inline unsigned long pax_close_kernel(void) { return 0; } #endif

Is there anything else I can do to help about this (mitigation solutions of Function_pointer_overwrite )?

Quoted 9 lines
Quoted 3 lines

Becsides, ret2dir is a common way to exploit UAF vulns so I think solutions like XPFO is a way to make those kind of exploitation more diffcult.

That's also good to hear. XPFO is making some progress; I'm looking forward to it's next patch version (though IIUC, we'll need arch-specific support for it on ARM -- the current patches are x86 only).

I think I can also start with porting XPFO on ARM if you need.

Quoted 11 lines
Quoted 3 lines

Right now KALSR is still disable in most android devices, so it is easy to get kernel symbol address,
however if KALSR is enable, it may make exploitation more diffcult.

Eliminating the various address exposures for KASLR is going to be a long process, I suspect. If you find any that look easily fixable, let's get them in. :)

Quoted 3 lines
Quoted 1 line

Are you interested mostly in ARM-specific things?

I am famillar with ARM-specific things mostly, but I can also accept

x86/x64

Quoted 10 lines
Quoted 5 lines

tasks.

Quoted 1 line

Are you interested in kernel-assisted userspace defenses too?

What dose that mean ? something like seccomp ?

Sure, though I meant things like the brute-force detection, or W^X memory enforcement for mmap/mprotect, etc. The defenses that the kernel provides, but are for userspace hardening rather than kernel hardening.

Right now, I am rather more interested in kernel hardening, however, if there are people in charge of all areas, I can also get involve in userspace hardening

2016-10-14 2:50 GMT+08:00 Kees Cook <[email protected]>:

Quoted 74 lines
Quoted 9 lines · Gengjia Chen
Quoted 2 lines

In your research have you seen a common kind of bug that results in the vulnerabilities you find?

No,
Most of those issues are caused by the lack of checking of user input length
in copy_xx_user functions or afterwards in memcpy functions, however, looking into the details,
they vary among different functions in different files.

Cool, I hope the recent hardened usercopy stuff will improve that situation, though there is plenty left to do.

Quoted 7 lines
Quoted 3 lines

Is there anything that would have
significantly made exploitation more difficult in the things you worked on?

Yes!

I mostly exploit buffer overflow vulns by overwrite function pointers

(such

Quoted 6 lines

as
pointers in file_operations) of a global object or a heap object to redirect execution (and if PXN is enable, we simply use rop gadgets). Therefore mitigation solutions of Function_pointer_overwrite would make such kind of exploitation much more diffcult.
But I don't know if you have let all the pointers "const".

Creating a mechanism like PaX's pax_open_kernel()/pax_close_kernel() combined with the constify plugin would vastly improve the function tables that could be const in the kernel. Perhaps that's something you could look at: porting the pax_open_kernel()/pax_close_kernel() infrastructure on ARM to upstream?

Quoted 3 lines

Becsides, ret2dir is a common way to exploit UAF vulns so I think solutions like XPFO is a way to make those kind of exploitation more diffcult.

That's also good to hear. XPFO is making some progress; I'm looking forward to it's next patch version (though IIUC, we'll need arch-specific support for it on ARM -- the current patches are x86 only).

Quoted 3 lines

Right now KALSR is still disable in most android devices, so it is easy to get kernel symbol address,
however if KALSR is enable, it may make exploitation more diffcult.

Eliminating the various address exposures for KASLR is going to be a long process, I suspect. If you find any that look easily fixable, let's get them in. :)

Quoted 3 lines
Quoted 1 line

Are you interested mostly in ARM-specific things?

I am famillar with ARM-specific things mostly, but I can also accept

x86/x64

Quoted 5 lines

tasks.

Quoted 1 line

Are you interested in kernel-assisted userspace defenses too?

What dose that mean ? something like seccomp ?

Sure, though I meant things like the brute-force detection, or W^X memory enforcement for mmap/mprotect, etc. The defenses that the kernel provides, but are for userspace hardening rather than kernel hardening.

-Kees

--
Kees Cook
Nexus Security

#13 lore raw
Quoted 64 lines · Gengjia Chen
Quoted 28 lines
Quoted 9 lines
Quoted 2 lines

In your research have you seen a common kind of bug that results in the vulnerabilities you find?

No,
Most of those issues are caused by the lack of checking of user input length
in copy_xx_user functions or afterwards in memcpy functions, however, looking into the details,
they vary among different functions in different files.

Cool, I hope the recent hardened usercopy stuff will improve that situation, though there is plenty left to do.

Quoted 6 lines
Quoted 3 lines

Is there anything that would have
significantly made exploitation more difficult in the things you worked on?

Yes!

Quoted 8 lines

I mostly exploit buffer overflow vulns by overwrite function pointers (such
as
pointers in file_operations) of a global object or a heap object to redirect execution (and if PXN is enable, we simply use rop gadgets). Therefore mitigation solutions of Function_pointer_overwrite would make such kind of exploitation much more diffcult.
But I don't know if you have let all the pointers "const".

Quoted 6 lines

Creating a mechanism like PaX's pax_open_kernel()/pax_close_kernel() combined with the constify plugin would vastly improve the function tables that could be const in the kernel. Perhaps that's something you could look at: porting the pax_open_kernel()/pax_close_kernel() infrastructure on ARM to upstream?

I found that pax_open_kernel()/pax_close_kernel() infrastructure had been ported on ARM in patch grsecurity-3.1-4.7.8-201610161720.patch, as follow:

file: arch/arm/include/asm/pgtable.h

#ifdef CONFIG_PAX_KERNEXEC
static inline unsigned long pax_open_kernel(void) {

#ifdef CONFIG_ARM_LPAE
        /* TODO */
#else
        preempt_disable();
        BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
        modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
#endif
        return 0;
}

static inline unsigned long pax_close_kernel(void) {

#ifdef CONFIG_ARM_LPAE
        /* TODO */
#else
        BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
        /* DOMAIN_MANAGER = "client" under KERNEXEC */
        modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
        preempt_enable_no_resched();
#endif
        return 0;
}
Quoted 7 lines

#else
static inline unsigned long pax_open_kernel(void) { return 0; } static inline unsigned long pax_close_kernel(void) { return 0; } #endif

Is there anything else I can do to help about this (mitigation solutions of Function_pointer_overwrite )?

The ARM open/close depends on their use of Domains. For upstream, you'd have to examine how Domains are being used (which seems different to me). The other work is building the in-kernel infrastructure to support write-rarely memory (likely a new section, like ro_after_init, etc).

Quoted 10 lines
Quoted 8 lines
Quoted 3 lines

Becsides, ret2dir is a common way to exploit UAF vulns so I think solutions like XPFO is a way to make those kind of exploitation more diffcult.

That's also good to hear. XPFO is making some progress; I'm looking forward to it's next patch version (though IIUC, we'll need arch-specific support for it on ARM -- the current patches are x86 only).

I think I can also start with porting XPFO on ARM if you need.

Sure, I'd be very curious to see this! Hopefully Juerg has some ideas for helping there (he's been working on the x86 XPFO).

Quoted 18 lines
Quoted 18 lines
Quoted 3 lines

Right now KALSR is still disable in most android devices, so it is easy to get kernel symbol address,
however if KALSR is enable, it may make exploitation more diffcult.

Eliminating the various address exposures for KASLR is going to be a long process, I suspect. If you find any that look easily fixable, let's get them in. :)

Quoted 9 lines
Quoted 1 line

Are you interested mostly in ARM-specific things?

I am famillar with ARM-specific things mostly, but I can also accept x86/x64
tasks.

Quoted 1 line

Are you interested in kernel-assisted userspace defenses too?

What dose that mean ? something like seccomp ?

Quoted 8 lines
Quoted 4 lines

Sure, though I meant things like the brute-force detection, or W^X memory enforcement for mmap/mprotect, etc. The defenses that the kernel provides, but are for userspace hardening rather than kernel hardening.

Right now, I am rather more interested in kernel hardening, however, if there are people in charge of all areas, I can also get involve in userspace hardening

Yeah, it's fine to stick with kernel; no worries. :) Thanks!

-Kees

Signature · 2 lines
Kees Cook
Nexus Security
#14 lore raw
Quoted 150 lines
Quoted 5 lines

2016-10-18 4:15 GMT+08:00 Kees Cook <[email protected]>:
On Mon, Oct 17, 2016 at 4:57 AM, Gengjia Chen <[email protected]>

Quoted 17 lines · wrote:
Quoted 17 lines
Quoted 17 lines
Quoted 9 lines
Quoted 2 lines

In your research have you seen a common kind of bug that results in the vulnerabilities you find?

No,
Most of those issues are caused by the lack of checking of user input length
in copy_xx_user functions or afterwards in memcpy functions, however, looking into the details,
they vary among different functions in different files.

Cool, I hope the recent hardened usercopy stuff will improve that situation, though there is plenty left to do.

Quoted 4 lines
Quoted 3 lines

Is there anything that would have
significantly made exploitation more difficult in the things you worked on?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Yes!

I mostly exploit buffer overflow vulns by overwrite function pointers (such
as
pointers in file_operations) of a global object or a heap object to redirect execution (and if PXN is enable, we simply use rop

gadgets).

Quoted 45 lines
Quoted 45 lines
Quoted 10 lines
Quoted 3 lines

Therefore mitigation solutions of Function_pointer_overwrite would make such kind of exploitation much more diffcult.
But I don't know if you have let all the pointers "const".

Creating a mechanism like PaX's pax_open_kernel()/pax_close_kernel() combined with the constify plugin would vastly improve the function tables that could be const in the kernel. Perhaps that's something you could look at: porting the pax_open_kernel()/pax_close_kernel() infrastructure on ARM to upstream?

I found that pax_open_kernel()/pax_close_kernel() infrastructure had been ported on ARM in patch grsecurity-3.1-4.7.8-201610161720.patch, as follow:

file: arch/arm/include/asm/pgtable.h

#ifdef CONFIG_PAX_KERNEXEC
static inline unsigned long pax_open_kernel(void) {

#ifdef CONFIG_ARM_LPAE
        /* TODO */
#else
        preempt_disable();
        BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
        modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
#endif
        return 0;
}

static inline unsigned long pax_close_kernel(void) {

#ifdef CONFIG_ARM_LPAE
        /* TODO */
#else
        BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
        /* DOMAIN_MANAGER = "client" under KERNEXEC */
        modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
        preempt_enable_no_resched();
#endif
        return 0;
}

#else
static inline unsigned long pax_open_kernel(void) { return 0; } static inline unsigned long pax_close_kernel(void) { return 0; } #endif

Quoted 1 line
Quoted 1 line

Is there anything else I can do to help about this (mitigation

solutions of

Quoted 5 lines
Quoted 1 line

Function_pointer_overwrite )?

The ARM open/close depends on their use of Domains. For upstream, you'd have to examine how Domains are being used (which seems different to me).

So, I will try to start to port pax_open_kernel/pax_close_kernel arm-specific features to upstream, and keep you in touch.

Quoted 4 lines

The other work is building the in-kernel
infrastructure to support write-rarely memory (likely a new section, like ro_after_init, etc).

It seems that the constify plugin still not been ported to the lastest code (v4.9-rc1),
If I understand, you means that a new section should be added to the upstream , and cooperate with the future constify plugin (the plugin automatically put those objects to that section ) ?

Quoted 49 lines
Quoted 10 lines
Quoted 8 lines
Quoted 3 lines

Becsides, ret2dir is a common way to exploit UAF vulns so I think solutions like XPFO is a way to make those kind of exploitation more diffcult.

That's also good to hear. XPFO is making some progress; I'm looking forward to it's next patch version (though IIUC, we'll need arch-specific support for it on ARM -- the current patches are x86 only).

I think I can also start with porting XPFO on ARM if you need.

Sure, I'd be very curious to see this! Hopefully Juerg has some ideas for helping there (he's been working on the x86 XPFO).

Quoted 18 lines
Quoted 18 lines
Quoted 3 lines

Right now KALSR is still disable in most android devices, so it is easy to get kernel symbol address,
however if KALSR is enable, it may make exploitation more diffcult.

Eliminating the various address exposures for KASLR is going to be a long process, I suspect. If you find any that look easily fixable, let's get them in. :)

Quoted 9 lines
Quoted 1 line

Are you interested mostly in ARM-specific things?

I am famillar with ARM-specific things mostly, but I can also accept x86/x64
tasks.

Quoted 1 line

Are you interested in kernel-assisted userspace defenses too?

What dose that mean ? something like seccomp ?

Quoted 8 lines
Quoted 4 lines

Sure, though I meant things like the brute-force detection, or W^X memory enforcement for mmap/mprotect, etc. The defenses that the kernel provides, but are for userspace hardening rather than kernel hardening.

Right now, I am rather more interested in kernel hardening, however, if there are people in charge of all areas, I can also get involve in userspace hardening

Yeah, it's fine to stick with kernel; no worries. :) Thanks!

-Kees

--
Kees Cook
Nexus Security

#15 lore raw
Quoted 7 lines · Gengjia Chen
Quoted 7 lines
Quoted 4 lines

2016-10-18 4:15 GMT+08:00 Kees Cook <[email protected]>:
The ARM open/close depends on their use of Domains. For upstream, you'd have to examine how Domains are being used (which seems different to me).

So, I will try to start to port pax_open_kernel/pax_close_kernel arm-specific features to upstream, and keep you in touch.

Cool, feel free to post RFC patches even if they're not totally finished. :)

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

The other work is building the in-kernel
infrastructure to support write-rarely memory (likely a new section, like ro_after_init, etc).

It seems that the constify plugin still not been ported to the lastest code (v4.9-rc1),
If I understand, you means that a new section should be added to the upstream , and cooperate with the future constify plugin (the plugin automatically put those objects to that section ) ?

It hasn't been forward-ported, no, but building out the infrastructure to support it in upstream will be needed regardless. In PaX, the section is called .data..read_only, but I suspect that will turn out to be a confusing name, since it's actually "write-rarely", but lives in the .rodata section, and the open/close implementation will be used to write to it.

The constify plugin actually moves variables into the .rodata section, so not only does any code writing to such things need to be wrapped in open/close calls, but the C compiler needs to be tricked into generating sensible code (see PaX's const_cast() macro).

-Kees

Signature · 2 lines
Kees Cook
Nexus Security
#16 lore raw
In reply to Kees Cook
Quoted 6 lines
Quoted 3 lines

So, I will try to start to port PAX_REFCOUNT arm-specific features to hardened_atomic_on_next, and keep you in touch. Is there a deadline?  (4.10 / 5.0 merge window?)

You may want to compare notes with Takahiro (CCed) who may have started to look at arm64 (and maybe arm too).

Thanks, I would be grateful!

Quoted 6 lines

As for a deadline, as Elena says, we have no specific target. ("As soon as possible.") The only thing around timing that I like to see is persistent progress: if a patch series goes up for review, getting people to take a look at it, ask questions, make comments, and then hopefully within a week or so, the next version comes up. Momentum is easier to maintain than to build. ;)

OK, good! I will have more time to work on it this WE, still I began to familiarize myself with atomic_t internals (and PaX patch).

I noticed the build is broken for non-x86 architecture (at least arm/arm64), since basically each arch needs to provide atomic_*_wrap() functions. Is there plans to have (probably dummies) functions in case the architecture does not implements this functionality? I noticed the list of define atomic_*_wrap at the end of atomic-long.h, but it does not seems to works (they are defined after the call sites in the expansion of previous macros).

Apart from that, in case of over-/underflow, hardened_atomic_overflow() is called to hang the system if CONFIG_HARDENED_ATOMIC is set. I don't get why the test in arch/x86/include/kernel/traps.c

	if (trapnr == X86_TRAP_OF)

         hardened_atomic_overflow(regs);

is not guarded by CONFIG_HARDENED_ATOMIC: the trap cannot occurs if CONFIG_HARDENED_ATOMIC is unset (since "int" instructions in arch/x86/include/asm/atomic.h are guarded by it), and it would avoid the other implementation of hardened_atomic_overflow in include/asm-generic/bug.h.

Quoted 7 lines
Quoted 1 line

[1] https://pax.grsecurity.net/pax-linux-3.6-201210022100.patch

This is a quite old version of PaX. (Note the date.) If you want to examine PaX separately from Grsecurity (noting differences can be enlightening), check here:

https://www.grsecurity.net/~paxguy1/?C=M;O=D

Thanks!

Colin

#17 lore raw
Quoted 8 lines · Colin Vidal
Quoted 6 lines
Quoted 3 lines

So, I will try to start to port PAX_REFCOUNT arm-specific features to hardened_atomic_on_next, and keep you in touch. Is there a deadline? (4.10 / 5.0 merge window?)

You may want to compare notes with Takahiro (CCed) who may have started to look at arm64 (and maybe arm too).

Thanks, I would be grateful!

Here's a thread Takahiro replied to:

http://www.openwall.com/lists/kernel-hardening/2016/10/12/2

Quoted 10 lines
Quoted 6 lines

As for a deadline, as Elena says, we have no specific target. ("As soon as possible.") The only thing around timing that I like to see is persistent progress: if a patch series goes up for review, getting people to take a look at it, ask questions, make comments, and then hopefully within a week or so, the next version comes up. Momentum is easier to maintain than to build. ;)

OK, good! I will have more time to work on it this WE, still I began to familiarize myself with atomic_t internals (and PaX patch).

Quoted 7 lines

I noticed the build is broken for non-x86 architecture (at least arm/arm64), since basically each arch needs to provide atomic_*_wrap() functions. Is there plans to have (probably dummies) functions in case the architecture does not implements this functionality? I noticed the list of define atomic_*_wrap at the end of atomic-long.h, but it does not seems to works (they are defined after the call sites in the expansion of previous macros).

Yeah, I think this has already come up in the other thread and folks are fixing (have fixed?) it. I expect to see a v2 RFC soon.

Quoted 2 lines

Apart from that, in case of over-/underflow, hardened_atomic_overflow() is called to hang the system if CONFIG_HARDENED_ATOMIC is set. I don't

No, not hang the system, but rather stop further kernel execution and kill the userspace process.

Quoted 10 lines

get why the test in arch/x86/include/kernel/traps.c

        if (trapnr == X86_TRAP_OF)
                hardened_atomic_overflow(regs);

is not guarded by CONFIG_HARDENED_ATOMIC: the trap cannot occurs if CONFIG_HARDENED_ATOMIC is unset (since "int" instructions in arch/x86/include/asm/atomic.h are guarded by it), and it would avoid the other implementation of hardened_atomic_overflow in include/asm-generic/bug.h.

The implementation is a static inline with no body, so the compiler will automatically eliminate the entire "if" statement, since it's a no-op. This is standard kernel coding style, to make the .c code as readable as possible. Having it littered with #ifdefs makes things harder to read.

Quoted 9 lines
Quoted 7 lines
Quoted 1 line

[1] https://pax.grsecurity.net/pax-linux-3.6-201210022100.patch

This is a quite old version of PaX. (Note the date.) If you want to examine PaX separately from Grsecurity (noting differences can be enlightening), check here:

https://www.grsecurity.net/~paxguy1/?C=M;O=D

Thanks!

Sure thing! I'm glad to have another set of eyes on this -- it's a pretty big set of changes. :)

-Kees

Signature · 2 lines
Kees Cook
Nexus Security
#18 lore raw
Quoted 5 lines

get why the test in arch/x86/include/kernel/traps.c

        if (trapnr == X86_TRAP_OF)
                hardened_atomic_overflow(regs);
Quoted 7 lines

is not guarded by CONFIG_HARDENED_ATOMIC: the trap cannot occurs if CONFIG_HARDENED_ATOMIC is unset (since "int" instructions in arch/x86/include/asm/atomic.h are guarded by it), and it would avoid the other implementation of hardened_atomic_overflow in include/asm-generic/bug.h.

The implementation is a static inline with no body, so the compiler will automatically eliminate the entire "if" statement, since it's a no-op.

Ups, my mistake here, this static inline function currently is not empty, see: https://github.com/ereshetova/linux-stable/commit/3591430c0c7560de88b4721021f461e816d6cf38#diff-94d0be26498109f234666923aaafc7d9R221
I didn't understood this part properly, will fix it to be a real empty function.

Thank you for noticing this!

Best Regards,
Elena.

#19 lore raw
In reply to Reshetova, Elena
Quoted 2 lines · Elena

This branch to be precise:
https://github.com/ereshetova/linux-stable/tree/hardened_atomic_on_next

Github seems to think this hasn't been touched in 2 weeks and shows an error of "Failed to load latest commit information." in its web UI. Is there some place to find the last version? (Or rather, is there an RFC v2 coming soon?)

I'd like to get it added to my kernel.org account so that the 0-day builder can poke at it. It regularly finds corner cases, etc...

Thanks!

-Kees

Signature · 2 lines
Kees Cook
Nexus Security
#20 lore raw
Quoted 9 lines · Kees Cook
Quoted 2 lines · Elena

This branch to be precise:
https://github.com/ereshetova/linux-stable/tree/hardened_atomic_on_next

Github seems to think this hasn't been touched in 2 weeks and shows an error of "Failed to load latest commit information." in its web UI. Is there some place to find the last version? (Or rather, is there an RFC v2 coming soon?)

Not sure what's up with the github repository, I've been getting the same error since we started. The most recent change was two days ago, which shows up on the commit page:

https://github.com/ereshetova/linux-stable/commits/hardened_atomic_on_next

..although it seems the individual dates haven't been updated, so maybe it's some issue with how we've been doing the updates. Anyays, the most recent code should be available there.

I'm working under the assumption we're trying to get the RFC v2 out next week, so hopefully soon.

Best Regards,
-hans

#21 lore raw
In reply to Colin Vidal
Quoted 11 lines · Colin Vidal

My name is Colin Vidal. I am currently a PhD student in computer science. My researches consist on building a dedicated specific language on top of JavaScript in order to handle asynchronous events in a synchronous style. Hence, with a direct relation between the control flow and the instruction flow.

Beside my researches, I am taking up the Eudyptula Challenge (task 15 submitted). It helps me to have a global view of the kernel (organization, tree, some features), but it is not enough to get involved in serious development. Therefore, I am looking for task I can accomplish to be involved into real kernel development!

Hi! Welcome to the fun! :)

I see there's already a thread getting into the HARDENED_ATOMIC effort, though I thought I might bring up some other areas too, in case they entice you as well. You've got some background in control flow -- have you spent much time in compiler internals? The recent addition of the gcc plugin infrastructure means there's a much wider ability for the kernel to do compiler tricks now. Two things that come to mind for CFI when looking at the existing PaX/Grsecurity gcc plugins are the kernexec plugin (which, AIUI, is mainly a weak form of SMEP emulation on x86, using simple CFI to keep the high bit set on all kernel function calls) which I think would be easy to extract as a stand-alone plugin:

https://github.com/linux-scraping/linux-grsecurity/blob/grsec-test/scripts/gcc-plugins/kernexec_plugin.c

And at the other end of the spectrum is the RAP plugin (which does a portion of PaX's full RAP, though there appear to be some non-trivial kernel changes need to support it, e.g. per-cpu PGD):

https://pax.grsecurity.net/docs/PaXTeam-H2HC15-RAP-RIP-ROP.pdf

Quoted 7 lines

I still don't have yet a narrow idea about where I can begin. I like though the idea of kernel self protection. For instance, I find the VM- mapped stack to be really interesting, but I think it is an overkill as a beginning, and a lot of work have already been done on it. On the architecture point-of-view, I have a preference of x86 since I only have this hardware for now, but I can work on ARM and others with QEMU too.

A piece missing from vmap-stack (I think) is having guard pages at _both_ ends of the kernel stack. Andy Lutomirski surely knows better than I do, but I'm hoping he's working on looking at PCID-based SMAP emulation. (Hi Andy!) :)

-Kees

Signature · 2 lines
Kees Cook
Nexus Security
#22 lore raw
Quoted 7 lines
Quoted 5 lines

Beside my researches, I am taking up the Eudyptula Challenge (task 15 submitted). It helps me to have a global view of the kernel (organization, tree, some features), but it is not enough to get involved in serious development. Therefore, I am looking for task I can accomplish to be involved into real kernel development!

Hi! Welcome to the fun! :)

Cheers :)

Quoted 4 lines

I see there's already a thread getting into the HARDENED_ATOMIC effort, though I thought I might bring up some other areas too, in case they entice you as well. You've got some background in control flow -- have you spent much time in compiler internals? The recent

Not really on mainstream compilers. I've done some static inter/intra procedural analysis on previous projects (in order to optimize object call site), and the compiler of the DSL I'm working on is based on a completely different theories (it uses Esterel synchronous language semantic) and does not uses static CFG. Hence, I am quite far of CFI analysis :(

Quoted 10 lines

addition of the gcc plugin infrastructure means there's a much wider ability for the kernel to do compiler tricks now. Two things that come to mind for CFI when looking at the existing PaX/Grsecurity gcc plugins are the kernexec plugin (which, AIUI, is mainly a weak form of SMEP emulation on x86, using simple CFI to keep the high bit set on all kernel function calls) which I think would be easy to extract as a stand-alone plugin:

https://github.com/linux-scraping/linux-grsecurity/blob/grsec-test/sc
ripts/gcc-plugins/kernexec_plugin.c

If I understand, this plugin protects against running user-space code in supervisor mode (SMEP emulation, so avoid ROP class exploit), but since this analysis is purely static, it does not protects again out-of-tree dynamically loaded modules, right?

Quoted 5 lines

And at the other end of the spectrum is the RAP plugin (which does a portion of PaX's full RAP, though there appear to be some non-trivial kernel changes need to support it, e.g. per-cpu PGD):

https://pax.grsecurity.net/docs/PaXTeam-H2HC15-RAP-RIP-ROP.pdf

Seems really interesting, though! I have plenty of food for thought with HARDENED_ATOMIC port for now, but I keep that in the back of my mind!

Quoted 8 lines
Quoted 7 lines

I still don't have yet a narrow idea about where I can begin. I like though the idea of kernel self protection. For instance, I find the VM- mapped stack to be really interesting, but I think it is an overkill as a beginning, and a lot of work have already been done on it. On the architecture point-of-view, I have a preference of x86 since I only have this hardware for now, but I can work on ARM and others with QEMU too.

Quoted 6 lines

A piece missing from vmap-stack (I think) is having guard pages at _both_ ends of the kernel stack. Andy Lutomirski surely knows better than I do, but I'm hoping he's working on looking at PCID-based SMAP emulation. (Hi Andy!) :)

-Kees

Thanks!

Colin

#23 lore raw
Quoted 11 lines · Colin Vidal
Quoted 4 lines

I see there's already a thread getting into the HARDENED_ATOMIC effort, though I thought I might bring up some other areas too, in case they entice you as well. You've got some background in control flow -- have you spent much time in compiler internals? The recent

Not really on mainstream compilers. I've done some static inter/intra procedural analysis on previous projects (in order to optimize object call site), and the compiler of the DSL I'm working on is based on a completely different theories (it uses Esterel synchronous language semantic) and does not uses static CFG. Hence, I am quite far of CFI analysis :(

Heh, okay, no worries. I just thought I'd ask. I saw some key words in your introduction. ;)

Quoted 8 lines
Quoted 8 lines

addition of the gcc plugin infrastructure means there's a much wider ability for the kernel to do compiler tricks now. Two things that come to mind for CFI when looking at the existing PaX/Grsecurity gcc plugins are the kernexec plugin (which, AIUI, is mainly a weak form of SMEP emulation on x86, using simple CFI to keep the high bit set on all kernel function calls) which I think would be easy to extract as a stand-alone plugin:

Quoted 7 lines
Quoted 2 lines

https://github.com/linux-scraping/linux-grsecurity/blob/grsec-test/sc
ripts/gcc-plugins/kernexec_plugin.c

If I understand, this plugin protects against running user-space code in supervisor mode (SMEP emulation, so avoid ROP class exploit), but since this analysis is purely static, it does not protects again out-of-tree dynamically loaded modules, right?

I can't tell which of two questions you're asking, so I'll answer both. :)

The gcc plugin infrastructure in the kernel is designed so that any kernel modules built for the kernel will get the plugin run on it. The kernexec plugin in particular, however, has logic to handle totally out-of-tree builds that lack the instrumentation (see the Kconfig for it). In that case, that module would not be protected, but the rest of the kernel would be.

And, allowing arbitrary module loading on a system would nullify virtually all kernel self-protection efforts when defending against the root user, so it's an assumed that systems that are serious about system security are either built monolithic (without modules) or perform some kind of module verification (module signing, or LoadPin with dm-verity).

-Kees

Signature · 2 lines
Kees Cook
Nexus Security
#24 lore raw
In reply to Kees Cook
Quoted 27 lines · Kees Cook
Quoted 11 lines · Colin Vidal

My name is Colin Vidal. I am currently a PhD student in computer science. My researches consist on building a dedicated specific language on top of JavaScript in order to handle asynchronous events in a synchronous style. Hence, with a direct relation between the control flow and the instruction flow.

Beside my researches, I am taking up the Eudyptula Challenge (task 15 submitted). It helps me to have a global view of the kernel (organization, tree, some features), but it is not enough to get involved in serious development. Therefore, I am looking for task I can accomplish to be involved into real kernel development!

Hi! Welcome to the fun! :)

I see there's already a thread getting into the HARDENED_ATOMIC effort, though I thought I might bring up some other areas too, in case they entice you as well. You've got some background in control flow -- have you spent much time in compiler internals? The recent addition of the gcc plugin infrastructure means there's a much wider ability for the kernel to do compiler tricks now. Two things that come to mind for CFI when looking at the existing PaX/Grsecurity gcc plugins are the kernexec plugin (which, AIUI, is mainly a weak form of SMEP emulation on x86, using simple CFI to keep the high bit set on all kernel function calls) which I think would be easy to extract as a stand-alone plugin:

Quoted 7 lines

https://github.com/linux-scraping/linux-grsecurity/blob/grsec-test/scripts/gcc-plugins/kernexec_plugin.c

And at the other end of the spectrum is the RAP plugin (which does a portion of PaX's full RAP, though there appear to be some non-trivial kernel changes need to support it, e.g. per-cpu PGD):

https://pax.grsecurity.net/docs/PaXTeam-H2HC15-RAP-RIP-ROP.pdf

Linus has loudly poo-pooed per-cpu PGD, and I'm not sure I disagree. It would be *really* nice to find a clean way to do RAP without it.

Quoted 9 lines
Quoted 8 lines

I still don't have yet a narrow idea about where I can begin. I like though the idea of kernel self protection. For instance, I find the VM- mapped stack to be really interesting, but I think it is an overkill as a beginning, and a lot of work have already been done on it. On the architecture point-of-view, I have a preference of x86 since I only have this hardware for now, but I can work on ARM and others with QEMU too.

Quoted 5 lines

A piece missing from vmap-stack (I think) is having guard pages at _both_ ends of the kernel stack. Andy Lutomirski surely knows better than I do, but I'm hoping he's working on looking at PCID-based SMAP emulation. (Hi Andy!) :)

Hi! I'm not presently working on it, and I'm a bit swamped, but maybe soon.