[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e297ba05-e82d-d269-20d2-5bd3914b1d14@c-s.fr>
Date: Tue, 23 Apr 2019 11:26:39 +0200
From: Christophe Leroy <christophe.leroy@....fr>
To: Michael Ellerman <mpe@...erman.id.au>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Paul Mackerras <paulus@...ba.org>, ruscur@...sell.cc
Cc: linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org
Subject: Re: [PATCH v2 10/10] powerpc/32s: Implement Kernel Userspace Access
Protection
Le 18/04/2019 à 08:55, Michael Ellerman a écrit :
> Christophe Leroy <christophe.leroy@....fr> writes:
>> diff --git a/arch/powerpc/include/asm/book3s/32/kup.h b/arch/powerpc/include/asm/book3s/32/kup.h
>> index 5f97c742ca71..b3560b2de435 100644
>> --- a/arch/powerpc/include/asm/book3s/32/kup.h
>> +++ b/arch/powerpc/include/asm/book3s/32/kup.h
>> @@ -37,6 +37,113 @@
> ...
>> +
>> +static inline void allow_user_access(void __user *to, const void __user *from, u32 size)
>> +{
>> + u32 addr = (__force u32)to;
>> + u32 end = min(addr + size, TASK_SIZE);
>> +
>> + if (!addr || addr >= TASK_SIZE || !size)
>> + return;
>> +
>> + current->thread.kuap = (addr & 0xf0000000) | ((((end - 1) >> 28) + 1) & 0xf);
>> + kuap_update_sr(mfsrin(addr) & ~SR_KS, addr, end); /* Clear Ks */
>> +}
>
> When rebasing on my v6 I changed the above to:
>
> static inline void allow_user_access(void __user *to, const void __user *from, u32 size)
> {
> u32 addr, end;
>
> if (__builtin_constant_p(to) && to == NULL)
> return;
Good point, it avoids keeping the test compiled in when the 'to' is not
NULL.
>
> addr = (__force u32)to;
>
> if (!addr || addr >= TASK_SIZE || !size)
> return;
Then the !addr test isn't needed anymore I think.
Christophe
>
> end = min(addr + size, TASK_SIZE);
> current->thread.kuap = (addr & 0xf0000000) | ((((end - 1) >> 28) + 1) & 0xf);
> kuap_update_sr(mfsrin(addr) & ~SR_KS, addr, end); /* Clear Ks */
> }
>
> Which I think achieves the same result. It does boot :)
>
>> +
>> +static inline void prevent_user_access(void __user *to, const void __user *from, u32 size)
>> +{
>> + u32 addr = (__force u32)to;
>> + u32 end = min(addr + size, TASK_SIZE);
>> +
>> + if (!addr || addr >= TASK_SIZE || !size)
>> + return;
>> +
>> + current->thread.kuap = 0;
>> + kuap_update_sr(mfsrin(addr) | SR_KS, addr, end); /* set Ks */
>> +}
>> +
>> +static inline void allow_read_from_user(const void __user *from, unsigned long size)
>> +{
>> +}
>
> And I dropped that.
>
> cheers
>
Powered by blists - more mailing lists