Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp143723rdb; Mon, 15 Jan 2024 15:45:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHr7hw3fiSap7VfMPBAWVMDqNjD6NyxGhKY2bJ/s2uC0m9AopsBSmuf+E9O6VM3lITUxZYe X-Received: by 2002:a05:6a20:918c:b0:19a:e201:3b1d with SMTP id v12-20020a056a20918c00b0019ae2013b1dmr4370054pzd.7.1705362355773; Mon, 15 Jan 2024 15:45:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705362355; cv=none; d=google.com; s=arc-20160816; b=a5CuREHZOtzw4C8xdXBIvwldDPHQ7bkqwRPD+5X4vS63NhX1A0Z67/LUyeRK9Vo8sh 6rgWY7UPIea9ll8/Mh10V8bp8JD4tpx2aiOquwTZqgdjoH0tiLkGtG69YseVckBpD6Gy 4ocMo3pC3NnS0hSwPumcAHaxaOu1XvJ9TexS6HYC65+FXqq8TzNIKyTqkiGwD5p1miCH +VFZvhQuxhwhIac+eGCw6aBkh076c7fbdjA1xlwhkrevLEB+9bHOfbKqwsbbviMX7WKB 2uNlxs6LBrlGnhcWxnv9yU92Fze7XngLVzCje/HElKU9lnaUoYrmB9k26XHokLi3nXrx wazA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=YZuf0VqdUcBkYDIvY7viFsIBz7oMsCdpww4/Qqct2GM=; fh=30SwNszRFCMR3ECSybIVMAhsM5YWddmpF8QJC5qQWJI=; b=zgxbkSLgc2Y8YFeGPA8TZq1uAp73UhlVbnNz7oF9rPC+4lRKgoeTfZylUMwemahcIo acNvKoZxKPBe3S8tCxnExXIG7nTwonVmWvL1wLBYhGOhFjfaCsGcf4MwwHP6nGgd2/LP mgCXRqQ4InhwjP3aBvFPqsr98o3h51yuPm/9PJH4Ay47A3pkTnU/Ykz2HWvsimeJpCSu nJq8wfzqczgKB1EEv+OK5FzcXCtHQV3sQPCRDGG9Ne4tojUWfCnr87nIlB2pmFuRteu0 zKi7T3bu36M/hp7iDgmef/FHnoXglSp1MoKCdPLvvwMoWcI19wcHVZo8YrKGmb9kwKGd MwQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Bj7o05n9; spf=pass (google.com: domain of linux-kernel+bounces-26567-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26567-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n36-20020a635924000000b005bdbf2ac2d2si9838135pgb.85.2024.01.15.15.45.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 15:45:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26567-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Bj7o05n9; spf=pass (google.com: domain of linux-kernel+bounces-26567-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26567-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 38E37283AE0 for ; Mon, 15 Jan 2024 23:35:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3BA220B39; Mon, 15 Jan 2024 23:26:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Bj7o05n9" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F422C20B21; Mon, 15 Jan 2024 23:26:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD7CAC43394; Mon, 15 Jan 2024 23:26:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705361203; bh=qDbhOQBbXTEZu7XYVNCaYPYNYZlxASCdbsVPh4RLvrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bj7o05n9gDJG6bDQv+XUObhMvrk9ZSyB710ow6JIXWSmDrFKdMRCviqpE7IaYHbgE ZcUWppCnS5X2iF3hYdtlSPr2hngdblvlMESS6Wb1qOdvjHhv/VtIGFSmWFlWucEdjM qQzY5oEDrQsk5uHmAEV948hfJeQJvvmiCruZzGySO5AVv970UpdHw9Qf1EBzWoHsiw WF732x/CqVh4jcXrpwW5NY2rIkNKpwLi/6lfiirUfzYyjTtEeg3iuudlaU+BAS1tje hR0MDqEMhvC8km/JgKNtdinlAGyGr1Rc1hJvrRcwCy4PTyWEgY0YY37j+mQEaKzj8+ COKShKVde8mfg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Naveen N Rao , "Gustavo A . R . Silva" , Michael Ellerman , Sasha Levin , christophe.leroy@csgroup.eu, linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 6.1 11/14] powerpc/lib: Validate size for vector operations Date: Mon, 15 Jan 2024 18:25:45 -0500 Message-ID: <20240115232611.209265-11-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115232611.209265-1-sashal@kernel.org> References: <20240115232611.209265-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.73 Content-Transfer-Encoding: 8bit From: Naveen N Rao [ 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 Reviewed-by: Gustavo A. R. Silva Build-tested-by: Gustavo A. R. Silva Signed-off-by: Michael Ellerman Link: https://msgid.link/20231123071705.397625-1-naveen@kernel.org Signed-off-by: Sasha Levin --- arch/powerpc/lib/sstep.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c index 398b5694aeb7..ec30af8eadb7 100644 --- a/arch/powerpc/lib/sstep.c +++ b/arch/powerpc/lib/sstep.c @@ -586,6 +586,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; @@ -636,6 +638,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; @@ -680,6 +684,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 */ @@ -707,6 +714,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 */ -- 2.43.0