[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wgjZ0DJgeo5Sk-Kc5vw8TXGuxXftPV79Wv221ncstk1tA@mail.gmail.com>
Date: Sun, 21 Apr 2024 09:04:31 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Jiri Slaby <jirislaby@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>, "Starke, Daniel" <daniel.starke@...mens.com>,
LKML <linux-kernel@...r.kernel.org>,
linux-security-module <linux-security-module@...r.kernel.org>
Subject: Re: [PATCH v2] tty: n_gsm: restrict tty devices to attach
On Sun, 21 Apr 2024 at 06:28, Tetsuo Handa
<penguin-kernel@...ove.sakura.ne.jp> wrote:
>
> "struct tty_ldisc_ops" says that ->write() function (e.g. gsmld_write())
> is allowed to sleep and "struct tty_operations" says that ->write() function
> (e.g. con_write()) is not allowed to sleep.
Well, clearly con_write() *is* allowed to sleep. The very first thing
it does is that
console_lock();
thing, which uses a sleeping semaphore.
But yes, the comment in the header does say "may not sleep".
Clearly that comment doesn't actually reflect reality - and never did.
The console lock sleeping isn't some new thing (ie it doesn't come
from the somewhat recent printk changes).
So the comment is bogus and wrong.
> Thus, I initially proposed
> https://lkml.kernel.org/r/9cd9d3eb-418f-44cc-afcf-7283d51252d6@I-love.SAKURA.ne.jp
> which makes con_write() no-op when called with IRQs disabled.
The thing is, that's not the only thing that makes atomic context.
And some atomic contexts cannot be detected at run-time, they are
purely static (ie being inside a spinlock withg a !PREEMPT kernel
build).
So you cannot test for this.
The only option is to *mark* the ones that are atomic. Which was my suggestion.
> My major/minor approach is based on a suggestion from Jiri that we just somehow
> disallow attaching this line discipline to a console
Since we already know that the comment is garbage, why do you think
it's just a con_write() that has this issue?
And if it is only the console that has this issue, why are you testing
for other major/minor numbers?
> Now, your 'struct tty_operations' flag saying 'my ->write() function is OK with
> atomic context' is expected to be set to all drivers.
I'm not convinced. The only thing I know is that the comment in
question is wrong, and has been wrong for over a decade (and honestly,
probably pretty much forever).
So how confident are we that other tty write functions are ok?
Also, since you think that only con_write() has a problem, why the
heck are you then testing for ptys etc? From a quick check, the
pty->ops->write() function is fine.
Linus
Powered by blists - more mailing lists