Received: by 10.192.165.148 with SMTP id m20csp1180790imm; Wed, 25 Apr 2018 14:01:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+rbR7rgUsBefqDpM/vc5JqREB7KjutRWT4hDRskwzwGE++WGQ68ZoDOJZr8IyfrSI57rcF X-Received: by 2002:a17:902:bb8c:: with SMTP id m12-v6mr31165875pls.53.1524690076523; Wed, 25 Apr 2018 14:01:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524690076; cv=none; d=google.com; s=arc-20160816; b=Uqum+jsK/6qA4KY+d/OxEJgcVxilSq7/ph7U9QefxD8vjqiucpFJtx+wb9eaQXXa2C FDUAx9CWEDURMccuTHSezPV77qeH0xUEZd8USrYq1TSeJadVVDBczXAe/jnym2bde3k+ kOJND0fx/0NH67rm5eqDywll0Z6WVe1XGiqG+n5R8ND4bAZooAQ54ptFeiBWtOVab0A3 DIiYQMBNb6yLDoS1iLGQL4JgTq/54cn7JSFbsOXapHs4QD7X/gJnbKWFLeHlRZeAyfh2 TT6pt/PGOdWcsGXIahz0kLU+R7YFd3esvgl138X8vISoFcZvHtlGVO4Ilb2auSBkaosp aeRg== 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 :arc-authentication-results; bh=l8IuNgEo4XM4P/ddXFIAn0Ycwcq3V+YmX3q2bvr0Vcc=; b=JwS0wJEPZaqfDeT8m7P6Q1rkwV2K+Ivog7ZHFSItv4j98nrDIHD0nvdB6J5eD6JfoS j69ceAZyVGSYIC+mCtuY5Q4KjLR0LyComIyigJHxG6gsr7wIJqxzY21yqRxg+U/fVJfa 1TDTd0tWgG4OHIPHlFifgdSl5zYzyd+JAyH0rp/PpoL5tSHlNqzVM/fl/mdhalrhHvyx sQ7MOfKv2szkigGze5b6w3pA3QBHZkwK/04cFVi/LrTqDVpgvoo6QdWpFZxEmDnVW2CK xEtSLumf02154CEggPh069g9JFm/Iz2JGXWN3e3at6RdXDIpDMzwJ/Vp9NKyLVt6a5I7 ykwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=N67t/zfc; 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 x10si15604373pfm.18.2018.04.25.14.01.00; Wed, 25 Apr 2018 14:01:16 -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=N67t/zfc; 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 S1751678AbeDYU6o (ORCPT + 99 others); Wed, 25 Apr 2018 16:58:44 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:42249 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751424AbeDYU6m (ORCPT ); Wed, 25 Apr 2018 16:58:42 -0400 Received: by mail-pf0-f195.google.com with SMTP id o16so16246907pfk.9; Wed, 25 Apr 2018 13:58:42 -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=l8IuNgEo4XM4P/ddXFIAn0Ycwcq3V+YmX3q2bvr0Vcc=; b=N67t/zfcGOP62LhgxiatUPidT2Mz4XMc3c4lThscQP8TE8RYd7UxUFhC4WgMA2hakD a9ajkzmReBsUz+c2uHTxS8M1maTfeUJknuXkhOy3nTdcuuUwvAaBi4UpUqflaVrzgWqM ExsUfov8xagB85xvyzTjVzSiMpcWKw69G91l+Xi3VXR2e24Mu458/kyF/UvZvN7pFIcz o8leTvC9WCJx6AIeo9+NdSqAF9LMC0fVSSkWLfvezTXYPHx/s62W0zwRpNZNzk0yA7b3 2QdCu1nrSfLvE5Ai1czfXMp8oa+htbh3R6SeFJZg4IQh0td2qfzwRQnKuLAEZuG4rc4o nc7A== 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=l8IuNgEo4XM4P/ddXFIAn0Ycwcq3V+YmX3q2bvr0Vcc=; b=HVWUoAXF67Sxvp8/PFihdgj44B/VJBZRha+ISFIIWLBg5pAAVPQK3wTxY8OyeypGk/ GrAviP8UiHA0I7PyNjDKX2ykhC8tWnKszAEHLqFajyqv9xwkKZtf2PyDL38SFLdocSbO 962BQQ07uvRTGvg++gqte3XY6iHDFNrJjVnHPpB98pAqwmkM1LBC2xRVKXyn0h2EAkS5 0jXpLa3sWksW++CDjsCs1eT/3zBe04i8XWMNhlBZEOBYMbWybYUMkiwj3J5FeSLj77Yf 4qeeaf7uTbWe5HaGuu6GHXytH/mhYjY8Vye9CTRvy+e8tHni4Nzu7rL15t1014IobCmp H2hA== X-Gm-Message-State: ALQs6tBnG2JCRk7QovqCGB9QHEywQaD0vYhdWl78V6pSPXrQzuXHB9Aw sVnjiHr7HSI2igw+x9KaGiE= X-Received: by 10.99.167.4 with SMTP id d4mr17680391pgf.324.1524689921602; Wed, 25 Apr 2018 13:58:41 -0700 (PDT) Received: from [10.11.17.54] ([198.233.165.212]) by smtp.gmail.com with ESMTPSA id a23sm4760125pfi.176.2018.04.25.13.58.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 13:58:40 -0700 (PDT) Subject: Re: [PATCH 7/9] Pmalloc Rare Write: modify selected pools To: Matthew Wilcox , lazytyped , dave.hansen@linux.intel.com Cc: keescook@chromium.org, paul@paul-moore.com, sds@tycho.nsa.gov, mhocko@kernel.org, corbet@lwn.net, labbott@redhat.com, david@fromorbit.com, rppt@linux.vnet.ibm.com, linux-security-module@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Igor Stoppa , Carlos Chinea Perez , Remi Denis Courmont References: <20180423125458.5338-1-igor.stoppa@huawei.com> <20180423125458.5338-8-igor.stoppa@huawei.com> <20180424115050.GD26636@bombadil.infradead.org> <20180424144404.GF26636@bombadil.infradead.org> From: Igor Stoppa Message-ID: <6a28fa46-a6b4-2803-0f15-8c278811ec2f@gmail.com> Date: Thu, 26 Apr 2018 00:58:39 +0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180424144404.GF26636@bombadil.infradead.org> 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 24/04/18 18:44, Matthew Wilcox wrote: > On Tue, Apr 24, 2018 at 02:32:36PM +0200, lazytyped wrote: >> On 4/24/18 1:50 PM, Matthew Wilcox wrote: >>> struct modifiable_data { >>> struct immutable_data *d; >>> ... >>> }; >>> >>> Then allocate a new pool, change d and destroy the old pool. >> >> With the above, you have just shifted the target of the arbitrary write >> from the immutable data itself to the pointer to the immutable data, so >> got no security benefit. > > There's always a pointer to the immutable data. How do you currently > get to the selinux context? file->f_security. You can't make 'file' > immutable, so file->f_security is the target of the arbitrary write. > All you can do is make life harder, and reduce the size of the target. In the patch that shows how to secure the selinux initialized state, there is a static _ro_after_init handle (the 'file' in your example), which is immutable, after init has completed. It is as immutable as any const data that is not optimized away. That is what the code uses to refer to the pmalloc data. Since the reference is static, I expect the code will use it through some offset, which will be in the code segment, which is also read-only, as much as the rest. Where is the writable pointer in this scenario? >> The goal of the patch is to reduce the window when stuff is writeable, >> so that an arbitrary write is likely to hit the time when data is read-only. > > Yes, reducing the size of the target in time as well as bytes. This patch > gives attackers a great roadmap (maybe even gadget) to unprotecting > a pool. Gadgets can be removed by inlining the function calls. Dave Hansen suggested I could do COW and replace the old page with the new one. I could implement that, if it is preferable, although I think it would be less efficient, for small writes, but it would not leave the current page mapped as writable, so there is certainly value in it. --- igor