17 Oct, 2007

2 commits

  • This adds three new functions (or in one case to be more exact makes it
    always available)

    tty_termios_copy_hw

    Copies all the hardware settings from one termios structure to the other.
    This is intended for drivers that support little or no hardware setting

    tty_termios_encode_baud_rate

    Allows you to set the input and output baud rate in a termios structure. A
    driver is supposed to set the resulting baud rate from a request so most
    will want to use this function to set the resulting input and output rates
    to match the hardware values. Internally it knows about keeping Bxxx
    encoding when possible to maximise compatibility.

    tty_encode_baud_rate

    As above but for the tty's own current termios structure

    I suspect this will initially need some tweaking as it gets enabled by
    driver patches over the next few mm cycles so consider this lot -mm only
    for the moment so it can stabilize and end up neat before it goes to base.

    I've tried not to break any obscure architectures - if you get a speed you
    can't represent the code will print warnings on non updated termios systems
    but not break.

    Once this is merged and seems sane I've got a growing pile of driver
    updates to use it - notably for USB serial drivers.

    [akpm@linux-foundation.org: cleanups]
    Signed-off-by: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     
  • No longer used. TTY_FLIPBUF_SIZE will also go soon but needs a couple of
    other cleanups first

    Signed-off-by: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     

13 Oct, 2007

1 commit


12 Aug, 2007

1 commit

  • Patch c5c34d4862e18ef07c1276d233507f540fb5a532 (tty: flush flip buffer on
    ldisc input queue flush) introduces a race condition which can lead to memory
    leaks.

    The problem can be triggered when tcflush() is called when data are being
    pushed to the line discipline driver by flush_to_ldisc().

    flush_to_ldisc() releases tty->buf.lock when calling the line discipline
    receive_buf function. At that poing tty_buffer_flush() kicks in and sets both
    tty->buf.head and tty->buf.tail to NULL. When flush_to_ldisc() finishes, it
    restores tty->buf.head but doesn't touch tty->buf.tail. This corrups the
    buffer queue, and the next call to tty_buffer_request_room() will allocate a
    new buffer and overwrite tty->buf.head. The previous buffer is then lost
    forever without being released.

    (Thanks to Laurent for the above text, for finding, disgnosing and reporting
    the bug)

    - Use tty->flags bits for the flush status.

    - Wait for the flag to clear again before returning

    - Fix the doc error noted

    - Fix flush of empty queue leaving stale flushpending

    [akpm@linux-foundation.org: cleanup]
    Signed-off-by: Alan Cox
    Acked-by: Paul Fulghum
    Cc: Laurent Pinchart
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     

17 Jul, 2007

2 commits

  • Add TTY input auditing, used to audit system administrator's actions. This is
    required by various security standards such as DCID 6/3 and PCI to provide
    non-repudiation of administrator's actions and to allow a review of past
    actions if the administrator seems to overstep their duties or if the system
    becomes misconfigured for unknown reasons. These requirements do not make it
    necessary to audit TTY output as well.

    Compared to an user-space keylogger, this approach records TTY input using the
    audit subsystem, correlated with other audit events, and it is completely
    transparent to the user-space application (e.g. the console ioctls still
    work).

    TTY input auditing works on a higher level than auditing all system calls
    within the session, which would produce an overwhelming amount of mostly
    useless audit events.

    Add an "audit_tty" attribute, inherited across fork (). Data read from TTYs
    by process with the attribute is sent to the audit subsystem by the kernel.
    The audit netlink interface is extended to allow modifying the audit_tty
    attribute, and to allow sending explanatory audit events from user-space (for
    example, a shell might send an event containing the final command, after the
    interactive command-line editing and history expansion is performed, which
    might be difficult to decipher from the TTY input alone).

    Because the "audit_tty" attribute is inherited across fork (), it would be set
    e.g. for sshd restarted within an audited session. To prevent this, the
    audit_tty attribute is cleared when a process with no open TTY file
    descriptors (e.g. after daemon startup) opens a TTY.

    See https://www.redhat.com/archives/linux-audit/2007-June/msg00000.html for a
    more detailed rationale document for an older version of this patch.

    [akpm@linux-foundation.org: build fix]
    Signed-off-by: Miloslav Trmac
    Cc: Al Viro
    Cc: Alan Cox
    Cc: Paul Fulghum
    Cc: Casey Schaufler
    Cc: Steve Grubb
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Miloslav Trmac
     
  • Without this a tty write could block if a previous blocking tty write was
    in progress on the same tty and blocked by a line discipline or hardware
    event. Originally found and reported by Dave Johnson.

    Signed-off-by: Alan Cox
    Acked-by: Dave Johnson
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     

09 May, 2007

1 commit

  • While researching the tty layer pid leaks I found a weird case in selinux when
    we drop a controlling tty because of inadequate permissions we don't do the
    normal hangup processing. Which is a problem if it happens the session leader
    has exec'd something that can no longer access the tty.

    We already have code in the kernel to handle this case in the form of the
    TIOCNOTTY ioctl. So this patch factors out a helper function that is the
    essence of that ioctl and calls it from the selinux code.

    This removes the inconsistency in handling dropping of a controlling tty and
    who knows it might even make some part of user space happy because it received
    a SIGHUP it was expecting.

    In addition since this removes the last user of proc_set_tty outside of
    tty_io.c proc_set_tty is made static and removed from tty.h

    Signed-off-by: Eric W. Biederman
    Acked-by: Alan Cox
    Cc: James Morris
    Cc: Stephen Smalley
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric W. Biederman
     

13 Feb, 2007

3 commits

  • Of kernel subsystems that work with pids the tty layer is probably the largest
    consumer. But it has the nice virtue that the assiation with a session only
    lasts until the session leader exits. Which means that no reference counting
    is required. So using struct pid winds up being a simple optimization to
    avoid hash table lookups.

    In the long term the use of pid_nr also ensures that when we have multiple pid
    spaces mixed everything will work correctly.

    Signed-off-by: Eric W. Biederman
    Cc: Alan Cox
    Cc: Oleg Nesterov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric W. Biederman
     
  • Every call to is_orphaned_pgrp passed in process_group(current) which is racy
    with respect to another thread changing our process group. It didn't bite us
    because we were dealing with integers and the worse we would get would be a
    stale answer.

    In switching the checks to use struct pid to be a little more efficient and
    prepare the way for pid namespaces this race became apparent.

    So I simplified the calls to the more specialized is_current_pgrp_orphaned so
    I didn't have to worry about making logic changes to avoid the race.

    Signed-off-by: Eric W. Biederman
    Cc: Alan Cox
    Cc: Oleg Nesterov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric W. Biederman
     
  • The aim of this patch set is to start wrapping up the struct pid conversions.
    As such this patchset culminates with the removal of kill_pg, kill_pg_info,
    __kill_pg_info, do_each_task_pid, and while_each_task_pid.

    kill_proc, daemonize, and kernel_thread are still in my sights but there is
    still work to get to them.

    The first three are basic cleanups around disassociate_ctty, while working on
    converting it I found several issues. tty_old_pgrp can be a tricky concept to
    wrap your head around.

    1 tty: Make __proc_set_tty static.
    2 tty: Clarify disassociate_ctty
    3 tty: Fix the locking for signal->session in disassociate_ctty

    These just stop using the old helper functions.

    4 signal: Use kill_pgrp not kill_pg in the sunos compatibility code.
    5 signal: Rewrite kill_something_info so it uses newer helpers.

    Then the grind to convert the tty layer and all of it's helper functions to
    struct pid.

    6 pid: Make session_of_pgrp use struct pid instead of pid_t.
    7 pid: Use struct pid for talking about process groups in exit.c
    8 pid: Replace is_orphaned_pgrp with is_current_pgrp_orphaned
    9 tty: Update the tty layer to work with struct pid.

    A final helper function update.

    10 pid: Replace do/while_each_task_pid with do/while_each_pid_task

    And the removal of the functions that are now unused.
    11 pid: Remove now unused do_each_task_pid and while_each_task_pid
    12 pid: Remove the now unused kill_pg kill_pg_info and __kill_pg_info

    All of these should be fairly simple and to the point.

    This patch:

    Currently all users of __proc_set_tty are in tty_io.c so make the function
    static.

    Signed-off-by: Eric W. Biederman
    Cc: Alan Cox
    Cc: Oleg Nesterov
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric W. Biederman
     

12 Feb, 2007

2 commits

  • The line discipline numbers N_* are currently defined for each architecture
    individually, but (except for a seeming mistake) identically, in
    asm/termios.h. There is no obvious reason why these numbers should be
    architecture specific, nor any apparent relationship with the termios
    structure. The total number of these, NR_LDISCS, is defined in linux/tty.h
    anyway. So I propose the following patch which moves the definitions of
    the individual line disciplines to linux/tty.h too.

    Three of these numbers (N_MASC, N_PROFIBUS_FDL, and N_SMSBLOCK) are unused
    in the current kernel, but the patch still keeps the complete set in case
    there are plans to use them yet.

    Signed-off-by: Tilman Schmidt
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tilman Schmidt
     
  • This does several things.
    - It moves looking up of the current foreground console into process
    context where we can safely take the semaphore that protects this
    operation.
    - It uses the new flavor of work queue processing.
    - This generates a factor of do_SAK, __do_SAK that runs immediately.
    - This calls __do_SAK with the console semaphore held ensuring nothing
    else happens to the console while we process the SAK operation.
    - With the console SAK processing moved into process context this
    patch removes the xchg operations that I used to attempt to attomically
    update struct pid, because of the strange locking used in the SAK processing.
    With SAK using the normal console semaphore nothing special is needed.

    Cc: Oleg Nesterov
    Signed-off-by: Eric W. Biederman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric W. Biederman
     

09 Dec, 2006

2 commits

  • This is the core of the switch to the new framework. I've split it from the
    driver patches which are mostly search/replace and would encourage people to
    give this one a good hard stare.

    The references to BOTHER and ISHIFT are the termios values that must be
    defined by a platform once it wants to turn on "new style" ioctl support. The
    code patches here ensure that providing

    1. The termios overlays the ktermios in memory
    2. The only new kernel only fields are c_ispeed/c_ospeed (or none)

    the existing behaviour is retained. This is true for the patches at this
    point in time.

    Future patches will define BOTHER, ISHIFT and enable newer termios structures
    for each architecture, and once they are all done some of the ifdefs also
    vanish.

    [akpm@osdl.org: warning fix]
    [akpm@osdl.org: IRDA fix]
    Signed-off-by: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     
  • Fix the locking of signal->tty.

    Use ->sighand->siglock to protect ->signal->tty; this lock is already used
    by most other members of ->signal/->sighand. And unless we are 'current'
    or the tasklist_lock is held we need ->siglock to access ->signal anyway.

    (NOTE: sys_unshare() is broken wrt ->sighand locking rules)

    Note that tty_mutex is held over tty destruction, so while holding
    tty_mutex any tty pointer remains valid. Otherwise the lifetime of ttys
    are governed by their open file handles. This leaves some holes for tty
    access from signal->tty (or any other non file related tty access).

    It solves the tty SLAB scribbles we were seeing.

    (NOTE: the change from group_send_sig_info to __group_send_sig_info needs to
    be examined by someone familiar with the security framework, I think
    it is safe given the SEND_SIG_PRIV from other __group_send_sig_info
    invocations)

    [schwidefsky@de.ibm.com: 3270 fix]
    [akpm@osdl.org: various post-viro fixes]
    Signed-off-by: Peter Zijlstra
    Acked-by: Alan Cox
    Cc: Oleg Nesterov
    Cc: Prarit Bhargava
    Cc: Chris Wright
    Cc: Roland McGrath
    Cc: Stephen Smalley
    Cc: James Morris
    Cc: "David S. Miller"
    Cc: Jeff Dike
    Cc: Martin Schwidefsky
    Cc: Jan Kara
    Signed-off-by: Martin Schwidefsky
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Peter Zijlstra
     

05 Dec, 2006

1 commit


02 Dec, 2006

1 commit


22 Nov, 2006

1 commit

  • Separate delayable work items from non-delayable work items be splitting them
    into a separate structure (delayed_work), which incorporates a work_struct and
    the timer_list removed from work_struct.

    The work_struct struct is huge, and this limits it's usefulness. On a 64-bit
    architecture it's nearly 100 bytes in size. This reduces that by half for the
    non-delayable type of event.

    Signed-Off-By: David Howells

    David Howells
     

01 Oct, 2006

1 commit


30 Sep, 2006

2 commits


28 Aug, 2006

1 commit

  • Unlike the other tty comment patch this one has code changes. Specifically
    it limits the queue size for a tty to 64K characters (128Kbytes) worst case
    even if the tty is ignoring tty->throttle. This is because certain drivers
    don't honour the throttle value correctly, although it is a useful
    safeguard anyway.

    Signed-off-by: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     

11 Jul, 2006

2 commits

  • screen_info.h doesn't have anything to do with the tty layer and shouldn't be
    included by tty.h. This patches removes the include and modifies all users to
    directly include screen_info.h. struct screen_info is mainly used to
    communicate with the console drivers in drivers/video/console. Note that this
    patch touches every arch and I have no way of testing it. If there is a
    mistake the worst thing that will happen is a compile error.

    [akpm@osdl.org: fix arm build]
    [akpm@osdl.org: fix alpha build]
    Signed-off-by: Jon Smirl
    Signed-off-by: Antonino Daplas
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jon Smirl
     
  • MAX_NR_CONSOLES, fg_console, want_console and last_console are more of a
    function of the VT layer than the TTY one. Moving these to vt.h and vt_kern.h
    allows all of the framebuffer and VT console drivers to remove their
    dependency on tty.h.

    [akpm@osdl.org: fix alpha build]
    Signed-off-by: Jon Smirl
    Signed-off-by: Antonino Daplas
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jon Smirl
     

29 Jun, 2006

2 commits

  • Remove 'active' field from tty buffer structure. This was added in 2.6.16
    as part of a patch to make the new tty buffering SMP safe. This field is
    unnecessary with the more intelligently written flush_to_ldisc that adds
    receive_room handling.

    Removing this field reverts to simpler logic where the tail buffer is
    always the 'active' buffer, which should not be freed by flush_to_ldisc.
    (active == buffer being filled with new data)

    The result is simpler, smaller, and faster tty buffer code.

    Signed-off-by: Paul Fulghum
    Cc: Alan Cox
    Cc: Theodore Ts'o
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Paul Fulghum
     
  • Remove TTY_DONT_FLIP tty flag. This flag was introduced in 2.1.X kernels
    to prevent the N_TTY line discipline functions read_chan() and
    n_tty_receive_buf() from running at the same time. 2.2.15 introduced
    tty->read_lock to protect access to the N_TTY read buffer, which is the
    only state requiring protection between these two functions.

    The current TTY_DONT_FLIP implementation is broken for SMP, and is not
    universally honored by drivers that send data directly to the line
    discipline receive_buf function.

    Because TTY_DONT_FLIP is not necessary, is broken in implementation, and is
    not universally honored, it is removed.

    Signed-off-by: Paul Fulghum
    Cc: Alan Cox
    Cc: Theodore Ts'o
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Paul Fulghum
     

22 Jun, 2006

1 commit


26 Apr, 2006

1 commit


23 Mar, 2006

1 commit

  • Semaphore to mutex conversion.

    The conversion was generated via scripts, and the result was validated
    automatically via a script as well.

    Signed-off-by: Ingo Molnar
    Cc: Alan Cox
    Cc: Russell King
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ingo Molnar
     

11 Feb, 2006

1 commit

  • Prevent stalled processing of received data when a driver allocates tty
    buffer space but does not immediately follow the allocation with more data
    and a call to schedule receive tty processing. (example: hvc_console) This
    bug was introduced by the first locking patch for the new tty buffering.

    Signed-off-by: Paul Fulghum
    Cc: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Paul Fulghum
     

04 Feb, 2006

1 commit

  • Change locking in the new tty buffering facility from using tty->read_lock,
    which is currently ignored by drivers and thus ineffective. New locking
    uses a new tty buffering specific lock enforced centrally in the tty
    buffering code.

    Two drivers (esp and cyclades) are updated to use the tty buffering
    functions instead of accessing tty buffering internals directly. This is
    required for the new locking to work.

    Minor checks for NULL buffers added to
    tty_prepare_flip_string/tty_prepare_flip_string_flags

    Signed-off-by: Paul Fulghum
    Cc: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Paul Fulghum
     

11 Jan, 2006

1 commit

  • The API and code have been through various bits of initial review by
    serial driver people but they definitely need to live somewhere for a
    while so the unconverted drivers can get knocked into shape, existing
    drivers that have been updated can be better tuned and bugs whacked out.

    This replaces the tty flip buffers with kmalloc objects in rings. In the
    normal situation for an IRQ driven serial port at typical speeds the
    behaviour is pretty much the same, two buffers end up allocated and the
    kernel cycles between them as before.

    When there are delays or at high speed we now behave far better as the
    buffer pool can grow a bit rather than lose characters. This also means
    that we can operate at higher speeds reliably.

    For drivers that receive characters in blocks (DMA based, USB and
    especially virtualisation) the layer allows a lot of driver specific
    code that works around the tty layer with private secondary queues to be
    removed. The IBM folks need this sort of layer, the smart serial port
    people do, the virtualisers do (because a virtualised tty typically
    operates at infinite speed rather than emulating 9600 baud).

    Finally many drivers had invalid and unsafe attempts to avoid buffer
    overflows by directly invoking tty methods extracted out of the innards
    of work queue structs. These are no longer needed and all go away. That
    fixes various random hangs with serial ports on overflow.

    The other change in here is to optimise the receive_room path that is
    used by some callers. It turns out that only one ldisc uses receive room
    except asa constant and it updates it far far less than the value is
    read. We thus make it a variable not a function call.

    I expect the code to contain bugs due to the size alone but I'll be
    watching and squashing them and feeding out new patches as it goes.

    Because the buffers now dynamically expand you should only run out of
    buffering when the kernel runs out of memory for real. That means a lot of
    the horrible hacks high performance drivers used to do just aren't needed any
    more.

    Description:

    tty_insert_flip_char is an old API and continues to work as before, as does
    tty_flip_buffer_push() [this is why many drivers dont need modification]. It
    does now also return the number of chars inserted

    There are also

    tty_buffer_request_room(tty, len)

    which asks for a buffer block of the length requested and returns the space
    found. This improves efficiency with hardware that knows how much to
    transfer.

    and tty_insert_flip_string_flags(tty, str, flags, len)

    to insert a string of characters and flags

    For a smart interface the usual code is

    len = tty_request_buffer_room(tty, amount_hardware_says);
    tty_insert_flip_string(tty, buffer_from_card, len);

    More description!

    At the moment tty buffers are attached directly to the tty. This is causing a
    lot of the problems related to tty layer locking, also problems at high speed
    and also with bursty data (such as occurs in virtualised environments)

    I'm working on ripping out the flip buffers and replacing them with a pool of
    dynamically allocated buffers. This allows both for old style "byte I/O"
    devices and also helps virtualisation and smart devices where large blocks of
    data suddenely materialise and need storing.

    So far so good. Lots of drivers reference tty->flip.*. Several of them also
    call directly and unsafely into function pointers it provides. This will all
    break. Most drivers can use tty_insert_flip_char which can be kept as an API
    but others need more.

    At the moment I've added the following interfaces, if people think more will
    be needed now is a good time to say

    int tty_buffer_request_room(tty, size)

    Try and ensure at least size bytes are available, returns actual room (may be
    zero). At the moment it just uses the flipbuf space but that will change.
    Repeated calls without characters being added are not cumulative. (ie if you
    call it with 1, 1, 1, and then 4 you'll have four characters of space. The
    other functions will also try and grow buffers in future but this will be a
    more efficient way when you know block sizes.

    int tty_insert_flip_char(tty, ch, flag)

    As before insert a character if there is room. Now returns 1 for success, 0
    for failure.

    int tty_insert_flip_string(tty, str, len)

    Insert a block of non error characters. Returns the number inserted.

    int tty_prepare_flip_string(tty, strptr, len)

    Adjust the buffer to allow len characters to be added. Returns a buffer
    pointer in strptr and the length available. This allows for hardware that
    needs to use functions like insl or mencpy_fromio.

    Signed-off-by: Alan Cox
    Cc: Paul Fulghum
    Signed-off-by: Hirokazu Takata
    Signed-off-by: Serge Hallyn
    Signed-off-by: Jeff Dike
    Signed-off-by: John Hawkes
    Signed-off-by: Martin Schwidefsky
    Signed-off-by: Adrian Bunk
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     

09 Jan, 2006

1 commit


10 Sep, 2005

1 commit

  • Add rudimentary support by manipulating the VGA registers. However, not
    all vesa modes are VGA compatible, so VGA compatiblity is checked first.
    Only 2 levels are supported, powerup and powerdown.

    Signed-off-by: Antonino Daplas
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Antonino A. Daplas
     

24 Jun, 2005

1 commit


17 Apr, 2005

1 commit

  • Initial git repository build. I'm not bothering with the full history,
    even though we have it. We can create a separate "historical" git
    archive of that later if we want to, and in the meantime it's about
    3.2GB when imported into git - space that would just make the early
    git days unnecessarily complicated, when we don't have a lot of good
    infrastructure for it.

    Let it rip!

    Linus Torvalds