Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2564852lkm; Mon, 20 Sep 2021 18:50:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQALRsXtl3OCveXQJC/81dOPfV0LHq9Lb9r52ooAPFBgtmred3PPrn6P1ljFFjZAeh8T15 X-Received: by 2002:a05:6638:3890:: with SMTP id b16mr22278027jav.65.1632189047111; Mon, 20 Sep 2021 18:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189047; cv=none; d=google.com; s=arc-20160816; b=0zKuhsGCQeKHb7tTImhy4uu7JzvMyBFYCuCP34/6rr8Vce2xLYfW6oqmRig+SnKQCP K4jATyW0n9QPzGsfPQxUyiKFOSW1cgKK6C6TXX/u5BOTczWL/XaBcnE3WErmtpysfJD2 2uFI+o0Tk6oKcvEcRu04e8qho4Pl3xX1UZpCbHk0KHclJ91pJoyQWofdrNAfnaytlnIs QLK7oEG76A5jZYIML7NjU6YDRVVT3OFy96MgtUe1ose+h5+702MbGcrb08u4+5Y4ns2g uZpzBUFlQtpkbjqZwKy2TzaLJ9LabtZo5i5cCSBjb43o9dSCSV8K13y0FNSnU8Uc5JOV tnlQ== 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=hfFxfOg5zwWl+gfvWSmMt5W+ZuAKoKhHyTxFu1OpByA=; b=A6na+SWy0OyfzPfODZlwXcOve679v22LYd/oLmtc2IOU0AMfDPvJdtWuiwFdniZzax VISZ2G90mYUOgNCX+MmSW6h/grsA34QG9uLy8ZCRNIha8l34v182gRt7olsb0QhcMmOW fT9dqHRZtVPWv4n4TgsqKHKkIm2u+kBC3FoM6BO8f9VTTMKTVcY6GipIFU4rO/nMLASL OrpvNXs5OApDypqz+LbMwaUYhn1cbHBs813F0WyRjWEmRGQgzdvuHGcXJ171/TUXXER0 rGpV+rDwOaKLbetGRk9usHBzm72H0KQ1MgEiJLnYa1FeBNKnYrKcrVlipel8OC/1ubxH kWYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LK7p6P1O; 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 e43si4330504jaf.97.2021.09.20.18.50.36; Mon, 20 Sep 2021 18:50:47 -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=LK7p6P1O; 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 S1356558AbhITSAf (ORCPT + 99 others); Mon, 20 Sep 2021 14:00:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:54556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355190AbhITRyS (ORCPT ); Mon, 20 Sep 2021 13:54:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7D46A61BFE; Mon, 20 Sep 2021 17:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158007; bh=dE7Vn0lCqonUuO3g+fvfTT795OVoIb9npFsBKYR+cKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LK7p6P1Od8gYwADdlspmLgiSOFLOcgoXc+5uSjh6VW2pkmTyZUuyjcWkb3Xk/oqmU KZSZhEK/mGu9iLSRejUzZT8oZxnOphF3jbw884EpAMy2X5FOy8IB9eHYkgqF+6GOfF vlJroQTdgx2ycFDbTk7dgHcFiCkOHngOs5hBA4zs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Brown , Catalin Marinas Subject: [PATCH 4.19 253/293] arm64/sve: Use correct size when reinitialising SVE state Date: Mon, 20 Sep 2021 18:43:35 +0200 Message-Id: <20210920163942.047521269@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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 @@ -434,7 +434,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; }