[syzbot] linux-next boot error: general protection fault in add_mtd_device

Linus Torvalds torvalds at linux-foundation.org
Sun Jul 24 11:21:20 PDT 2022


On Sat, Jul 23, 2022 at 6:34 PM Tetsuo Handa
<penguin-kernel at i-love.sakura.ne.jp> wrote:
>
> Linus, can we have macros like valid_kernel_ptr() ? Macros like
> valid_kernel_ptr(), valid_kernel_ptr_or_null(), valid_kernel_ptr_or_err() can
> serve for documentation purpose without runtime cost for non-debug builds.

No. We have IS_ERR_OR_NULL(), but validating a kernel pointer in
general is pretty much impossible.

You can try to just dereference it - and it's even fairly efficient if
the exception case is supposed to be very rare.

But even that is not really "safe", in that it can cause IO accesses
etc.  Plus it fundamentally cannot catch the likely case - the pointer
"works", but it's simply stale and doesn't point to the right data.

And honestly, even if the pointer doesn't actually "work" as a
pointer, you are actually much better off taking the exception at that
point, and getting an oops, and just FIXING THE BUG instead.

Having some model where "this pointer fails, so I'll just do something
else" is completely and utterly wrong.

It's bad for debugging, and it's impossible for any real use.

So the whole notion of "is this pointer safe" is garbage.

The only way to make sure a pointer is safe is to just make sure it's
initialized properly. Once you start using random pointers, all bets
are off, and no amount of "let's verify this" will ever help at all.
It will only hurt.

           Linus



More information about the linux-mtd mailing list