24 Mar, 2019

1 commit

  • commit 73052b0daee0b750b39af18460dfec683e4f5887 upstream.

    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 = &@cast($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
    Reported-by: Zheng Wang
    Reported-by: Brandon Schwartz
    Root-caused-by: Maximilian Heyne
    Root-caused-by: Nicolas Pernas Maradei
    CC: David Woodhouse
    CC: Maximilian Heyne
    CC: Stefan Nuernberger
    CC: Amit Shah
    CC: Linus Torvalds
    CC: Greg Kroah-Hartman
    CC: Al Viro
    CC: Christian Brauner
    CC: Eric W. Biederman
    CC: Matthew Wilcox
    CC: Eric Biggers
    CC: # 4.9+
    Signed-off-by: Al Viro
    Signed-off-by: Greg Kroah-Hartman

    Varad Gautam
     

22 Aug, 2018

1 commit

  • ida_alloc_max() matches what this driver wants to do. Also removes a
    call to ida_pre_get(). We no longer need the protection of the mutex,
    so convert pty_count to an atomic_t and remove the mutex entirely.

    Signed-off-by: Matthew Wilcox

    Matthew Wilcox
     

14 Mar, 2018

3 commits

  • Signed-off-by: Christian Brauner
    Acked-by: "Eric W. Biederman"
    Acked-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Christian Brauner
     
  • Most libcs will still look at /dev/ptmx when opening the master fd of a pty
    device. When /dev/ptmx is a bind-mount of /dev/pts/ptmx and the TIOCGPTPEER
    ioctl() is used to safely retrieve a file descriptor for the slave side of
    the pty based on the master fd, the /proc/self/fd/{0,1,2} symlinks will
    point to /. A very simply reproducer for this issue presupposing a libc
    that uses TIOCGPTPEER in its openpty() implementation is:

    unshare --mount
    mount --bind /dev/pts/ptmx /dev/ptmx
    chmod 666 /dev/ptmx
    script
    ls -al /proc/self/fd/0

    Having bind-mounts of /dev/pts/ptmx to /dev/ptmx not working correctly is a
    regression. In addition, it is also a fairly common scenario in containers
    employing user namespaces.

    The reason for the current failure is that the kernel tries to verify the
    useability of the devpts filesystem without resolving the /dev/ptmx
    bind-mount first. This will lead it to detect that the dentry is escaping
    its bind-mount. The reason is that while the devpts filesystem mounted at
    /dev/pts has the devtmpfs mounted at /dev as its parent mount:

    21 -- -- / /dev
    -- 21 -- / /dev/pts

    devtmpfs and devpts are on different devices

    -- -- 0:6 / /dev
    -- -- 0:20 / /dev/pts

    This has the consequence that the pathname of the parent directory of the
    devpts filesystem mount at /dev/pts is /. So if /dev/ptmx is a bind-mount
    of /dev/pts/ptmx then the /dev/ptmx bind-mount and the devpts mount at
    /dev/pts will end up being located on the same device which is recorded in
    the superblock of their vfsmount. This means the parent directory of the
    /dev/ptmx bind-mount will be /ptmx:

    -- -- ---- /ptmx /dev/ptmx

    Without the bind-mount resolution patch the kernel will now perform the
    bind-mount escape check directly on /dev/ptmx. The function responsible for
    this is devpts_ptmx_path() which calls pts_path() which in turn calls
    path_parent_directory(). Based on the above explanation,
    path_parent_directory() will yield / as the parent directory for the
    /dev/ptmx bind-mount and not the expected /dev. Thus, the kernel detects
    that /dev/ptmx is escaping its bind-mount and will set /proc//fd/
    to /.

    This patch changes the logic to first resolve any bind-mounts. After the
    bind-mounts have been resolved (i.e. we have traced it back to the
    associated devpts mount) devpts_ptmx_path() can be called. In order to
    guarantee correct path generation for the slave file descriptor the kernel
    now requires that a pts directory is found in the parent directory of the
    ptmx bind-mount. This implies that when doing bind-mounts the ptmx
    bind-mount and the devpts mount should have a common parent directory. A
    valid example is:

    mount -t devpts devpts /dev/pts
    mount --bind /dev/pts/ptmx /dev/ptmx

    an invalid example is:

    mount -t devpts devpts /dev/pts
    mount --bind /dev/pts/ptmx /ptmx

    This allows us to support:
    - calling open on ptmx devices located inside non-standard devpts mounts:
    mount -t devpts devpts /mnt
    master = open("/mnt/ptmx", ...);
    slave = ioctl(master, TIOCGPTPEER, ...);
    - calling open on ptmx devices located outside the devpts mount with a
    common ancestor directory:
    mount -t devpts devpts /dev/pts
    mount --bind /dev/pts/ptmx /dev/ptmx
    master = open("/dev/ptmx", ...);
    slave = ioctl(master, TIOCGPTPEER, ...);

    while failing on ptmx devices located outside the devpts mount without a
    common ancestor directory:
    mount -t devpts devpts /dev/pts
    mount --bind /dev/pts/ptmx /ptmx
    master = open("/ptmx", ...);
    slave = ioctl(master, TIOCGPTPEER, ...);

    in which case save path generation cannot be guaranteed.

    Signed-off-by: Christian Brauner
    Suggested-by: Eric Biederman
    Suggested-by: Linus Torvalds
    Reviewed-by: "Eric W. Biederman"
    Acked-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Christian Brauner
     
  • Hoist the check whether we have already found a suitable devpts filesystem
    out of devpts_ptmx_path() in preparation for the devpts bind-mount
    resolution patch. This is a non-functional change.

    Signed-off-by: Christian Brauner
    Reviewed-by: "Eric W. Biederman"
    Acked-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Christian Brauner
     

01 Feb, 2018

1 commit

  • If devpts_ptmx_path() returns an error code, then devpts_mntget()
    dereferences an ERR_PTR():

    BUG: unable to handle kernel paging request at fffffffffffffff5
    IP: devpts_mntget+0x13f/0x280 fs/devpts/inode.c:173

    Fix it by returning early in the error paths.

    Reproducer:

    #define _GNU_SOURCE
    #include
    #include
    #include
    #define TIOCGPTPEER _IO('T', 0x41)

    int main()
    {
    for (;;) {
    int fd = open("/dev/ptmx", 0);
    unshare(CLONE_NEWNS);
    ioctl(fd, TIOCGPTPEER, 0);
    }
    }

    Fixes: 311fc65c9fb9 ("pty: Repair TIOCGPTPEER")
    Reported-by: syzbot
    Cc: # v4.13+
    Signed-off-by: Eric Biggers
    Signed-off-by: Linus Torvalds

    Eric Biggers
     

25 Aug, 2017

1 commit

  • The implementation of TIOCGPTPEER has two issues.

    When /dev/ptmx (as opposed to /dev/pts/ptmx) is opened the wrong
    vfsmount is passed to dentry_open. Which results in the kernel displaying
    the wrong pathname for the peer.

    The second is simply by caching the vfsmount and dentry of the peer it leaves
    them open, in a way they were not previously Which because of the inreased
    reference counts can cause unnecessary behaviour differences resulting in
    regressions.

    To fix these move the ioctl into tty_io.c at a generic level allowing
    the ioctl to have access to the struct file on which the ioctl is
    being called. This allows the path of the slave to be derived when
    opening the slave through TIOCGPTPEER instead of requiring the path to
    the slave be cached. Thus removing the need for caching the path.

    A new function devpts_ptmx_path is factored out of devpts_acquire and
    used to implement a function devpts_mntget. The new function devpts_mntget
    takes a filp to perform the lookup on and fsi so that it can confirm
    that the superblock that is found by devpts_ptmx_path is the proper superblock.

    v2: Lots of fixes to make the code actually work
    v3: Suggestions by Linus
    - Removed the unnecessary initialization of filp in ptm_open_peer
    - Simplified devpts_ptmx_path as gotos are no longer required

    [ This is the fix for the issue that was reverted in commit
    143c97cc6529, but this time without breaking 'pbuilder' due to
    increased reference counts - Linus ]

    Fixes: 54ebbfb16034 ("tty: add TIOCGPTPEER ioctl")
    Reported-by: Christian Brauner
    Reported-and-tested-by: Stefan Lippers-Hollmann
    Signed-off-by: "Eric W. Biederman"
    Signed-off-by: Linus Torvalds

    Eric W. Biederman
     

24 Aug, 2017

1 commit

  • This reverts commit c8c03f1858331e85d397bacccd34ef409aae993c.

    It turns out that while fixing the ptmx file descriptor to have the
    correct 'struct path' to the associated slave pty is a really good
    thing, it breaks some user space tools for a very annoying reason.

    The problem is that /dev/ptmx and its associated slave pty (/dev/pts/X)
    are on different mounts. That was what caused us to have the wrong path
    in the first place (we would mix up the vfsmount of the 'ptmx' node,
    with the dentry of the pty slave node), but it also means that now while
    we use the right vfsmount, having the pty master open also keeps the pts
    mount busy.

    And it turn sout that that makes 'pbuilder' very unhappy, as noted by
    Stefan Lippers-Hollmann:

    "This patch introduces a regression for me when using pbuilder
    0.228.7[2] (a helper to build Debian packages in a chroot and to
    create and update its chroots) when trying to umount /dev/ptmx (inside
    the chroot) on Debian/ unstable (full log and pbuilder configuration
    file[3] attached).

    [...]
    Setting up build-essential (12.3) ...
    Processing triggers for libc-bin (2.24-15) ...
    I: unmounting dev/ptmx filesystem
    W: Could not unmount dev/ptmx: umount: /var/cache/pbuilder/build/1340/dev/ptmx: target is busy
    (In some cases useful info about processes that
    use the device is found by lsof(8) or fuser(1).)"

    apparently pbuilder tries to unmount the /dev/pts filesystem while still
    holding at least one master node open, which is arguably not very nice,
    but we don't break user space even when fixing other bugs.

    So this commit has to be reverted.

    I'll try to figure out a way to avoid caching the path to the slave pty
    in the master pty. The only thing that actually wants that slave pty
    path is the "TIOCGPTPEER" ioctl, and I think we could just recreate the
    path at that time.

    Reported-by: Stefan Lippers-Hollmann
    Cc: Eric W Biederman
    Cc: Christian Brauner
    Cc: Al Viro
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

18 Aug, 2017

1 commit

  • Christian Brauner reported that if you use the TIOCGPTPEER ioctl() to
    get a slave pty file descriptor, the resulting file descriptor doesn't
    look right in /proc//fd/. In particular, he wanted to use
    readlink() on /proc/self/fd/ to get the pathname of the slave pty
    (basically implementing "ptsname{_r}()").

    The reason for that was that we had generated the wrong 'struct path'
    when we create the pty in ptmx_open().

    In particular, the dentry was correct, but the vfsmount pointed to the
    mount of the ptmx node. That _can_ be correct - in case you use
    "/dev/pts/ptmx" to open the master - but usually is not. The normal
    case is to use /dev/ptmx, which then looks up the pts/ directory, and
    then the vfsmount of the ptmx node is obviously the /dev directory, not
    the /dev/pts/ directory.

    We actually did have the right vfsmount available, but in the wrong
    place (it gets looked up in 'devpts_acquire()' when we get a reference
    to the pts filesystem), and so ptmx_open() used the wrong mnt pointer.

    The end result of this confusion was that the pty worked fine, but when
    if you did TIOCGPTPEER to get the slave side of the pty, end end result
    would also work, but have that dodgy 'struct path'.

    And then when doing "d_path()" on to get the pathname, the vfsmount
    would not match the root of the pts directory, and d_path() would return
    an empty pathname thinking that the entry had escaped a bind mount into
    another mount.

    This fixes the problem by making devpts_acquire() return the vfsmount
    for the pts filesystem, allowing ptmx_open() to trivially just use the
    right mount for the pts dentry, and create the proper 'struct path'.

    Reported-by: Christian Brauner
    Cc: Al Viro
    Acked-by: Eric Biederman
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

11 Oct, 2016

1 commit

  • Pull more vfs updates from Al Viro:
    ">rename2() work from Miklos + current_time() from Deepa"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    fs: Replace current_fs_time() with current_time()
    fs: Replace CURRENT_TIME_SEC with current_time() for inode timestamps
    fs: Replace CURRENT_TIME with current_time() for inode timestamps
    fs: proc: Delete inode time initializations in proc_alloc_inode()
    vfs: Add current_time() api
    vfs: add note about i_op->rename changes to porting
    fs: rename "rename2" i_op to "rename"
    vfs: remove unused i_op->rename
    fs: make remaining filesystems use .rename2
    libfs: support RENAME_NOREPLACE in simple_rename()
    fs: support RENAME_NOREPLACE for local filesystems
    ncpfs: fix unused variable warning

    Linus Torvalds
     

28 Sep, 2016

1 commit

  • CURRENT_TIME macro is not appropriate for filesystems as it
    doesn't use the right granularity for filesystem timestamps.
    Use current_time() instead.

    CURRENT_TIME is also not y2038 safe.

    This is also in preparation for the patch that transitions
    vfs timestamps to use 64 bit time and hence make them
    y2038 safe. As part of the effort current_time() will be
    extended to do range checks. Hence, it is necessary for all
    file system timestamps to use current_time(). Also,
    current_time() will be transitioned along with vfs to be
    y2038 safe.

    Note that whenever a single call to current_time() is used
    to change timestamps in different inodes, it is because they
    share the same time granularity.

    Signed-off-by: Deepa Dinamani
    Reviewed-by: Arnd Bergmann
    Acked-by: Felipe Balbi
    Acked-by: Steven Whitehouse
    Acked-by: Ryusuke Konishi
    Acked-by: David Sterba
    Signed-off-by: Al Viro

    Deepa Dinamani
     

23 Sep, 2016

6 commits


04 Sep, 2016

1 commit

  • In commit 8ead9dd54716 ("devpts: more pty driver interface cleanups") I
    made devpts_get_priv() just return the dentry->fs_data directly. And
    because I thought it wouldn't happen, I added a warning if you ever saw
    a pts node that wasn't on devpts.

    And no, that warning never triggered under any actual real use, but you
    can trigger it by creating nonsensical pts nodes by hand.

    So just revert the warning, and make devpts_get_priv() return NULL for
    that case like it used to.

    Reported-by: Dmitry Vyukov
    Cc: stable@vger.kernel.org # 4.6+
    Cc: Eric W Biederman"
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

24 Jun, 2016

1 commit


06 Jun, 2016

1 commit

  • The /dev/ptmx device node is changed to lookup the directory entry "pts"
    in the same directory as the /dev/ptmx device node was opened in. If
    there is a "pts" entry and that entry is a devpts filesystem /dev/ptmx
    uses that filesystem. Otherwise the open of /dev/ptmx fails.

    The DEVPTS_MULTIPLE_INSTANCES configuration option is removed, so that
    userspace can now safely depend on each mount of devpts creating a new
    instance of the filesystem.

    Each mount of devpts is now a separate and equal filesystem.

    Reserved ttys are now available to all instances of devpts where the
    mounter is in the initial mount namespace.

    A new vfs helper path_pts is introduced that finds a directory entry
    named "pts" in the directory of the passed in path, and changes the
    passed in path to point to it. The helper path_pts uses a function
    path_parent_directory that was factored out of follow_dotdot.

    In the implementation of devpts:
    - devpts_mnt is killed as it is no longer meaningful if all mounts of
    devpts are equal.
    - pts_sb_from_inode is replaced by just inode->i_sb as all cached
    inodes in the tty layer are now from the devpts filesystem.
    - devpts_add_ref is rolled into the new function devpts_ptmx. And the
    unnecessary inode hold is removed.
    - devpts_del_ref is renamed devpts_release and reduced to just a
    deacrivate_super.
    - The newinstance mount option continues to be accepted but is now
    ignored.

    In devpts_fs.h definitions for when !CONFIG_UNIX98_PTYS are removed as
    they are never used.

    Documentation/filesystems/devices.txt is updated to describe the current
    situation.

    This has been verified to work properly on openwrt-15.05, centos5,
    centos6, centos7, debian-6.0.2, debian-7.9, debian-8.2, ubuntu-14.04.3,
    ubuntu-15.10, fedora23, magia-5, mint-17.3, opensuse-42.1,
    slackware-14.1, gentoo-20151225 (13.0?), archlinux-2015-12-01. With the
    caveat that on centos6 and on slackware-14.1 that there wind up being
    two instances of the devpts filesystem mounted on /dev/pts, the lower
    copy does not end up getting used.

    Signed-off-by: "Eric W. Biederman"
    Cc: Greg KH
    Cc: Peter Hurley
    Cc: Peter Anvin
    Cc: Andy Lutomirski
    Cc: Al Viro
    Cc: Serge Hallyn
    Cc: Willy Tarreau
    Cc: Aurelien Jarno
    Cc: One Thousand Gnomes
    Cc: Jann Horn
    Cc: Jiri Slaby
    Cc: Florian Weimer
    Cc: Konstantin Khlebnikov
    Signed-off-by: Linus Torvalds

    Eric W. Biederman
     

27 Apr, 2016

1 commit

  • This is more prep-work for the upcoming pty changes. Still just code
    cleanup with no actual semantic changes.

    This removes a bunch pointless complexity by just having the slave pty
    side remember the dentry associated with the devpts slave rather than
    the inode. That allows us to remove all the "look up the dentry" code
    for when we want to remove it again.

    Together with moving the tty pointer from "inode->i_private" to
    "dentry->d_fsdata" and getting rid of pointless inode locking, this
    removes about 30 lines of code. Not only is the end result smaller,
    it's simpler and easier to understand.

    The old code, for example, depended on the d_find_alias() to not just
    find the dentry, but also to check that it is still hashed, which in
    turn validated the tty pointer in the inode.

    That is a _very_ roundabout way to say "invalidate the cached tty
    pointer when the dentry is removed".

    The new code just does

    dentry->d_fsdata = NULL;

    in devpts_pty_kill() instead, invalidating the tty pointer rather more
    directly and obviously. Don't do something complex and subtle when the
    obvious straightforward approach will do.

    The rest of the patch (ie apart from code deletion and the above tty
    pointer clearing) is just switching the calling convention to pass the
    dentry or file pointer around instead of the inode.

    Cc: Eric Biederman
    Cc: Peter Anvin
    Cc: Andy Lutomirski
    Cc: Al Viro
    Cc: Peter Hurley
    Cc: Serge Hallyn
    Cc: Willy Tarreau
    Cc: Aurelien Jarno
    Cc: Alan Cox
    Cc: Jann Horn
    Cc: Greg KH
    Cc: Jiri Slaby
    Cc: Florian Weimer
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

19 Apr, 2016

1 commit

  • This gets rid of the horrible notion of having that

    struct inode *ptmx_inode

    be the linchpin of the interface between the pty code and devpts.

    By de-emphasizing the ptmx inode, a lot of things actually get cleaner,
    and we will have a much saner way forward. In particular, this will
    allow us to associate with any particular devpts instance at open-time,
    and not be artificially tied to one particular ptmx inode.

    The patch itself is actually fairly straightforward, and apart from some
    locking and return path cleanups it's pretty mechanical:

    - the interfaces that devpts exposes all take "struct pts_fs_info *"
    instead of "struct inode *ptmx_inode" now.

    NOTE! The "struct pts_fs_info" thing is a completely opaque structure
    as far as the pty driver is concerned: it's still declared entirely
    internally to devpts. So the pty code can't actually access it in any
    way, just pass it as a "cookie" to the devpts code.

    - the "look up the pts fs info" is now a single clear operation, that
    also does the reference count increment on the pts superblock.

    So "devpts_add/del_ref()" is gone, and replaced by a "lookup and get
    ref" operation (devpts_get_ref(inode)), along with a "put ref" op
    (devpts_put_ref()).

    - the pty master "tty->driver_data" field now contains the pts_fs_info,
    not the ptmx inode.

    - because we don't care about the ptmx inode any more as some kind of
    base index, the ref counting can now drop the inode games - it just
    gets the ref on the superblock.

    - the pts_fs_info now has a back-pointer to the super_block. That's so
    that we can easily look up the information we actually need. Although
    quite often, the pts fs info was actually all we wanted, and not having
    to look it up based on some magical inode makes things more
    straightforward.

    In particular, now that "devpts_get_ref(inode)" operation should really
    be the *only* place we need to look up what devpts instance we're
    associated with, and we do it exactly once, at ptmx_open() time.

    The other side of this is that one ptmx node could now be associated
    with multiple different devpts instances - you could have a single
    /dev/ptmx node, and then have multiple mount namespaces with their own
    instances of devpts mounted on /dev/pts/. And that's all perfectly sane
    in a model where we just look up the pts instance at open time.

    This will eventually allow us to get rid of our odd single-vs-multiple
    pts instance model, but this patch in itself changes no semantics, only
    an internal binding model.

    Cc: Eric Biederman
    Cc: Peter Anvin
    Cc: Andy Lutomirski
    Cc: Al Viro
    Cc: Peter Hurley
    Cc: Serge Hallyn
    Cc: Willy Tarreau
    Cc: Aurelien Jarno
    Cc: Alan Cox
    Cc: Jann Horn
    Cc: Greg KH
    Cc: Jiri Slaby
    Cc: Florian Weimer
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

07 Feb, 2016

1 commit

  • Considering current pty code and multiple devpts instances, it's possible
    to umount a devpts file system while a program still has /dev/tty opened
    pointing to a previosuly closed pty pair in that instance. In the case all
    ptmx and pts/N files are closed, umount can be done. If the program closes
    /dev/tty after umount is done, devpts_kill_index will use now an invalid
    super_block, which was already destroyed in the umount operation after
    running ->kill_sb. This is another "use after free" type of issue, but now
    related to the allocated super_block instance.

    To avoid the problem (warning at ida_remove and potential crashes) for
    this specific case, I added two functions in devpts which grabs additional
    references to the super_block, which pty code now uses so it makes sure
    the super block structure is still valid until pty shutdown is done.
    I also moved the additional inode references to the same functions, which
    also covered similar case with inode being freed before /dev/tty final
    close/shutdown.

    Signed-off-by: Herton R. Krzesinski
    Cc: stable@vger.kernel.org # 2.6.29+
    Reviewed-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Herton R. Krzesinski
     

23 Jan, 2016

1 commit

  • parallel to mutex_{lock,unlock,trylock,is_locked,lock_nested},
    inode_foo(inode) being mutex_foo(&inode->i_mutex).

    Please, use those for access to ->i_mutex; over the coming cycle
    ->i_mutex will become rwsem, with ->lookup() done with it held
    only shared.

    Signed-off-by: Al Viro

    Al Viro
     

01 Jul, 2015

1 commit

  • If devpts failed to initialize, it would store an ERR_PTR in the global
    devpts_mnt. A subsequent open of /dev/ptmx would call devpts_new_index,
    which would dereference devpts_mnt and crash.

    Avoid storing invalid values in devpts_mnt; leave it NULL instead. Make
    both devpts_new_index and devpts_pty_new fail gracefully with ENODEV in
    that case, which then becomes the return value to the userspace open call
    on /dev/ptmx.

    [akpm@linux-foundation.org: remove unneeded static]
    Signed-off-by: Josh Triplett
    Reported-by: Fengguang Wu
    Reviewed-by: Peter Hurley
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     

16 Apr, 2015

1 commit


07 Jun, 2014

1 commit

  • Also convert spaces to tabs (checkpatch warnings) if (!dentry) KERN_NOTICE
    converted to pr_err (like if (!inode) error process)

    [akpm@linux-foundation.org: use KBUILD_MODNAME, per Joe]
    Signed-off-by: Fabian Frederick
    Cc: Joe Perches
    Cc: "Theodore Ts'o"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Fabian Frederick
     

13 Mar, 2014

1 commit

  • Previously, the no-op "mount -o mount /dev/xxx" operation when the
    file system is already mounted read-write causes an implied,
    unconditional syncfs(). This seems pretty stupid, and it's certainly
    documented or guaraunteed to do this, nor is it particularly useful,
    except in the case where the file system was mounted rw and is getting
    remounted read-only.

    However, it's possible that there might be some file systems that are
    actually depending on this behavior. In most file systems, it's
    probably fine to only call sync_filesystem() when transitioning from
    read-write to read-only, and there are some file systems where this is
    not needed at all (for example, for a pseudo-filesystem or something
    like romfs).

    Signed-off-by: "Theodore Ts'o"
    Cc: linux-fsdevel@vger.kernel.org
    Cc: Christoph Hellwig
    Cc: Artem Bityutskiy
    Cc: Adrian Hunter
    Cc: Evgeniy Dushistov
    Cc: Jan Kara
    Cc: OGAWA Hirofumi
    Cc: Anders Larsen
    Cc: Phillip Lougher
    Cc: Kees Cook
    Cc: Mikulas Patocka
    Cc: Petr Vandrovec
    Cc: xfs@oss.sgi.com
    Cc: linux-btrfs@vger.kernel.org
    Cc: linux-cifs@vger.kernel.org
    Cc: samba-technical@lists.samba.org
    Cc: codalist@coda.cs.cmu.edu
    Cc: linux-ext4@vger.kernel.org
    Cc: linux-f2fs-devel@lists.sourceforge.net
    Cc: fuse-devel@lists.sourceforge.net
    Cc: cluster-devel@redhat.com
    Cc: linux-mtd@lists.infradead.org
    Cc: jfs-discussion@lists.sourceforge.net
    Cc: linux-nfs@vger.kernel.org
    Cc: linux-nilfs@vger.kernel.org
    Cc: linux-ntfs-dev@lists.sourceforge.net
    Cc: ocfs2-devel@oss.oracle.com
    Cc: reiserfs-devel@vger.kernel.org

    Theodore Ts'o
     

13 Nov, 2013

1 commit

  • When devpts is unmounted, there may be a no-longer-used IDR tree hanging
    off the superblock we are about to kill. This needs to be cleaned up
    before destroying the SB.

    The leak is usually not a big deal because unmounting devpts is typically
    done when shutting down the whole machine. However, shutting down an LXC
    container instead of a physical machine exposes the problem (the garbage
    is detectable with kmemleak).

    Signed-off-by: Ilija Hadzic
    Cc: Sukadev Bhattiprolu
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ilija Hadzic
     

27 Jan, 2013

1 commit

  • - The context in which devpts is mounted has no effect on the creation
    of ptys as the /dev/ptmx interface has been used by unprivileged
    users for many years.

    - Only support unprivileged mounts in combination with the newinstance
    option to ensure that mounting of /dev/pts in a user namespace will
    not allow the options of an existing mount of devpts to be modified.

    - Create /dev/pts/ptmx as the root user in the user namespace that
    mounts devpts so that it's permissions to be changed.

    Acked-by: Serge Hallyn
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     

23 Oct, 2012

4 commits

  • Add kernel-doc texts for some devpts functions, i.e. document them.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • The goal is to stop setting and using tty->driver_data in devpts code.
    It should be used solely by the driver's code, pty in this case.

    Now driver_data are managed only in the pty driver. devpts_pty_new is
    switched to accept what we used to dig out of tty_struct, i.e. device
    node number and index.

    This also removes a note about driver_data being set outside of the
    driver.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • The goal is to stop setting and using tty->driver_data in devpts code.
    It should be used solely by the driver's code, pty in this case.

    For the cleanup of layering, we will need the inode created in
    devpts_pty_new to be stored into slave's driver_data. So we convert
    devpts_pty_new to return the inode or an ERR_PTR-encoded error in case
    of failure.

    The move of 'inode = new_inode(sb);' from declarators to the code is
    only cosmetical, but it makes the code easier to read.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • The goal is to stop setting and using tty->driver_data in devpts code.
    It should be used solely by the driver's code, pty in this case.

    First, here we remove TTY from devpts_get_tty and rename it to
    devpts_get_priv. Note we do not remove type safety, we just shift the
    [implicit] (void *) cast one layer up.

    index was unused in devpts_get_tty, so remove that from the prototype
    too.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

14 Jul, 2012

1 commit

  • Pass mount flags to sget() so that it can use them in initialising a new
    superblock before the set function is called. They could also be passed to the
    compare function.

    Signed-off-by: David Howells
    Signed-off-by: Al Viro

    David Howells
     

16 May, 2012

1 commit


22 Mar, 2012

1 commit

  • Pull vfs pile 1 from Al Viro:
    "This is _not_ all; in particular, Miklos' and Jan's stuff is not there
    yet."

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (64 commits)
    ext4: initialization of ext4_li_mtx needs to be done earlier
    debugfs-related mode_t whack-a-mole
    hfsplus: add an ioctl to bless files
    hfsplus: change finder_info to u32
    hfsplus: initialise userflags
    qnx4: new helper - try_extent()
    qnx4: get rid of qnx4_bread/qnx4_getblk
    take removal of PF_FORKNOEXEC to flush_old_exec()
    trim includes in inode.c
    um: uml_dup_mmap() relies on ->mmap_sem being held, but activate_mm() doesn't hold it
    um: embed ->stub_pages[] into mmu_context
    gadgetfs: list_for_each_safe() misuse
    ocfs2: fix leaks on failure exits in module_init
    ecryptfs: make register_filesystem() the last potential failure exit
    ntfs: forgets to unregister sysctls on register_filesystem() failure
    logfs: missing cleanup on register_filesystem() failure
    jfs: mising cleanup on register_filesystem() failure
    make configfs_pin_fs() return root dentry on success
    configfs: configfs_create_dir() has parent dentry in dentry->d_parent
    configfs: sanitize configfs_create()
    ...

    Linus Torvalds
     

21 Mar, 2012

1 commit


25 Jan, 2012

2 commits

  • After adding devpts multiple-insrances sysctl kernel.pty.max limit pty count for
    each devpts instance independently, while kernel.pty.nr shows total pty count.

    This patch restores sysctl kernel.pty.max as global limit (4096 by default),
    adds pty reseve for main devpts (mounted without "newinstance" argument),
    and new sysctl to tune it: kernel.pty.reserve (1024 by default)

    Also it adds devpts mount option "max=%d" to limit pty count for each devpts
    instance independently. (by default NR_UNIX98_PTY_MAX == 2^20)

    Thus devpts instances in containers cannot eat up all available pty even if we didn't
    set any limits, while with "max" argument we can adjust limits more precisely.

    Plus, now open("/dev/ptmx") return -ENOSPC in case lack of pty indexes,
    this is more informative than -EIO.

    Signed-off-by: Konstantin Khlebnikov
    Signed-off-by: Greg Kroah-Hartman

    Konstantin Khlebnikov
     
  • Let's move this stuff to the better place, where we can account pty right in
    tty-indexes managing code.

    Signed-off-by: Konstantin Khlebnikov
    Signed-off-by: Greg Kroah-Hartman

    Konstantin Khlebnikov