Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3805468yba; Sat, 11 May 2019 21:13:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyT2gqoeU328qZkNhMpnY5lBcrS+yydIfT01rERHKqHWXyoYuYqECyGM6cSlUTMt6ZDnycL X-Received: by 2002:aa7:86c3:: with SMTP id h3mr24844036pfo.169.1557634401994; Sat, 11 May 2019 21:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557634401; cv=none; d=google.com; s=arc-20160816; b=rfkjv8hBZmvSNEzC2Fzk65kbjWLA+nopO4M/30ki+lQdNDXaVsZnPboEm2vyvOTBFE hA2fI5qTzxpcIO6nXMlhFsxkVcGHucELJ3v4bf/feDt7rfSW+WsHUXX6QNNEONLSvo6I WNVEtpTWoPjLkBBuKSu5xNEM3GnEaLFXM5wcx1KYnUIGu94OU9BJa5nSHXW26vJ5XOYU RdiO2Duzg9TR9O4meSZfnM9YZnDt2275GYvOuagg6KQmR/sfPYrvSOrefACdVwWpXVbD xzS+MeyiItkqKE/J4WZ5e2tF0GJOmAlb70yZZw/Vr0HFFGQLkRmbkKFCDjQjMTGBMFIe bNGw== 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=okCF2G2bDtULdDLlOPAao87uH7PkIsUp6GVlHHgydZ4=; b=LxujxMfbOh1Kw5s/sLTRb7C6O5PnMhaa8ga0zhERo09O/qxPOVdlT4XHc88eM8I/zV OCHXQ+3SShn8YnTg3n2fw1hyUsasLrXJVOpYfe4KG6OdEHLdreNouydzZmFMAo9Xk4eu 2iRUFBaIaAtIsyFm4ko0Adr8NIXyRHnR903pMTI5xWaA4MWg+6sf/omHNsDCDdWEH432 eII4gN2pF4vFcdk87VFENvweLyokYzzuBavpLi/sYgHnTZEUMMZyp7oANQfP5hh6KvDI s423ID4JAkyQSFw0NSbFF9zyqru0EgbYIYwvdaS4x9XKm/Vr3JM564t6tlzp+sC1T5af geRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dOYPVs5d; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si408362plk.245.2019.05.11.21.13.04; Sat, 11 May 2019 21:13:21 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dOYPVs5d; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726190AbfELELr (ORCPT + 99 others); Sun, 12 May 2019 00:11:47 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59432 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725913AbfELELr (ORCPT ); Sun, 12 May 2019 00:11:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=okCF2G2bDtULdDLlOPAao87uH7PkIsUp6GVlHHgydZ4=; b=dOYPVs5dvX8lEHg5muxxqJWqS /xG2ZXX2IkLiYFXOYPm0Huc19L3yU4aCZIgQFRHUxCBV4LBYfFgRyTnCmzEIHsKGGSSTgq/Fhxmr6 K6lZERXbV2UvcE1awG3xBWu7fTQcDcoDFklJh/kgXo+sLdlhfw9a0eUIfLEOtRrWtFbQFBrEXWqGV o6+vZUj1hZhJP9cd8RZpkp06mOndvxH698rVsoFicFOt02JUqRRqp5iPfojLVdTPMaOh1LnbQjUFn 6IUD6EtbtMfPK8dR+SvM7gNSYFXUGQvXSRU8vvE3LAIlDbDuRFZlC5wUp5u+k0uKI4pNEwABqvKXW 6xglXU9LA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1hPfpv-0000Gh-1h; Sun, 12 May 2019 04:11:43 +0000 Date: Sat, 11 May 2019 21:11:42 -0700 From: Matthew Wilcox To: Kees Cook Cc: Laura Abbott , Andrew Morton , Eric Biggers , Rik van Riel , linux-kernel@vger.kernel.org Subject: Re: [PATCH] usercopy: Remove HARDENED_USERCOPY_PAGESPAN Message-ID: <20190512041142.GA24542@bombadil.infradead.org> References: <201905101341.A17DDD7@keescook> <201905111657.76FE0BDCEC@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201905111657.76FE0BDCEC@keescook> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 11, 2019 at 05:03:08PM -0700, Kees Cook wrote: > On Fri, May 10, 2019 at 08:41:43PM -0400, Laura Abbott wrote: > > On 5/10/19 3:43 PM, Kees Cook wrote: > > > This feature continues to cause more problems than it solves[1]. Its > > > intention was to check the bounds of page-allocator allocations by using > > > __GFP_COMP, for which we would need to find all missing __GFP_COMP > > > markings. This work has been on hold and there is an argument[2] > > > that such markings are not even the correct signal for checking for > > > same-allocation pages. Instead of depending on BROKEN, this just removes > > > it entirely. It can be trivially reverted if/when a better solution for > > > tracking page allocator sizes is found. > > > > > > [1] https://www.mail-archive.com/linux-crypto@vger.kernel.org/msg37479.html > > > [2] https://lkml.kernel.org/r/20190415022412.GA29714@bombadil.infradead.org > > > > I agree the page spanning is broken but is it worth keeping the > > checks against __rodata __bss etc.? > > They're all just white-listing later checks (except RODATA which is > doing a cheap RO test which is redundant on any architecture with actual > rodata...) so they don't have any value in staying without the rest of > the page allocator logic. > > > > - /* Is the object wholly within one base page? */ > > > - if (likely(((unsigned long)ptr & (unsigned long)PAGE_MASK) == > > > - ((unsigned long)end & (unsigned long)PAGE_MASK))) > > > - return; > > > - > > > - /* Allow if fully inside the same compound (__GFP_COMP) page. */ > > > - endpage = virt_to_head_page(end); > > > - if (likely(endpage == page)) > > > - return; > > We _could_ keep the mixed CMA/reserved/neither check if we really wanted > to, but that's such a corner case of a corner case, I'm not sure it's > worth doing the virt_to_head_page() across the whole span to figure > it out. I'd delete that first check, because it's a subset of the second check, /* Is the object wholly within a single (base or compound) page? */ endpage = virt_to_head_page(end); if (likely(endpage == page)) return; /* * If the start and end are more than MAX_ORDER apart, they must * be from separate allocations */ if (n >= (PAGE_SIZE << MAX_ORDER)) usercopy_abort("spans too many pages", NULL, to_user, 0, n); /* * If neither page is compound, we can't tell if the object is * within a single allocation or not */ if (!PageCompound(page) && !PageCompound(endpage)) return; > I really wish we had size of allocation reliably held somewhere. We'll > need it for doing memory tagging of the page allocator too... I think we'll need to store those allocations in a separate data structure on the side. As far as the rest of the kernel is concerned, those struct pages belong to them once the page allocator has given them.