Re: [PATCH 1/5] tty: remove TTY_MAGIC

From: Jiri Slaby
Date: Fri Sep 16 2022 - 04:46:00 EST


On 16. 09. 22, 9:33, Theodore Ts'o wrote:
On Fri, Sep 16, 2022 at 03:54:59AM +0200, наб wrote:
According to Greg, in the context of magic numbers as defined in
magic-number.rst, "the tty layer should not need this and I'll gladly
take patches"

Ref: https://lore.kernel.org/linux-doc/YyMlovoskUcHLEb7@xxxxxxxxx/

Well, I would disagree with Greg K-H on this --- but I haven't been
tty maintainer in well over a decade. Assuming code is Bug-Free(tm),
sure, it's not necessary. But there is any kind of memory bug (e.g.,
a corrupted pointer,

I don't think it can help with corrupted pointer much, but:

a use-after free, some other structure
corruption), this catches the problem earlier rather than later, and
it's a light-weight to do a quick sanity check.

Although it's light-weight, it's also NOT that useful. Maybe tty _userspace_ functions return EIO, but that's about it (kernel does not check magic in any of its code paths, if I am looking correctly). I bet users would notice a corrupted tty structure even without this, and maybe earlier. And in that case, kmemcheck is next on the list. And that tells us much more than "we are corrupted".

It has certainly caught problems in the past, and I still use this
programming technique in programs that I do maintain, such as
e2fsprogs.

Asking google about:
"tty_paranoia_check" "bad magic number"
gives ~149 results, the last one from 2008. And it seems to be the only report, the others are links to sources. So yes, it triggered at least once, but is it that useful? Looking at the results, I don't think so.

thanks,
--
js
suse labs