[PATCH] x86/shstk: Change order of __user in type

Rick Edgecombe posted 1 patch 2 years, 3 months ago
There is a newer version of this series
arch/x86/kernel/shstk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] x86/shstk: Change order of __user in type
Posted by Rick Edgecombe 2 years, 3 months ago
0day reports a sparse warning:
arch/x86/kernel/shstk.c:295:55: sparse: sparse: cast removes address space
'__user' of expression

The __user is in the wrong spot. Move it to right spot and make sparse
happy.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202308222312.Jt4Tog5T-lkp@intel.com/
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
---
 arch/x86/kernel/shstk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c
index cd10d074a444..fd689921a1db 100644
--- a/arch/x86/kernel/shstk.c
+++ b/arch/x86/kernel/shstk.c
@@ -275,7 +275,7 @@ static int shstk_push_sigframe(unsigned long *ssp)
 		return -EINVAL;
 
 	*ssp -= SS_FRAME_SIZE;
-	if (put_shstk_data((void *__user)*ssp, target_ssp))
+	if (put_shstk_data((void __user *)*ssp, target_ssp))
 		return -EFAULT;
 
 	return 0;
-- 
2.34.1
Re: [PATCH] x86/shstk: Change order of __user in type
Posted by Kees Cook 2 years, 3 months ago
On Thu, Aug 24, 2023 at 06:45:54PM -0700, Rick Edgecombe wrote:
> 0day reports a sparse warning:
> arch/x86/kernel/shstk.c:295:55: sparse: sparse: cast removes address space
> '__user' of expression
> 
> The __user is in the wrong spot. Move it to right spot and make sparse
> happy.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202308222312.Jt4Tog5T-lkp@intel.com/
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>

Ah yeah, a good find. I with we could sanely use "address spaces" in GCC
and Clang so we didn't need to depend on sparse for these checks. I
tried to get Clang doing it[1] a few years ago, but the wall of warnings
was huge.

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

[1] https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=clang/address_space&id=beff911c13390a71b3f7921fd82ec6a71ca75c02

-- 
Kees Cook