Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3828509imd; Mon, 29 Oct 2018 13:03:34 -0700 (PDT) X-Google-Smtp-Source: AJdET5fXVkQq89OYAsfXMacLwUCDpBVyCEh3MFrnVSOcJyQ0KtBiY5HcwYckWArJNrE2Kw8eBX1r X-Received: by 2002:a17:902:b486:: with SMTP id y6-v6mr6949062plr.263.1540843413950; Mon, 29 Oct 2018 13:03:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540843413; cv=none; d=google.com; s=arc-20160816; b=vpeSdFbv6dE1+etl2sU27NjB4aQqvg0YsPKt6VwoWoG8vPp5O4K/klrCIf8/LXKatR +ixF+Rkz47VinJtsXzTnnnrWfzXBl4/IaHnNgMPhWeyE9D9oAMOIgkvuFTNwi8a1e4b1 xAIeBnXMP2KwjC1+vdpPpADSNLj6Du/Rf9hoTpTNxAFQygqR626aZpIh6+6+fAF/v29x n+sStnasg/DSXBkzKNdpI/88BGpMOgrQVLdhNgmD1tz3uddDyh3mbARDknVpCiVuVQ8j ZF+E4G1106Pyncu2R0jVTMH1a97hTQfT2Pt2N5Ofz39WsXBREFe4A+HMW1WKhWI4PWeY BMaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=TLUjEGuOtOvRkbxWiZWPWrLvobGSOVuiXeWjVsEyOZo=; b=q5uPwdqepJwFlaXrjGWAROtd9IYbVWD6+jUwYVY7YTgR2x7QFwlVKkbaFVvZS68CFe mMBR7IDyVtCoUYGnlOuEs9bHQ0AjGF08YhlojHj+gQR83ailIzCdoDFt536BD21C+Hb3 cfPxuxfNLo+hPurWyUPfinStXUxyTYGS6n1GpWMIdh/tgTVwAhx/9MUvGkPUC8JPxOpo 9R9SPF46fyMu5u6kXHtcAAodmb4n8dSbtG8LE5BY750RmfyP/1kTkSrm8m3eC42ACcly wgW2DIDt45Dp/dsyaPZB3Y9dzd1ho4YJILJ/WubzgaEQrKywe4q7PxT8xBmM4JozDKvm XsTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MdYBRsbs; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 16-v6si22314826pgp.175.2018.10.29.13.03.17; Mon, 29 Oct 2018 13:03:33 -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=@gmail.com header.s=20161025 header.b=MdYBRsbs; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729646AbeJ3Evi (ORCPT + 99 others); Tue, 30 Oct 2018 00:51:38 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:37501 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725781AbeJ3Evi (ORCPT ); Tue, 30 Oct 2018 00:51:38 -0400 Received: by mail-lj1-f196.google.com with SMTP id c4-v6so9089176lja.4; Mon, 29 Oct 2018 13:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=TLUjEGuOtOvRkbxWiZWPWrLvobGSOVuiXeWjVsEyOZo=; b=MdYBRsbs3ctFw1ugW+m4ixvGjd0UxLnxRjMiGEmB49tp9R2HLLiUNt0ZX3z0muHt+s XHEyzdqyaQBEp9tuNwiU4v7fJU8HG/ykpxG+bUgJ2GX2d/F9s1bxd/WD9Holi13K3Heo JRduAdbgooPEt0XgeuQszq8KQlHAZsCi0hPP18Jzt/TT5zae5gCtTmXDK7p11/3wq8vp P8f/LhNWuisArMBfuXAx3M6tD/4vXOc9Zp74oK8uZJSdxfwXGndgAxBp3I7NiHViIyan 5lAXnmuCiS3l+Ly3hNrwuBU825JTZEKB83euPN1vC6KfYsgxt78zky6rbfilnJYUP7Vm omBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=TLUjEGuOtOvRkbxWiZWPWrLvobGSOVuiXeWjVsEyOZo=; b=H1gDlzPzngtzF3aAwf6uFwlAm8876uLZ7hiyjG6mvWzdHLiV2YPFm24/0wFN5RP4bO ifROjX2yxvGCuP/EE+FDDdOpQiVckQRPrbnnIHk2WgkKDfUspKohYISehBMvPjdY9+IK /kVSYllbgXFhYzswFYu6Df+kH+C51wAadTqc1DPz/8yQekdtk+sgNzB8hOnYUSfZhS0w BFQAZNrUWQp90xVRzJW2c8RiqtjQz0Qx0I4ylZ4zlevwi5j4VPKvktP4GHaQANZvg3/Q jSAn+pWiI+ToaPBn3+BC8C4sX+Gp/AMZVpHIEo6pWiY7j/HfqsecA8DGGGkGUb7b0jCY bRnQ== X-Gm-Message-State: AGRZ1gI4eJgEKs/OCFgPXBOEviFdH/NCut3VVvJJv83MYz4TN1fURV9C ZrtqAg8fSIlJXqx0VtzL0dI0pPnFpLQ= X-Received: by 2002:a2e:59ca:: with SMTP id g71-v6mr9812056ljf.79.1540843285129; Mon, 29 Oct 2018 13:01:25 -0700 (PDT) Received: from ?IPv6:2001:14bb:52:7be:f0bf:dd2d:f008:5213? (dmkd798g-7z2-yccwcp-4.rev.dnainternet.fi. [2001:14bb:52:7be:f0bf:dd2d:f008:5213]) by smtp.gmail.com with ESMTPSA id r22-v6sm2041418ljh.77.2018.10.29.13.01.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Oct 2018 13:01:24 -0700 (PDT) Subject: Re: [PATCH 02/17] prmem: write rare for static allocation To: Peter Zijlstra Cc: Mimi Zohar , Kees Cook , Matthew Wilcox , Dave Chinner , James Morris , Michal Hocko , kernel-hardening@lists.openwall.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, igor.stoppa@huawei.com, Dave Hansen , Jonathan Corbet , Laura Abbott , Vlastimil Babka , "Kirill A. Shutemov" , Andrew Morton , Pavel Tatashin , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20181023213504.28905-1-igor.stoppa@huawei.com> <20181023213504.28905-3-igor.stoppa@huawei.com> <20181026094105.GE3159@worktop.c.hoisthospitality.com> From: Igor Stoppa Message-ID: Date: Mon, 29 Oct 2018 22:01:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181026094105.GE3159@worktop.c.hoisthospitality.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26/10/2018 10:41, Peter Zijlstra wrote: > On Wed, Oct 24, 2018 at 12:34:49AM +0300, Igor Stoppa wrote: >> +static __always_inline > > That's far too large for inline. The reason for it is that it's supposed to minimize the presence of gadgets that might be used in JOP attacks. I am ready to stand corrected, if I'm wrong, but this is the reason why I did it. Regarding the function being too large, yes, I would not normally choose it for inlining. Actually, I would not normally use "__always_inline" and instead I would limit myself to plain "inline", at most. > >> +bool wr_memset(const void *dst, const int c, size_t n_bytes) >> +{ >> + size_t size; >> + unsigned long flags; >> + uintptr_t d = (uintptr_t)dst; >> + >> + if (WARN(!__is_wr_after_init(dst, n_bytes), WR_ERR_RANGE_MSG)) >> + return false; >> + while (n_bytes) { >> + struct page *page; >> + uintptr_t base; >> + uintptr_t offset; >> + uintptr_t offset_complement; >> + >> + local_irq_save(flags); >> + page = virt_to_page(d); >> + offset = d & ~PAGE_MASK; >> + offset_complement = PAGE_SIZE - offset; >> + size = min(n_bytes, offset_complement); >> + base = (uintptr_t)vmap(&page, 1, VM_MAP, PAGE_KERNEL); >> + if (WARN(!base, WR_ERR_PAGE_MSG)) { >> + local_irq_restore(flags); >> + return false; >> + } >> + memset((void *)(base + offset), c, size); >> + vunmap((void *)base); > > BUG yes, somehow I managed to drop this debug configuration from the debug builds I made. [...] > Also, I see an amount of duplication here that shows you're not nearly > lazy enough. I did notice a certain amount of duplication, but I didn't know how to exploit it. -- igor