Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5137773yba; Wed, 10 Apr 2019 12:11:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWXIzSuiyJcG3siKFA/V/5kh95qaNJrR4WQ7UzDSNzuq6XJAW19S7n7KM/kJQOQCvq5JtS X-Received: by 2002:a17:902:a583:: with SMTP id az3mr45932306plb.205.1554923474005; Wed, 10 Apr 2019 12:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554923473; cv=none; d=google.com; s=arc-20160816; b=XqO/e3TSlgSjUEQDrxB3JZAuYmNmCyyWYqLudGQhNEHbKq++EYpZ3q10fQ8kEKvMLq zIfZKohwZs1cPFHXQJ9XGiyPfSjXwSUL7zMrezWfAhYjB1/VhPrN3GbfpDhdoW2g7lNF PuChOqQuIMhW+Z7A53JxFlT6FFdjG5HC+B9SX9UH1KJmH2Sda0uctHfQV2nTl3eq5osH PwG8lqOcCRY8Nx/XkpCHOFph2WYhv4vyiXT72Bxw/OPxzT788ep3ZYJT3Ff+HonMnCP3 YSg///wIjTKdCajRkJhfGEkwcNrn3Sm3mkSxsgcEeCtXHv81P2mNHssiYF6fJY79b0/E BpWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=HZrouuH6qDcbcN0Xir61EX//r5Pvf+jE6u/Bex0vtPA=; b=KVvBlHm25DTs1+857LTkoekr3JDi176BNayXsG/GJMbQDWM7uT87hn8s46UZH6IZ4a 68XipVQzRK9Hr6e6RzPctsODqngd8XgE+MnmL6rbc2bui0nlPFbnHiLivj6C76MZGNpt ElLnEECK8DEiiTYGuI8Vme3ewKZcaYv45LHMppzs6ISBOB+cpyw3YVdFUDBZioRcKd38 x6MfW/hQLvk+giv4IjurvbDk4SnefqQoAhOQoz6nPnzEg0KDs+MnrKT2ca3hxQG+vXek qi0cT6Pcrj711aVFTzn9z5csG82ThNMxRzyblWQKwSGDfF9C5v7+XP2+CnwiHpFRkF7B lHYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ChsrIjTR; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f63si34446458pfa.154.2019.04.10.12.10.58; Wed, 10 Apr 2019 12:11:13 -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=@chromium.org header.s=google header.b=ChsrIjTR; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731558AbfDJSbM (ORCPT + 99 others); Wed, 10 Apr 2019 14:31:12 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:45466 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727229AbfDJSbL (ORCPT ); Wed, 10 Apr 2019 14:31:11 -0400 Received: by mail-vs1-f66.google.com with SMTP id o10so1933947vsp.12 for ; Wed, 10 Apr 2019 11:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HZrouuH6qDcbcN0Xir61EX//r5Pvf+jE6u/Bex0vtPA=; b=ChsrIjTR2XUXY98NFeP4EYidlDto2ZP21YpmNICKQthef5L3chA1evffBlGc7f5Cpd AVLdt06zVihsEe31IHJ9/S+3AZeljeUHUhTc1c2zEZwWOWJ77/kz5jXchKIL0j3RJt7Z q8y86gbdDx/7EpkMgNN0PhF3sbVnMJ0w/ySFg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HZrouuH6qDcbcN0Xir61EX//r5Pvf+jE6u/Bex0vtPA=; b=DkwVKt3zIsglAR5jGoBDqs9ppXxCuaEuL5i6PpaWUt55JymKlnJRYPCxX66lkYLoar 42bd1tHFMfQ0Bt+nwRVONFf32+3ZjESPnkbcjL8nT2r0ISxEWweybFk1mfOnLtESXZEU AAh/MQf7iNWs+rzXrlynskKelmJC8iPT2hxRtb1vitFPKrcebEuNkEjpF2jrTqJKsU2K YaIHot7Y7qvu1Z4wuo4F48s4sBksUwUQkRkmqK+v1hscCBfx0vkKXO0P2Xz2gJOdxoGF lSAjVF2apt/TVC0vpq4a185PP/npHLUGQfWYdz98quw3uCLaWJAc7aAMc54tqWspZlO/ MLsw== X-Gm-Message-State: APjAAAX0JOKT6W7t8pmFE1w98BkLRi3BgemxbfuoDk6RJ0iaM/AQhgRP Ujac2lddBZB7ZaU4BeDH4rZaKbB2h/A= X-Received: by 2002:a67:6991:: with SMTP id e139mr25717826vsc.80.1554921069865; Wed, 10 Apr 2019 11:31:09 -0700 (PDT) Received: from mail-vs1-f50.google.com (mail-vs1-f50.google.com. [209.85.217.50]) by smtp.gmail.com with ESMTPSA id e81sm17503356vkd.56.2019.04.10.11.31.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 11:31:09 -0700 (PDT) Received: by mail-vs1-f50.google.com with SMTP id f22so1943340vso.7 for ; Wed, 10 Apr 2019 11:31:08 -0700 (PDT) X-Received: by 2002:a67:7816:: with SMTP id t22mr24108905vsc.115.1554921068268; Wed, 10 Apr 2019 11:31:08 -0700 (PDT) MIME-Version: 1.0 References: <20190319170911.GB202956@gmail.com> <20190320185719.GB180195@gmail.com> <20190321175122.GA1587@sol.localdomain> <20190410031734.GB7140@sol.localdomain> In-Reply-To: <20190410031734.GB7140@sol.localdomain> From: Kees Cook Date: Wed, 10 Apr 2019 11:30:57 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: crypto: Kernel memory overwrite attempt detected to spans multiple pages To: Eric Biggers Cc: Geert Uytterhoeven , Herbert Xu , linux-security-module , Linux ARM , Linux Crypto Mailing List , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. -- Kees Cook