Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3605734ybn; Fri, 27 Sep 2019 08:41:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjP7Ekpecu3swIfzSMRdHf054mn/vIIcAQQY1qZR5TLlelRKylUh5xD25kjr/Z4YhytqQ8 X-Received: by 2002:a17:906:7f03:: with SMTP id d3mr8256207ejr.115.1569598896073; Fri, 27 Sep 2019 08:41:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569598896; cv=none; d=google.com; s=arc-20160816; b=Ro0PzCs6tLjfHSAjStFZ+gGYj/YCh/Lk/S//nkDNU80kMLlJEsKo922plkqMMZKVKl MYQH6zXGMNjcKPUjgJxNJzvt7/VbzS/NtNI/rU+wpEtXY3anD50c9gw9mvR5dtK9Xmmh PF97nKs3rdsT6akG8MCvDuypL2tafyawTw0oW6JqrANZBEaQfwIiEQm32nPQWfImDmE/ +YTgUI18PB3ucyo8B3vsnsXQ3bHTdrz2mo7/mxuWTBP1XlXhef5jQ9kUXm998l2FKzo2 RIuCFKqicxbAJ5L3yzGsU8KIRp6p1m/hycGuWZM1oRDJiCGvchHEaZFzz4C/D8gbDWr0 PllA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Cpv5ZNVm9yUOsy7vshEHjPrRDw5bm6guIdo54Z4wEpg=; b=pjmDutQFjoTQlCcY4EiQQtaMa11DDEIYMBIt+gSZpwDv/P492a77qFpWbOdUTYCeN1 0TSLDE4tzYxHXedzC4iCGAzIYPUVRi7NYbHDOvKiJW0XxCBfTt2rjeLUHxzC4cOzc9xe UJq6Db5JhO77EFFALJv97Azf3b55GaqYCYZnlQ9et7VmHtqo8YjUFK3/Qe0/Wj4rTfeb luAGVYcYlkkPJ01nU3pXh9FlR2QhXZhKi9btzfBeaOeKHWLAahgjgDPs/0XGLsVkrB0W w+7N8I/5kw0Y0Xk+oDq5g9JIa4Mjsm8F3vij69G8LoACZM7nBD2DoTSdncPGxo1W7OMt vjkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uuB0lD3f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ec21si2569494ejb.26.2019.09.27.08.41.10; Fri, 27 Sep 2019 08:41:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uuB0lD3f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727836AbfI0Pj5 (ORCPT + 99 others); Fri, 27 Sep 2019 11:39:57 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:43569 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727427AbfI0Pj5 (ORCPT ); Fri, 27 Sep 2019 11:39:57 -0400 Received: by mail-qt1-f193.google.com with SMTP id c3so7783488qtv.10 for ; Fri, 27 Sep 2019 08:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Cpv5ZNVm9yUOsy7vshEHjPrRDw5bm6guIdo54Z4wEpg=; b=uuB0lD3fcX2NayhCWqNwWoaQ88d7SNLOxTyN4fzAmIqh8st6lYIXQC+nvvTJBHS0NL KiFSFOo7oS7qcCNMq1H3zbtN5RRxQ/0pUTPeLFjs1ewSzaJu0cQX0zn6ljqwWNH1gBQ4 dP1bI3AqhMO1jDx71uSRcuzRXDAbfZjfFAcG+pbeOtQSCu6ZrqIA7f0JOEM0GowXTcqw TGh4qbSEAcN8L5aIceACCVcqBUUcIlASjkTxVczSVYHCACkOK/la/iMONawnFo2RVBeL cJdp3OC90dbVziwQS9BssT9M3NWJYRHnqY43xXtI5ULv9VmxuDjknrND3GmVF1RuvWfG ZhLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Cpv5ZNVm9yUOsy7vshEHjPrRDw5bm6guIdo54Z4wEpg=; b=g/nmdd2f1h9V8r6F/iF+xSAFQ5xYXcBRgPEbk2BiXa606qZHMVk8bbBgCn443ogaPE JlwLyHU6IheUEclUZc3B209SG5+gl3gSx6OIeG+IeAzFvOJ8tOpWWzvHATB8ScmRG/XW tMFfQA8JAQbsRXtNWlnLhymUYLk1/gMr8lVnnA8HJLEYeKbqYR8xlckYqpBJLZHiJB3+ L7HnjRCCvkbCIZfFQ40mefDuvYQp44ScXk5dq5E9Ln/ZqyqNadS1uHXHUAS3gDSJcH3M 2SEYKHbOsPCtLmIMHXVzEgAmCY2WXMA+esvBXlbny8izosQ5Y2PjPRzBMVBHhA4FCVai vO9w== X-Gm-Message-State: APjAAAWpZ5MCuv2KRU/1bYVf+zbdUfJZ5huNxjK86YrD7Bpfj0g9dP0/ MFHKtelDmW25CCX3NYn4gg== X-Received: by 2002:a0c:d6c9:: with SMTP id l9mr8321121qvi.179.1569598796511; Fri, 27 Sep 2019 08:39:56 -0700 (PDT) Received: from gabell.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id n42sm3030137qta.31.2019.09.27.08.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 08:39:55 -0700 (PDT) From: Masayoshi Mizuma To: Dave Martin , Julien Grall , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org Cc: Masayoshi Mizuma , Masayoshi Mizuma , linux-kernel@vger.kernel.org Subject: [PATCH v2] arm64/sve: Fix wrong free for task->thread.sve_state Date: Fri, 27 Sep 2019 11:39:49 -0400 Message-Id: <20190927153949.29870-1-msys.mizuma@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masayoshi Mizuma The system which has SVE feature crashed because of the memory pointed by task->thread.sve_state was destroyed by someone. That is because sve_state is freed while the forking the child process. The child process has the pointer of sve_state which is same as the parent's because the child's task_struct is copied from the parent's one. If the copy_process() fails as an error on somewhere, for example, copy_creds(), then the sve_state is freed even if the parent is alive. The flow is as follows. copy_process p = dup_task_struct => arch_dup_task_struct *dst = *src; // copy the entire region. : retval = copy_creds if (retval < 0) goto bad_fork_free; : bad_fork_free: ... delayed_free_task(p); => free_task => arch_release_task_struct => fpsimd_release_task => __sve_free => kfree(task->thread.sve_state); // free the parent's sve_state Move child's sve_state = NULL and clearing TIF_SVE flag to arch_dup_task_struct() so that the child doesn't free the parent's one. Cc: stable@vger.kernel.org Fixes: bc0ee4760364 ("arm64/sve: Core task context handling") Signed-off-by: Masayoshi Mizuma Reported-by: Hidetoshi Seto Suggested-by: Dave Martin --- arch/arm64/kernel/process.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index f674f28df..6937f5935 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -323,22 +323,16 @@ void arch_release_task_struct(struct task_struct *tsk) fpsimd_release_task(tsk); } -/* - * src and dst may temporarily have aliased sve_state after task_struct - * is copied. We cannot fix this properly here, because src may have - * live SVE state and dst's thread_info may not exist yet, so tweaking - * either src's or dst's TIF_SVE is not safe. - * - * The unaliasing is done in copy_thread() instead. This works because - * dst is not schedulable or traceable until both of these functions - * have been called. - */ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) { if (current->mm) fpsimd_preserve_current_state(); *dst = *src; + BUILD_BUG_ON(!IS_ENABLED(CONFIG_THREAD_INFO_IN_TASK)); + dst->thread.sve_state = NULL; + clear_tsk_thread_flag(dst, TIF_SVE); + return 0; } @@ -351,13 +345,6 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context)); - /* - * Unalias p->thread.sve_state (if any) from the parent task - * and disable discard SVE state for p: - */ - clear_tsk_thread_flag(p, TIF_SVE); - p->thread.sve_state = NULL; - /* * In case p was allocated the same task_struct pointer as some * other recently-exited task, make sure p is disassociated from -- 2.18.1