From patchwork Tue Feb 15 16:52:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12747306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 979B6C4321E for ; Tue, 15 Feb 2022 16:52:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA6FE6B0078; Tue, 15 Feb 2022 11:52:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E55BB6B007B; Tue, 15 Feb 2022 11:52:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D44BD6B007D; Tue, 15 Feb 2022 11:52:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id C1B2F6B0078 for ; Tue, 15 Feb 2022 11:52:36 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 81603181AC9CC for ; Tue, 15 Feb 2022 16:52:36 +0000 (UTC) X-FDA: 79145607912.29.A955515 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf22.hostedemail.com (Postfix) with ESMTP id 8920EC0002 for ; Tue, 15 Feb 2022 16:52:22 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1644943940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=x0WqM712H6kGeqw3TwDc06pcqFg5ecYp2OoNXB9nDtc=; b=hpIlGRiz9NewVc3tjwMSNma3ps7kUMWeWbHJGVVzUnmYckb+tYbEzRH9bRJHWP+gKCE8af 0aRjRQR2Lza4OahDsRnPFNU8moxBt1CaQjK8Y24us21RgRbLSqKG/oJL3XV3R0hw+R4E4K k7+o60f3sUXhfhpDu9YuRYAjeczwhok= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm] fix for "kasan, fork: reset pointer tags of vmapped stacks" Date: Tue, 15 Feb 2022 17:52:17 +0100 Message-Id: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspamd-Queue-Id: 8920EC0002 X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=hpIlGRiz; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Stat-Signature: dj6iui8e7z8nd9ypwbxwdamqqjto4jqi X-Rspamd-Server: rspam11 X-HE-Tag: 1644943942-277108 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov That patch didn't update the case when a stack is retrived from cached_stacks in alloc_thread_stack_node(). As cached_stacks stores vm_structs and not stack pointers themselves, the pointer tag needs to be reset there as well. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- kernel/fork.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 57d624f05182..5e3ad2e7a756 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -226,15 +226,17 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) if (!s) continue; - /* Mark stack accessible for KASAN. */ + /* Reset stack metadata. */ kasan_unpoison_range(s->addr, THREAD_SIZE); + stack = kasan_reset_tag(s->addr); + /* Clear stale pointers from reused stack. */ - memset(s->addr, 0, THREAD_SIZE); + memset(stack, 0, THREAD_SIZE); tsk->stack_vm_area = s; - tsk->stack = s->addr; - return s->addr; + tsk->stack = stack; + return stack; } /*