Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3648228ybn; Fri, 27 Sep 2019 09:16:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxexUBTpJVzDaFMRqFf+EIsl2plzE/rbBZ06ubVCFDHvfVTosAO0YTsU2r3vq9ukAY+N6Rl X-Received: by 2002:a17:906:7a0d:: with SMTP id d13mr8630209ejo.242.1569600988859; Fri, 27 Sep 2019 09:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569600988; cv=none; d=google.com; s=arc-20160816; b=znQEiBObD4dBUdETeVRhdL2BdaZgu39WaxKbpqkoSvlS/d2c0G+x/Yy4tyQ/iDw1UI yOWmmbP/9w45pCKyg2lyq46rGC0592j1w0ofpvjeCYkZYNAAew+2oQKnGccRsvU8Hitk J+bRLirxQ2+NKLQXg7+/qVdR8qSGuZF2TLMwPdBturd/8UtQhRs3vwsPxfUR0XW+3tAV X2HM7luF3FRIOkpC+NyHxztiDB6l0SbG1tA3ahBXnXUcwiiOrGhl8cHWIEflkq0Itwet GS5809/ZUieQu+UncvAh/dobyHDHaAktRezX4XE4VPH+NZcDm9/GKX6dmSykVfTVtfUM vtmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=V7yT0hy0ddMed4OdM0JaFdcManj04cIOw48qMwL3eag=; b=c2eWQFVbFnkOecVfZ9RXZCCuOSS4f5lHflyVMNGrdPYj9Lmi2AdN+gxbR3kFfSYxNs q/eSlUFPg5/UjsjrtKBtBUMTAlwi0J3xeh5RWx3EyKgkS8J9UiUNhfp6vtuWbMSi7sWm VhxMT+qwS0pP1RCoXNoaLerY/fpIHmraQWF47bpSo0UXNVlynon2vmp6FAPo5D97o7dQ Bv4q4+ynuql9/KgA2MFdW3s8mx77fZ788a0F6CVXgxDFSWwc+SodXZCnVVAO8eddb9rA 2KEnLkchZxofEIEPpFER/YYRDkQuIiSEOVZWtrGuW5162qRVtEpSr6AZ3kB3uVpNt39a TM+w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1si1207066ejh.281.2019.09.27.09.16.02; Fri, 27 Sep 2019 09:16:28 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727932AbfI0QPk (ORCPT + 99 others); Fri, 27 Sep 2019 12:15:40 -0400 Received: from foss.arm.com ([217.140.110.172]:55990 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbfI0QPj (ORCPT ); Fri, 27 Sep 2019 12:15:39 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 32B2A1000; Fri, 27 Sep 2019 09:15:39 -0700 (PDT) Received: from arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2F5BC3F534; Fri, 27 Sep 2019 09:15:38 -0700 (PDT) Date: Fri, 27 Sep 2019 17:15:36 +0100 From: Dave Martin To: Masayoshi Mizuma Cc: Julien Grall , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, Masayoshi Mizuma , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] arm64/sve: Fix wrong free for task->thread.sve_state Message-ID: <20190927161535.GS27757@arm.com> References: <20190927153949.29870-1-msys.mizuma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190927153949.29870-1-msys.mizuma@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 27, 2019 at 11:39:49AM -0400, Masayoshi Mizuma wrote: > 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. You could also add: --8<-- There is no need to wait until copy_process() to clear TIF_SVE for dst, becuase the thread flags for dst are initialized already by copying the src task_struct. This change simplifies the code, so get rid of comments that are no longer needed. -->8-- > > Cc: stable@vger.kernel.org Since SVE only exists from v4.15, it may be helpful to specify that, i.e., replace that Cc line with: Cc: # 4.15.x- Otherwise, I'm happy to see this applied, but I'd like somebody to confirm that this change definitely fixes the bug. Cheers ---Dave [...] > 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 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel