Re: [PATCH] x86/dumpstack: Dump user space code correctly again

From: Thomas Gleixner
Date: Thu Jul 23 2020 - 07:05:47 EST


Christoph Hellwig <hch@xxxxxx> writes:
> On Wed, Jul 22, 2020 at 07:54:15PM +0200, Thomas Gleixner wrote:
>> + /*
>> + * Make sure userspace isn't trying to trick us into dumping kernel
>> + * memory by pointing the userspace instruction pointer at it.
>> + */
>> + if (__chk_range_not_ok(src, nbytes, TASK_SIZE_MAX))
>> + return -EINVAL;
>> +
>> + return copy_from_user_nmi(buf, (void __user *)src, nbytes);
>
> copy_from_user_nmi already contains a:
>
> if (__range_not_ok(from, n, TASK_SIZE))
> return n;
>
> what is the reason it checks for TASK_SIZE vs TASK_SIZE_MAX, and why
> do we need both checks?

TBH, I just kept it because being lazy. But you are right, the check is
redundant and TASK_SIZE_MAX is inaccurate as it does not take compat
tasks into account. I'll rip that out.

Thanks,

tglx