Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1341491pxu; Sat, 5 Dec 2020 12:17:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAasLbwIqf1UH6sf989AaqsbgsQitrhFh7DqSjIWtLzLCueqnPJNr5OlDhdEyL5zyRp2yj X-Received: by 2002:a50:9ea4:: with SMTP id a33mr10127653edf.70.1607199466879; Sat, 05 Dec 2020 12:17:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607199466; cv=none; d=google.com; s=arc-20160816; b=yBwnlkelIAsP1+l5eiWzidM8np0GOrZIp7oziMk41d8zOP6xdKRr+o8w8UjGG37UZ5 8BKrzeuY62UZ1ovrONVrVwGYxmN04VnrAapqozEjTqwDfwpoazJwPcGqwJKuoW294wKq O8tE/aA8vL+gt/xAKchyuCYqWtct8o8Pj08CrA0rsN4ARutcO3YcXhE/JTe9E/9AEwCP 29Ya3T2FmlSOi9k41zujNMMWePAhqnvUa3tlRkYHjTMbZQIZpSYsz92t3cZxtRJPtyIT dmIylYkuAVLIRdQxdZOry1gWEJb6ifYkz3Gdxkt/XTH6n7WeUiJtQK0kScRvEBCy7flO 3+9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=pMu1qIAWq3lzHv5n2IPWZfCaO+S55T0UAivuJF1pVq8=; b=vyJs7JBSOjzTzvRws8y38XgW4GhtwzaZXDiHWsD9XVVUDUYt5XYs7pJJHen/Xq4aoL eQMXw9jAjYrc7dOZjNWeRBzcoeKO+Pj6E/z9TbkchvQIPwUr0o11zkxMe8lF5wDvwxgr Xnotz0sR/6oDH1D4pKrGwWFaqWVKZ+WmjS0zixCEX87GJQEzXZTA6sNXXqC+uYZz/Y5/ OalMWDBP4zNLptWGrf0InmQPVmKJG+fegHlZZ9MX6LslFd9vH0nwMbJ6g6NxXEWcWkV8 xV9hedvnFv+MObNRj65XMwd5VIVPHBhuDZIZA+StdsNb3SwBOqI2NenGOUNvfg/rul1Q x0jw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt13si3815169ejb.98.2020.12.05.12.17.14; Sat, 05 Dec 2020 12:17:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725863AbgLEURM (ORCPT + 99 others); Sat, 5 Dec 2020 15:17:12 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:53822 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725270AbgLEURM (ORCPT ); Sat, 5 Dec 2020 15:17:12 -0500 X-IronPort-AV: E=Sophos;i="5.78,395,1599516000"; d="scan'208";a="481316044" Received: from 173.121.68.85.rev.sfr.net (HELO hadrien) ([85.68.121.173]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2020 21:16:04 +0100 Date: Sat, 5 Dec 2020 21:16:04 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Thomas Gleixner cc: Corentin Labbe , herbert@gondor.apana.org.au, mripard@kernel.org, wens@csie.org, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Jens Axboe , linux-mm@kvack.org, Andrew Morton Subject: Re: crypto: sun4i-ss: error with kmap In-Reply-To: <87mtys8268.fsf@nanos.tec.linutronix.de> Message-ID: References: <20201201144529.GA6786@Red> <87v9dlfthf.fsf@nanos.tec.linutronix.de> <20201202195501.GA29296@Red> <877dpzexfr.fsf@nanos.tec.linutronix.de> <20201203173846.GA16207@Red> <87r1o6bh1u.fsf@nanos.tec.linutronix.de> <20201204132631.GA25321@Red> <874kl1bod0.fsf@nanos.tec.linutronix.de> <20201204192753.GA19782@Red> <87wnxx9tle.fsf@nanos.tec.linutronix.de> <20201205184334.GA8034@Red> <87mtys8268.fsf@nanos.tec.linutronix.de> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Sat, 5 Dec 2020, Thomas Gleixner wrote: > Corentin, > > On Sat, Dec 05 2020 at 19:43, Corentin Labbe wrote: > > On Fri, Dec 04, 2020 at 09:58:21PM +0100, Thomas Gleixner wrote: > >> Can you please replace the debug patch with the one below and try again? > >> That stops the trace right on the condition. > > > > Hello, the result could be found at http://kernel.montjoie.ovh/130739.log > > Thanks for providing this. This is clearly showing where stuff goes > wrong. It starts here at 729.550001. I removed the uninteresting parts: > > 0d..2 147103293us : __kmap_local_page_prot <-sg_miter_next > 0d..3 147103308us :__kmap_local_pfn_prot: kmap_local_pfn: 1 ffefd000 > > 0d..3 147103311us : __kmap_local_page_prot <-sg_miter_next > 0d..4 147103325us : __kmap_local_pfn_prot: kmap_local_pfn: 3 ffefb000 > > 0d..3 147103429us : kunmap_local_indexed <-sg_miter_stop > 0d..4 147103433us : kunmap_local_indexed: kunmap_local: 3 ffefd000 > > So this maps two pages and unmaps the first one. That's all called from > sun4i_ss_opti_poll() and the bug is clearly visible there: > > sg_miter_next(&mi); > sg_miter_next(&mo); > > release_ss: > sg_miter_stop(&mi); > sg_miter_stop(&mo); > > Written by yourself :) Same issue in sun4i_ss_cipher_poll() > > Fix below. > > Julia, it might be worth to have a coccinelle check for that. It's the > only place which got it wrong, but this goes unnoticed when code is > e.g. only fully tested on 64bit or as in this case never tested with > full debugging enabled. The whole kmap_atomic and kmap_local (new in > next) family and all users like the sg_miter stuff are affected by this. OK, thanks for the suggestion. I will look into it. julia > > Thanks, > > tglx > --- > Subject: crypto: sun4i-ss - Fix sg_miter_stop() ordering > From: Thomas Gleixner > Date: Sat, 05 Dec 2020 20:17:28 +0100 > > sun4i_ss_opti_poll() and sun4i_ss_cipher_poll() do: > > sg_miter_next(&mi); > sg_miter_next(&mo); > ... > sg_miter_stop(&mi); > sg_miter_stop(&mo); > > which is the wrong order because sg_miter_next() maps a page with > kmap_atomic() and sg_miter_stop() unmaps it. kmap_atomic() uses a stack > internaly which requires that the nested map is unmapped first. As this > uses the wrong order it triggers the warning in kunmap_local_indexed() > which checks the to be unmapped address and subsequently crashes. > > This went unnoticed for 5 years because the ARM kmap_atomic() > implementation had the warning conditional on CONFIG_DEBUG_HIGHMEM which > was obviously never enabled when testing that driver. > > Flip the order to cure it. > > Reported-by: Corentin Labbe > Fixes: 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator") > Signed-off-by: Thomas Gleixner > Cc: stable@vger.kernel.org > --- > drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c > +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c > @@ -109,8 +109,8 @@ static int noinline_for_stack sun4i_ss_o > } > > release_ss: > - sg_miter_stop(&mi); > sg_miter_stop(&mo); > + sg_miter_stop(&mi); > writel(0, ss->base + SS_CTL); > spin_unlock_irqrestore(&ss->slock, flags); > return err; > @@ -333,8 +333,8 @@ static int sun4i_ss_cipher_poll(struct s > } > > release_ss: > - sg_miter_stop(&mi); > sg_miter_stop(&mo); > + sg_miter_stop(&mi); > writel(0, ss->base + SS_CTL); > spin_unlock_irqrestore(&ss->slock, flags); > > > >