Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2351404pxb; Mon, 20 Sep 2021 19:47:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwl2nBo8L/WJbBZTcsp1kdCEUwNA2RJPKY2cAZS9vQ7YXo33jfKPZ1jjyKYDm0E1J3tciXK X-Received: by 2002:aa7:c80d:: with SMTP id a13mr32186092edt.71.1632192446402; Mon, 20 Sep 2021 19:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192446; cv=none; d=google.com; s=arc-20160816; b=pfmyjlZtlL2Mub+gkJFRO4Fx8aALrhd2lT01DgS78Q/uOM+ZZ8X+DZrvahHCFHWsZ8 VtDNWPMC5qRpv1KyePYtDj9rxzfluR6euNUT7O3jOPJq2lwTguwvxiNz8NJLFqc3wlup 9smlWBi9uiJS6f/2dAaadYDeVGwGaUAvPEVwhGbIEgUD1xvUgHqGmYKAKqG2xBugtZQY Dy0eXtu0JtdL3758Rr29R0ZfwqgJ84X+u+hP6uCYJ3Lr2kWatY3Y91bSuvJbdaYzsUQg 6XMPwR63oRJj7NNqp5eSx6p5by7Wk3F8LYWlvGPO/FzaqxWRZxfWXLezWpd11N2N9zJE tJ+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dXnfEh7ZsgGPGNE3s4YRkCxMgFfs8Mcxcg3okfpUptc=; b=Ee9O5UQ4Xc5Nzgr4CgCoiEdiNff8XjfG4Luys/tEjiVxigT2bix8YOBiO4ZziDrnLN e4fhQX7auXWCuWDZbJG1xSueW8VKg3tOkaDTUPZhZndYVRL7XOJ8ZigY3Qic/EH8hgf9 M10hDCIqO7w87+ckJY9gQxUwDeA90P4/3hCKmo/V41OlMjH28/fg5ym6pmEpVx56sTuy 1up3vJWgQKZwD77lmvEO0T4WyD99RGrs6c1bLmIxRwuMadYvE7GZUa4GswrKdPefi2yh aufEQh+afe+qreaTJnSE4LrikLUJ34ll5/1QkJ+b3yhMUJCdPFNSlFO1I5hbOJMkgZh5 nh0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RklfHSS0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v6si17857672ejh.227.2021.09.20.19.47.02; Mon, 20 Sep 2021 19:47:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RklfHSS0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378661AbhITSZe (ORCPT + 99 others); Mon, 20 Sep 2021 14:25:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:40990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344009AbhITSS5 (ORCPT ); Mon, 20 Sep 2021 14:18:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A6DF9632AB; Mon, 20 Sep 2021 17:23:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158593; bh=nFgCtX4TUZ4Is7S8X4Jxx5TU8pPnTOTTKO3PHLhqnzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RklfHSS0yBz1QEEi3ZNwrA9Lh9/qWxkf0TOOJjLMee1nR5ai/yxYzNpIwC2/sZw5t u7Z1bozKHIv9YIgoIqKS+rXhVRrpMUUzGzfyAk8hTWFEyP7vRG50ko/xSCGhaPLTL+ kbE+nQVZnXb8fkcC6p4aBiFRnOi3hCGfjHz1i3yo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Brown , Catalin Marinas Subject: [PATCH 5.4 195/260] arm64/sve: Use correct size when reinitialising SVE state Date: Mon, 20 Sep 2021 18:43:33 +0200 Message-Id: <20210920163937.737954530@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Brown commit e35ac9d0b56e9efefaeeb84b635ea26c2839ea86 upstream. When we need a buffer for SVE register state we call sve_alloc() to make sure that one is there. In order to avoid repeated allocations and frees we keep the buffer around unless we change vector length and just memset() it to ensure a clean register state. The function that deals with this takes the task to operate on as an argument, however in the case where we do a memset() we initialise using the SVE state size for the current task rather than the task passed as an argument. This is only an issue in the case where we are setting the register state for a task via ptrace and the task being configured has a different vector length to the task tracing it. In the case where the buffer is larger in the traced process we will leak old state from the traced process to itself, in the case where the buffer is smaller in the traced process we will overflow the buffer and corrupt memory. Fixes: bc0ee4760364 ("arm64/sve: Core task context handling") Cc: # 4.15.x Signed-off-by: Mark Brown Link: https://lore.kernel.org/r/20210909165356.10675-1-broonie@kernel.org Signed-off-by: Catalin Marinas Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/fpsimd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -498,7 +498,7 @@ size_t sve_state_size(struct task_struct void sve_alloc(struct task_struct *task) { if (task->thread.sve_state) { - memset(task->thread.sve_state, 0, sve_state_size(current)); + memset(task->thread.sve_state, 0, sve_state_size(task)); return; }