]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
powerpc/lib: Validate size for vector operations
authorNaveen N Rao <naveen@kernel.org>
Thu, 23 Nov 2023 07:17:05 +0000 (12:47 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Feb 2024 07:54:37 +0000 (08:54 +0100)
[ Upstream commit 8f9abaa6d7de0a70fc68acaedce290c1f96e2e59 ]

Some of the fp/vmx code in sstep.c assume a certain maximum size for the
instructions being emulated. The size of those operations however is
determined separately in analyse_instr().

Add a check to validate the assumption on the maximum size of the
operations, so as to prevent any unintended kernel stack corruption.

Signed-off-by: Naveen N Rao <naveen@kernel.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Build-tested-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231123071705.397625-1-naveen@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/powerpc/lib/sstep.c

index 2d39b7c246e30ab72c71d7732d85b7ac9df6f74c..ecc2e06854d74376ad432c6385cfa9dc55d6b33b 100644 (file)
@@ -529,6 +529,8 @@ static int do_fp_load(struct instruction_op *op, unsigned long ea,
        } u;
 
        nb = GETSIZE(op->type);
+       if (nb > sizeof(u))
+               return -EINVAL;
        if (!address_ok(regs, ea, nb))
                return -EFAULT;
        rn = op->reg;
@@ -579,6 +581,8 @@ static int do_fp_store(struct instruction_op *op, unsigned long ea,
        } u;
 
        nb = GETSIZE(op->type);
+       if (nb > sizeof(u))
+               return -EINVAL;
        if (!address_ok(regs, ea, nb))
                return -EFAULT;
        rn = op->reg;
@@ -623,6 +627,9 @@ static nokprobe_inline int do_vec_load(int rn, unsigned long ea,
                u8 b[sizeof(__vector128)];
        } u = {};
 
+       if (size > sizeof(u))
+               return -EINVAL;
+
        if (!address_ok(regs, ea & ~0xfUL, 16))
                return -EFAULT;
        /* align to multiple of size */
@@ -650,6 +657,9 @@ static nokprobe_inline int do_vec_store(int rn, unsigned long ea,
                u8 b[sizeof(__vector128)];
        } u;
 
+       if (size > sizeof(u))
+               return -EINVAL;
+
        if (!address_ok(regs, ea & ~0xfUL, 16))
                return -EFAULT;
        /* align to multiple of size */