public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Gui-Dong Han <2045gemini@gmail.com>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	jirislaby@kernel.org, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org, baijiaju1990@outlook.com,
	stable@vger.kernel.org
Subject: Re: [PATCH] tty: fix atomicity violation in n_tty_read
Date: Sun, 14 Jan 2024 14:43:02 -0500	[thread overview]
Message-ID: <20240114194302.GC911245@mit.edu> (raw)
In-Reply-To: <CAOPYjvZYdPSiZ+jX4vhwPQ3AKRvW15XT1znAa8vd9a6DVoor5w@mail.gmail.com>

On Sat, Jan 13, 2024 at 12:59:11AM +0800, Gui-Dong Han wrote:
> 
> I apologize for any confusion caused by my reference to Linux 5.17 in
> the patch description. I'm currently working on a project involving
> kernel static analysis to identify atomicity violations, and part of
> this work involves comparison with a previous study that supports up
> to Linux 5.17. Therefore, I initially ran my tool on 5.17 to filter
> potential bugs that are still unaddressed in the upstream. I want to
> clarify that the patch was developed and tested on linux-next. I
> realize now that this may have led to misunderstandings, and I will
> ensure clearer communication in future submissions.
> My experience with Linux kernel contributions is still growing, and I
> acknowledge that my recent submission might have been hasty and lacked
> thorough consideration, especially regarding the critical nature of
> n_tty_read and the potential impacts of the patch, like performance
> concerns. I will take more care in future assessments before
> submitting patches and continue to familiarize myself with the rules
> and practices of the Linux kernel community.

In general, static analysis tools need to be supplemented by an
attempt to understand what the code is trying to do.  This code is
related to the packet mode, which is related to pseudo-tty's --- *not*
the linux serial driver.

From the man page for tty_ioctl:

       TIOCPKT
              Argument: const int *argp

              Enable (when *argp is nonzero) or disable packet mode.
              Can be applied to the master side of a pseudoterminal
              only (and will return ENOTTY otherwise).  In packet
              mode, each subsequent read(2) will return a packet that
              either contains a single nonzero control byte, or has a
              single byte containing zero ('\0') followed by data
              written on the slave side of the pseudoterminal.  If the
              first byte is not TI‐ OCPKT_DATA (0), it is an OR of one
              or more of the following bits:

              TIOCPKT_FLUSHREAD    The read queue for the terminal is flushed.
              TIOCPKT_FLUSHWRITE   The write queue for the terminal is flushed.
              TIOCPKT_STOP         Output to the terminal is stopped.
              TIOCPKT_START        Output to the terminal is restarted.
              TIOCPKT_DOSTOP       The start and stop characters are ^S/^Q.

              TIOCPKT_NOSTOP       The start and stop characters are not ^S/^Q.

              While  packet  mode is in use, the presence of control status informa‐
              tion to be read from the master side may be detected  by  a  select(2)
              for exceptional conditions or a poll(2) for the POLLPRI event.

              This  mode  is used by rlogin(1) and rlogind(8) to implement a remote-
              echoed, locally ^S/^Q flow-controlled remote login.

The n_tty_read() function is called by the userspace program on the
master side of the pty pair.  This is not, strictly speaking a hot
path; it's not on the interrupt service path of the serial driver, for
example.  So it's unliklely that "fixing" this problem is going to
result an measurable performance impact.

It's also the case that not taking the spinlock before checking the
packet mode is not necessarily going to be disastrous.  Yes, it might
mean that when the user types ^S, sshd might not stop sending
characters to the client right away, and the status report about the
status of the pty gets delayed by a millisecond or two.

So it's actually *not* a big deal.  Now, if you want to make the
argument that it would be nice if these sorts of "false positives" are
suppressed so that it's easier to find real bugs, that's one thing.
But if you're looking at proof that your static checker is actually
fixing Real Bugs (tm), this is probably not the best example.

Cheers,

					- Ted

  reply	other threads:[~2024-01-14 19:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-12 12:58 [PATCH] tty: fix atomicity violation in n_tty_read Gui-Dong Han
2024-01-12 13:48 ` Greg KH
2024-01-12 16:59   ` Gui-Dong Han
2024-01-14 19:43     ` Theodore Ts'o [this message]
2024-01-16  8:29 ` kernel test robot
2024-01-16 10:14 ` Ilpo Järvinen
2024-02-01  9:02 ` This is classified as spam [was: [PATCH] tty: fix atomicity violation in n_tty_read] Jiri Slaby
2024-02-01 14:23   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240114194302.GC911245@mit.edu \
    --to=tytso@mit.edu \
    --cc=2045gemini@gmail.com \
    --cc=baijiaju1990@outlook.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox