The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
	Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	Andrew Morton <akpm@linux-foundation.org>,
	Daniel Starke <daniel.starke@siemens.com>,
	syzbot <syzbot+dbac96d8e73b61aa559c@syzkaller.appspotmail.com>
Subject: Re: [PATCH] tty: add the option to have a tty reject a new ldisc
Date: Wed, 24 Apr 2024 08:25:12 +0200	[thread overview]
Message-ID: <b914dbad-858c-42eb-80be-337e69f189e4@kernel.org> (raw)
In-Reply-To: <20240423163339.59780-1-torvalds@linux-foundation.org>

On 23. 04. 24, 18:33, Linus Torvalds wrote:
> ... and use it to limit the virtual terminals to just N_TTY.  They are
> kind of special, and in particular, the "con_write()" routine violates
> the "writes cannot sleep" rule that some ldiscs rely on.
> 
> This avoids the
> 
>     BUG: sleeping function called from invalid context at kernel/printk/printk.c:2659
> 
> when N_GSM has been attached to a virtual console, and gsmld_write()
> calls con_write() while holding a spinlock, and con_write() then tries
> to get the console lock.
...> --- a/drivers/tty/tty_ldisc.c
> +++ b/drivers/tty/tty_ldisc.c
> @@ -545,6 +545,12 @@ int tty_set_ldisc(struct tty_struct *tty, int disc)
>   		goto out;
>   	}
>   
> +	if (tty->ops->ldisc_ok) {




> +		retval = tty->ops->ldisc_ok(tty, disc);
> +		if (retval)
> +			goto out;

This caught my eye as it looks like:
if (ldisc_ok)
   die;

Perhaps dub it ldisc_check()? Alternatively, make it return a bool and 
invert the logic here? That would make the ugly ternary in 
con_ldisc_ok() go away too.

But whatever, it finally evades that group of bugs.

Now, I am not sure what the problem with attaching some weird ldisc to a 
pty was. I will take a look next week (I am unavailable ATM).

thanks,
-- 
js
suse labs


      reply	other threads:[~2024-04-24  6:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-23 16:33 [PATCH] tty: add the option to have a tty reject a new ldisc Linus Torvalds
2024-04-24  6:25 ` Jiri Slaby [this message]

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=b914dbad-858c-42eb-80be-337e69f189e4@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=daniel.starke@siemens.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=syzbot+dbac96d8e73b61aa559c@syzkaller.appspotmail.com \
    --cc=torvalds@linux-foundation.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