• P
    n_tty: Fix unsafe update of available buffer space · b8483052
    Peter Hurley 提交于
    receive_room is used to control the amount of data the flip
    buffer work can push to the read buffer. This update is unsafe:
    
      CPU 0                        |  CPU 1
                                   |
                                   | n_tty_read()
                                   |   n_tty_set_room()
                                   |     left = <calc of space>
    n_tty_receive_buf()            |
      <push data to buffer>        |
      n_tty_set_room()             |
        left = <calc of space>     |
        tty->receive_room = left   |
                                   |     tty->receive_room = left
    
    receive_room is now updated with a stale calculation of the
    available buffer space, and the subsequent work loop will likely
    overwrite unread data in the input buffer.
    
    Update receive_room atomically with the calculation of the
    available buffer space.
    Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    b8483052
n_tty.c 55.3 KB