Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5139581yba; Wed, 10 Apr 2019 12:13:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbRF8Lx2W/3/5mW/3m/Mh7QIY6lBNHSRwgd0dmzChN8093+f8hs7qCNUqVwjDYHSMl0NID X-Received: by 2002:aa7:943b:: with SMTP id y27mr21453391pfo.59.1554923610947; Wed, 10 Apr 2019 12:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554923610; cv=none; d=google.com; s=arc-20160816; b=LH9vUvDAY2vnt6M17CoaefnEJD3rj1kKrhpAcrNqTb+vR4ABClhX6XPw9UPk7JdU92 OiK/9Fumt3zFt/8L8HUDPeIAiCep0FGoAePc4Ygk2kHt6rqXTRtzWnWfSPgueAN9ZiNQ 6aB3gkWL+ZjKrMh5sNku+/g5fkUSeKWxuWymecXcE1N+hXHCM5/ep29XGtU6+sESFLNN 8iHaa4zzltrqDw3D2PGNabe3q6RiN47rFvzLglOAiFpp2EVzP2Xbgq6v5LN6eVa4/+au +67+BhdRMpz3hFEHjCctLn5/XooUHF5S64cAhQrMYimMK60ruzHM0U1vJVcjIkmrE7VT SKjw== 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:dkim-signature; bh=tJwvo2EpLrEOPVhfguf5RydvgBOiuIGmGv8afP2DulI=; b=Q210Ss2pr1q9jes1AdJXuTVttNuzjPQYNKwNjUUusPskCEgF7d6pyqY0QSpWfDPWEG wTH47cnFP1HKHwYZrvOpsYWT6in25uY2gstIxHdSQsfWc6NKPDcsPibCoEZ16GiLhXxP PQpHNaFq2jz/z/udwE4OBUCrgMI7FijvjZ9pVvaCUjREyNCp5/4odPmsdeTDHHwLs8C2 Her+AYxzjKkGH2IKbTyj9fxtzThXihE2XD+gATfWk4lX8Z3Q0/2gQHm2tT5jOFDuTH+U MsqqJa9n52THZqO7f5emKWJhq5wrOvCrI1gwq8iv0DxNijfaxDgh2ekTRjdTSx7su30n EFEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lpbMvmzo; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u18si26076958plq.184.2019.04.10.12.13.15; Wed, 10 Apr 2019 12:13:30 -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=@kernel.org header.s=default header.b=lpbMvmzo; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726768AbfDJTHe (ORCPT + 99 others); Wed, 10 Apr 2019 15:07:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:33648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726753AbfDJTHe (ORCPT ); Wed, 10 Apr 2019 15:07:34 -0400 Received: from gmail.com (unknown [104.132.1.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D39952082E; Wed, 10 Apr 2019 19:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554923253; bh=l5kx7M5yIhwXZKbmcPL7AM62Ycxqpjj9uZJIKXIkFXk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lpbMvmzoK4obAkSjUiVj+EJaYr0Z2YfkhiR34D1ICsugEYR1EAhNnz5I7CbWuJcfg ZZdcdlhzwAO3/43bU/AoqBZhciueBKrBKPr0zqNY1P3zcqN738Rj7zmls3BBsZ9YLF /5/0OdnzKiGCKE1wYY1814YukGtRhezkGyeOjNpc= Date: Wed, 10 Apr 2019 12:07:31 -0700 From: Eric Biggers To: Kees Cook Cc: Geert Uytterhoeven , Herbert Xu , linux-security-module , Linux ARM , Linux Crypto Mailing List , Linux Kernel Mailing List Subject: Re: crypto: Kernel memory overwrite attempt detected to spans multiple pages Message-ID: <20190410190729.GA120258@gmail.com> References: <20190319170911.GB202956@gmail.com> <20190320185719.GB180195@gmail.com> <20190321175122.GA1587@sol.localdomain> <20190410031734.GB7140@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 10, 2019 at 11:30:57AM -0700, Kees Cook wrote: > On Tue, Apr 9, 2019 at 8:17 PM Eric Biggers wrote: > > > > On Thu, Mar 21, 2019 at 10:51:22AM -0700, Eric Biggers wrote: > > > On Thu, Mar 21, 2019 at 10:45:31AM -0700, Kees Cook wrote: > > > > On Wed, Mar 20, 2019 at 11:57 AM Eric Biggers wrote: > > > > > > > > > > On Tue, Mar 19, 2019 at 10:09:13AM -0700, Eric Biggers wrote: > > > > > > On Tue, Mar 19, 2019 at 12:54:23PM +0100, Geert Uytterhoeven wrote: > > > > > > > When running the sha1-asm crypto selftest on arm with > > > > > > > CONFIG_HARDENED_USERCOPY_PAGESPAN=y: > > > > > > > > > > > > > > usercopy: Kernel memory overwrite attempt detected to spans > > > > > > > multiple pages (offset 0, size 42)! > > > > > > > > > > > > Well, this must happen with the new (in 5.1) crypto self-tests implementation > > > > > > for any crypto algorithm when CONFIG_HARDENED_USERCOPY_PAGESPAN=y. I don't > > > > > > understand why hardened usercopy considers it a bug though, as there's no buffer > > > > > > overflow. The crypto tests use copy_from_iter() to copy data into a 2-page > > > > > > buffer that was allocated with __get_free_pages(): > > > > > > > > > > > > __get_free_pages(GFP_KERNEL, 1) > > > > > > > > > > > > ... where 1 means an order-1 allocation. > > > > > > > > > > > > If it copies to offset=4064 len=42, for example, then hardened usercopy > > > > > > considers it a bug even though the buffer is 8192 bytes long. Why? > > > > > > > > > > > > It isn't actually copying anything to/from userspace, BTW; it's using iov_iter > > > > > > with ITER_KVEC. > > > > > > > > > > > > - Eric > > > > > > > > > > Kees, any thoughts on why hardened usercopy rejects copies spanning a page > > > > > boundary when they seem to be fine? > > > > > > > > This is due to missing the compound page marking, if I remember > > > > correctly. However, I tend to leave the pagespan test disabled: it > > > > really isn't ready for production use -- there are a lot of missing > > > > annotations still. > > > > > > > > > > So do I need to add __GFP_COMP? Is there any actual reason to do so? > > > Why does hardened usercopy check for it? > > > > > > - Eric > > > > Hi Kees, any answer to this question? > > Hi! Sorry, this got lost in my inbox. Yes, if you can add __GFP_COMP, > that would fix this case. No one has had time lately to track down all > these cases, but avoiding adding new ones would be wonderful. :) > > It's in there because it's a state I'd like to get to in the kernel, > but it'll require a lot more work to get there. > That didn't answer my question. My question is what is the purpose of this? If there was actual buffer overflow when __GFP_COMP isn't specified that would make perfect sense, but AFAICS there isn't. So why does hardened usercopy consider it broken when __GFP_COMP isn't specified? - Eric