Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp552756pxb; Wed, 29 Sep 2021 05:04:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfP9ZxoYVr0ejrUUunFo5kdGcPaapusZwSz3YwF7HfherrxYHY3rXaS26hyG7RL4FLIkdg X-Received: by 2002:aa7:c50e:: with SMTP id o14mr14785508edq.96.1632917063697; Wed, 29 Sep 2021 05:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632917063; cv=none; d=google.com; s=arc-20160816; b=eW6KcDjfX588kLT55gnJnMz+TVBU7RbBbQi1e9vWva4fovGsb+cqKlldLaEgbLNOtJ 6H1VqE/jTJI/oN32NqLrLCBk1Qpr2mBQgmIyPQ4NpG5Rhf9DgN420uy2cKETEe8pHZ6j lNQWguety2RZIfHo22DSaCbMy9dVVEPYOJt1Qa+Pp00hJL8qpS8Qk7dMKVNkUrQ8CAG8 AaoZeyQmJJWYZBXv5XIsXTNEyGKE+zlHt2mkTmJ1gsaqDlZPJxzLbcr87gOd/yGFDRLd blIJtLkdJ6CKw++JaMCS9YkkL2q4C0aPvN+EDWmVYZujpeYdZP/XwSMJSPOalOtdyhhR tUlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=kFGi5YO/UZpvnUP0GpzDl7UQZbYDZXhxeRI/GGcFqpM=; b=CTI4Om/p9swQ3Urt7EAgy+8alw4btP3hcL5D6giXQVELCnVY8E6/4VbelTEy1PxyGQ 7+XXF45qW1GTQpt2QOg2v8U4btWadrjGEG3zxRhy9WzcWXhVQN/55Pxln0iCgHJKZmFx SeQID+AeZqOcPI1qFkeRQG++0fZ7Ic6CZZrmTUhoaTcn5C6KuhivvpqBDgwbeOUi2SqZ nO6JmFnyarAusLS6Nlz89mkeMT2+o89fgIqdCs/eWfy/qGQttFHOMAgj40wzif3B5NfT uSyKM1RHI5W/qWRmjRRMfpd3fBtcIRzVtOWcRLxycu086f9gmZ2vdbrAP553t+Vgtt4s kzgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F3Euc0uH; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f5si2272703edx.339.2021.09.29.05.03.59; Wed, 29 Sep 2021 05:04:23 -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=@kernel.org header.s=k20201202 header.b=F3Euc0uH; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343608AbhI2L4w (ORCPT + 99 others); Wed, 29 Sep 2021 07:56:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:50678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343559AbhI2L4h (ORCPT ); Wed, 29 Sep 2021 07:56:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B2A456136A; Wed, 29 Sep 2021 11:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632916493; bh=EZ71/Hs+sFEq9J5Fv5IdbNz2X8Ij31zbmQ2wxKWDiOo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F3Euc0uHxd7XebKMfcFXFKgfeD+VCo37VEbfQm/1QSkarQTeqTCKd1XGhkyiyWd/u utkV8LHwJsfRVKvvL9/omgl8Tq3cl0S5G4jFq0BUlCFptDvatQ2Kq51nWoUu93aRCc YchiKm313sbqrLCEDDSLBpqXEwH0/n5Kd/MYzEAVsdWSdN9Ln06J9M7tO6fI4VW8St OrRRBX2+IFfANR2SRMoSa5glpF8rjPyycAvBet1NqBD1Ob+idAlCV949ktkT2pQjJb KBM+f9kahwmVQ+xuxWsvg4bwE1R2f/sNPi2R2Li3M4NVxejUoCo7m9MY7RN6bLzc4+ wvkksbgUu/uaA== Date: Wed, 29 Sep 2021 12:54:48 +0100 From: Will Deacon To: yee.lee@mediatek.com Cc: linux-kernel@vger.kernel.org, nicholas.Tang@mediatek.com, Kuan-Ying.lee@mediatek.com, chinwen.chang@mediatek.com, Matthias Brugger , Sami Tolvanen , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" Subject: Re: [PATCH] scs: Release kasan vmalloc poison in scs_free process Message-ID: <20210929115447.GA21631@willie-the-truck> References: <20210923095316.13867-1-yee.lee@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210923095316.13867-1-yee.lee@mediatek.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 23, 2021 at 05:53:12PM +0800, yee.lee@mediatek.com wrote: > From: Yee Lee > > Since scs allocation has been moved to vmalloc region, the > shadow stack is protected by kasan_posion_vmalloc. > However, the vfree_atomic operation needs to access > its context for scs_free process and causes kasan error > as the dump info below. > > This patch Adds kasan_unpoison_vmalloc() before vfree_atomic, > which aligns to the prior flow as using kmem_cache. > The vmalloc region will go back posioned in the following > vumap() operations. > > ================================================================== > BUG: KASAN: vmalloc-out-of-bounds in llist_add_batch+0x60/0xd4 > Write of size 8 at addr ffff8000100b9000 by task kthreadd/2 > > CPU: 0 PID: 2 Comm: kthreadd Not tainted 5.15.0-rc2-11681-(skip) > Hardware name: linux,dummy-virt (DT) > Call trace: > dump_backtrace+0x0/0x43c > show_stack+0x1c/0x2c > dump_stack_lvl+0x68/0x84 > print_address_description+0x80/0x394 > kasan_report+0x180/0x1dc > __asan_report_store8_noabort+0x48/0x58 > llist_add_batch+0x60/0xd4 > vfree_atomic+0x60/0xe0 > scs_free+0x1dc/0x1fc > scs_release+0xa4/0xd4 > free_task+0x30/0xe4 Thanks, I can reproduce this easily with mainline. We only recently gained vmalloc support for kasan on arm64, so that's probably why we didn't spot this earlier. > diff --git a/kernel/scs.c b/kernel/scs.c > index e2a71fc82fa0..25c0d8e416e6 100644 > --- a/kernel/scs.c > +++ b/kernel/scs.c > @@ -68,6 +68,7 @@ void scs_free(void *s) > > __scs_account(s, -1); > > + kasan_unpoison_vmalloc(s, SCS_SIZE); > /* > * We cannot sleep as this can be called in interrupt context, > * so use this_cpu_cmpxchg to update the cache, and vfree_atomic I don't think we should be unpoisoning the stack pages if we're putting them back on to the local cache -- unpoisoning happens on the alloc path in that case anyway so that we can zero them. So how about sending a v2 with this moved a bit later (see below)? With that change: Acked-by: Will Deacon Tested-by: Will Deacon Thanks, Will --->8 diff --git a/kernel/scs.c b/kernel/scs.c index e2a71fc82fa0..579841be8864 100644 --- a/kernel/scs.c +++ b/kernel/scs.c @@ -78,6 +78,7 @@ void scs_free(void *s) if (this_cpu_cmpxchg(scs_cache[i], 0, s) == NULL) return; + kasan_unpoison_vmalloc(s, SCS_SIZE); vfree_atomic(s); }