Skip to contentSkip to conversation

pty: make ptmx file ops read-only after init

PATCH In review Kees Cook 3 participants 5 messages Sep 8, 2016 – Sep 21, 2016 TTY layer and serial drivers

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 pty: make ptmx file ops read-only after init

The ptmx_fops structure is only changed during init, so mark it as such.

---
 drivers/tty/pty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/pty.c +1 -1
index 51e0d32883ba..a23fa5ed1d67 100644
@@ -800,7 +800,7 @@ out_free_file:
 	return retval;
 }
 
-static struct file_operations ptmx_fops;
+static struct file_operations ptmx_fops __ro_after_init;
 
 static void __init unix98_pty_init(void)
 {
Signature · 6 lines
2.7.4


-- 
Kees Cook
Nexus Security
#1 lore raw
Quoted 1 line · Kees Cook

The ptmx_fops structure is only changed during init, so mark it as such.

Right, but I am missing what is the benefit? You would have to elaborate here...

Quoted 11 lines
---
 drivers/tty/pty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/pty.c +0 -0
index 51e0d32883ba..a23fa5ed1d67 100644

drivers/tty/pty.c out_free_file: · line 806

Quoted 8 lines
drivers/tty/pty.c +1 -1
@@ -800,7 +800,7 @@ out_free_file:
 	return retval;
 }
 
-static struct file_operations ptmx_fops;
+static struct file_operations ptmx_fops __ro_after_init;
 
 static void __init unix98_pty_init(void)
 {

thanks,

Signature · 2 lines
js
suse labs
#2 lore raw
Quoted 5 lines · On Wed, 14 Sep 2016 09:59:42 +0200 Jiri Slaby <[email protected]> wrote:
Quoted 1 line · Kees Cook

The ptmx_fops structure is only changed during init, so mark it as such.

Right, but I am missing what is the benefit? You would have to elaborate here...

The pages end up marked read only even to the kernel (and in future could even be marked read only forever when in kvm if we get suitable virtual machine extensions). That makes it much harder to patch those vectors when making security attacks.

author
#3 lore raw
Quoted 6 lines · One Thousand Gnomes
Quoted 3 lines · On Wed, 14 Sep 2016 09:59:42 +0200 Jiri Slaby <[email protected]> wrote:
Quoted 1 line · Kees Cook

The ptmx_fops structure is only changed during init, so mark it as such.

Quoted 7 lines
Quoted 2 lines

Right, but I am missing what is the benefit? You would have to elaborate here...

The pages end up marked read only even to the kernel (and in future could even be marked read only forever when in kvm if we get suitable virtual machine extensions). That makes it much harder to patch those vectors when making security attacks.

Correct, this is a continuing effort to reduce the internal attack surface of the kernel, where one of the most common exploitation methods is overwriting function pointers.

Some examples of attacks and mitigations are here:
http://kernsec.org/wiki/index.php/Exploit_Methods/Function_pointer_overwrite

While this patch isn't a huge change, it's still a viable candidate. I send these as I notice them, and hope that other folks will start to see these opportunities and send more patches too. :)

-Kees

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

Correct, this is a continuing effort to reduce the internal attack surface of the kernel, where one of the most common exploitation methods is overwriting function pointers.

Some examples of attacks and mitigations are here:
http://kernsec.org/wiki/index.php/Exploit_Methods/Function_pointer_overwrite

While this patch isn't a huge change, it's still a viable candidate. I send these as I notice them, and hope that other folks will start to see these opportunities and send more patches too. :)

I didn't object to the patch. I could imagine the use case. But putting the idea to the commit message would have made it clear.

thanks,

Signature · 2 lines
js
suse labs