lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 24 Jan 2019 14:03:06 +0100
From:   <vrd@...zon.com>
To:     <linux-kernel@...r.kernel.org>
CC:     Nicolas Pernas Maradei <npernas@...zon.de>,
        Varad Gautam <vrd@...zon.de>,
        David Woodhouse <dwmw@...zon.co.uk>,
        Maximilian Heyne <mheyne@...zon.de>,
        Stefan Nuernberger <snu@...zon.de>, Amit Shah <aams@...zon.de>,
        "Linus Torvalds" <torvalds@...ux-foundation.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Al Viro <viro@...IV.linux.org.uk>,
        "Christian Brauner" <christian.brauner@...ntu.com>,
        "Eric W . Biederman" <ebiederm@...ssion.com>,
        Matthew Wilcox <willy@...radead.org>,
        Eric Biggers <ebiggers@...gle.com>,
        "# 4 . 9+" <stable@...r.kernel.org>
Subject: [PATCH] fs/devpts: always delete dcache dentry-s in dput()

From: Varad Gautam <vrd@...zon.de>

d_delete only unhashes an entry if it is reached with
dentry->d_lockref.count != 1. Prior to commit 8ead9dd54716 ("devpts:
more pty driver interface cleanups"), d_delete was called on a dentry
from devpts_pty_kill with two references held, which would trigger the
unhashing, and the subsequent dputs would release it.

Commit 8ead9dd54716 reworked devpts_pty_kill to stop acquiring the second
reference from d_find_alias, and the d_delete call left the dentries
still on the hashed list without actually ever being dropped from dcache
before explicit cleanup. This causes the number of negative dentries for
devpts to pile up, and an `ls /dev/pts` invocation can take seconds to
return.

Provide always_delete_dentry() from simple_dentry_operations
as .d_delete for devpts, to make the dentry be dropped from dcache.

Without this cleanup, the number of dentries in /dev/pts/ can be grown
arbitrarily as:

`python -c 'import pty; pty.spawn(["ls", "/dev/pts"])'`

A systemtap probe on dcache_readdir to count d_subdirs shows this count
to increase with each pty spawn invocation above:

probe kernel.function("dcache_readdir") {
    subdirs = &@...t($file->f_path->dentry, "dentry")->d_subdirs;
    p = subdirs;
    p = @cast(p, "list_head")->next;
    i = 0
    while (p != subdirs) {
      p = @cast(p, "list_head")->next;
      i = i+1;
    }
    printf("number of dentries: %d\n", i);
}

Fixes: 8ead9dd54716 ("devpts: more pty driver interface cleanups")
Signed-off-by: Varad Gautam <vrd@...zon.de>
Reported-by: Zheng Wang <wanz@...zon.de>
Reported-by: Brandon Schwartz <bsschwar@...zon.de>
Root-caused-by: Maximilian Heyne <mheyne@...zon.de>
Root-caused-by: Nicolas Pernas Maradei <npernas@...zon.de>
CC: David Woodhouse <dwmw@...zon.co.uk>
CC: Maximilian Heyne <mheyne@...zon.de>
CC: Stefan Nuernberger <snu@...zon.de>
CC: Amit Shah <aams@...zon.de>
CC: Linus Torvalds <torvalds@...ux-foundation.org>
CC: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
CC: Al Viro <viro@...IV.linux.org.uk>
CC: Christian Brauner <christian.brauner@...ntu.com>
CC: Eric W. Biederman <ebiederm@...ssion.com>
CC: Matthew Wilcox <willy@...radead.org>
CC: Eric Biggers <ebiggers@...gle.com>
CC: <stable@...r.kernel.org> # 4.9+
---
 fs/devpts/inode.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index c538145..553a3f3 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -455,6 +455,7 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
 	s->s_blocksize_bits = 10;
 	s->s_magic = DEVPTS_SUPER_MAGIC;
 	s->s_op = &devpts_sops;
+	s->s_d_op = &simple_dentry_operations;
 	s->s_time_gran = 1;
 
 	error = -ENOMEM;
-- 
2.7.4
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ