Re: [PATCH 1/3] lib/test_printf: Clean up test of hashed pointers

From: Petr Mladek
Date: Mon Mar 02 2020 - 05:24:33 EST


On Thu 2020-02-27 15:30:51, Uwe Kleine-König wrote:
> Hello Petr,
>
> On 2/27/20 2:01 PM, Petr Mladek wrote:
> > The commit ad67b74d2469d9b82a ("printk: hash addresses printed with %p")
> > helps to prevent leaking kernel addresses.
> >
> > The testing of this functionality is a bit problematic because the output
> > depends on a random key that is generated during boot. Though, it is
> > still possible to check some aspects:
> >
> > + output string length
> > + hash differs from the original pointer value
> > + top half bits are zeroed on 64-bit systems
>
> Is "hash differs from the original pointer value" a valid check?
> Depending on the random value and the actual pointer I can imagine a
> valid match. Such a match is unlikely but not necessarily bogus, is it?

Yes, there is a small risk or false negative.

It might be possible to try if the problem persist with PTR+1 value or
so. But I am not sure if it is worth it.

The problem is only on 32-bit systems. The chance is really small.
I have added a comment above the check. It can be found via the added
error message.

Note that this check has been there even before in plain_hash().
But it was worse because it was without any comment or error message.

Best Regards,
Petr